Predicting Emerging Adulthood Outcomes from School Grades

  1. Data preparation: Subset data, recode variables, get Z-scores, save datasets for analyses
  2. Preliminary analyses: Descriptives, correlations and Cronbach’s alpha, SES comparison 16 to 23
  3. Regression models without moderation
  4. Regression models with moderation for sex and SES
  5. Multi-group regression models

###variable overview###

data available GCSE at 16 pcexdata1 TEDS21 phase 1 u1cdata1 TEDS21 phase 2 u2cdata1 age age web test 16 pcwebage1 age GCSE pcexgcseage1 age TEDS21 phase 1 u1cage1 age TEDS21 phase 2 u2cage1 sex sex1 SES SES index 1 (1st contact) ases SES index 2 (age 7) gses SES index 3 (income age 9) ipincome SES age 16 pses SES age 23 (TEDS 21) u1pses school performance (GCSE, age 16) pcexgcsecoregrdm1 (4-11, higher=better)

#outcomes (age 21) edu. attainment composite, standardised u1cedat1 still studying u1chqualp1 (1-11, higher=better) university performance u1cdegr11 (2-5, higher=better) employment status u1cstatus1 (needs to be recoded) recoded version 1 status1 (0-4, nominal) recoded binary status_bin (0 = not in emp.:gap,parent,unemp.; 1 = emp.:study,apprentice.,work) occupational prestige (SOC) u1csoc1 (1-9, lower=better!) recoded version soc1 (0-8, higher=better) income monthly emp. income u1cjobinc1 (1-9, higher=better) monthly not from work u1cothinc1 benefit status (receive any) u1cbenf11 (0=no, 1=yes)
financial attitudes + behaviour u1cmonam1 (1-5, higher=better) financial contentment w/ life (CLAS) u1cfinam1 (1-5, higher=better) wellbeing (MFQ) u1cmfqt1 (0-16, lower=better! will be recoded) recoded version wellb1 (0-16, higher=better) anxiety u2cganxt1 (0-40, lower=better/less anxiety) behaviour problems (SDQ) u1csdqbeht1 (0-40, lower=better/less problem behav.) alcohol use u2calcoaudit1 (0-40, lower=better/less alcohol)

install/load packages

#Step 1: #Data preparation: Subset data, recode variables, get Z-scores, save datasets for analyses

#load data
dat <- read.spss("/Users/cgb538/Library/CloudStorage/GoogleDrive-alexandra.starr@york.ac.uk/My Drive/projects and papers/DevPsych_prediction grades adulthood/data/557 Sophie von Stumm GCSE and emerging adulthood Apr2023.sav",use.value.label = FALSE, to.data.frame=TRUE)
dim(dat) #19984 339
## [1] 19984   339
#Save as csv file
write.csv(dat, '/Users/cgb538/Library/CloudStorage/GoogleDrive-alexandra.starr@york.ac.uk/My Drive/projects and papers/DevPsych_prediction grades adulthood/data/grades_adulth.csv', row.names = F, na = 'NA')

#And re-read
data <- read.csv("/Users/cgb538/Library/CloudStorage/GoogleDrive-alexandra.starr@york.ac.uk/My Drive/projects and papers/DevPsych_prediction grades adulthood/data/grades_adulth.csv", header = T, strip.white = T,na.strings = c('NA', '', ' '
))
dim(data)  #19984 339
## [1] 19984   339
#str(data)

df<- data[, c('randomfamid', 'randomtwinid', 'twin', 'random', 'cohort', 'sex1', 'sex2', 'zygos', 
             'sexzyg', 'x3zygos', 'acontact', 'medexcl1', 'exclude1', 'ases', 'gses', 'pses', 'u1pses', 'ipincome',
             'pcexdata1', 'u1cdata1', 'u2cdata1','pcwebage1', 'pcexgcseage1', 'u1cage1', 'u2cage1',
             'pcexgcsecoregrdm1', 'u1cedat1', 'u1chqualp1', 'u1cdegr11',
             'u1cstatus1', 'u1csoc1', 'u1cjobinc1', 'u1cbenf11', 
             'u1cmona11', 'u1cmona1r1', 'u1cmona21', 'u1cmona2r1', 'u1cmona31', 'u1cmona41', 
             'u1cmona51', 'u1cmona61', 'u1cmona6r1', 'u1cmonam1',
             'u1cfinam1', 'u1cfina11', 'u1cfina21', 'u1cfina31', 'u1cfina41', 'u1cfina51', 'u1cfina5r1',
             'u1cmfqt1', 'u1cmfq11', 'u1cmfq21', 'u1cmfq31', 'u1cmfq41', 'u1cmfq51', 'u1cmfq61', 'u1cmfq71', 'u1cmfq81',
             'u2cganxt1', 'u2cganx011', 'u2cganx021', 'u2cganx031', 'u2cganx041', 'u2cganx051', 
             'u2cganx061', 'u2cganx071', 'u2cganx081', 'u2cganx091', 'u2cganx101',
             'u1csdqbeht1', 'u1csdqemot1', 'u1csdqcont1', 'u1csdqhypt1', 'u1csdqpert1',
             'u2calcoaudit1', 'u2calco041', 'u2calco051', 'u2calco061', 'u2calco071', 'u2calco081', 
             'u2calco091', 'u2calco101', 'u2calco111', 'u2calco121', 'u2calco131'),]

         
dim(df)    #19984  86
## [1] 19984    86
#str(df)

write.csv(df, '/Users/cgb538/Library/CloudStorage/GoogleDrive-alexandra.starr@york.ac.uk/My Drive/projects and papers/DevPsych_prediction grades adulthood/data/grades_adulth_reduced.csv', row.names = F, na = 'NA')
rm(list=ls())
ls()
## character(0)
#initial sample size
df <- read.csv("/Users/cgb538/Library/CloudStorage/GoogleDrive-alexandra.starr@york.ac.uk/My Drive/projects and papers/DevPsych_prediction grades adulthood/data/grades_adulth_reduced.csv", header = T, strip.white = T,na.strings = c('NA', '', ' '
))
dim(df) #19984    86
## [1] 19984    86
#sample size after medical exclusions
df1 = df[df$exclude1==0, ]
dim(df1) #18946    86
## [1] 18946    86
#exclude all cases with missing value on GCSE --> still keep both twins for data prep and later for multi-group regressions
freq(df1$pcexgcsecoregrdm1)
## Frequencies  
## df1$pcexgcsecoregrdm1  
## Type: Numeric  
## 
##                Freq    % Valid   % Valid Cum.    % Total   % Total Cum.
## ----------- ------- ---------- -------------- ---------- --------------
##           4      10     0.0770         0.0770     0.0528         0.0528
##         4.3       3     0.0231         0.1001     0.0158         0.0686
##         4.5      11     0.0847         0.1849     0.0581         0.1267
##         4.7      11     0.0847         0.2696     0.0581         0.1847
##         4.8       1     0.0077         0.2773     0.0053         0.1900
##           5      48     0.3698         0.6471     0.2534         0.4434
##         5.2       3     0.0231         0.6702     0.0158         0.4592
##         5.3      17     0.1310         0.8012     0.0897         0.5489
##         5.4      10     0.0770         0.8782     0.0528         0.6017
##         5.5      26     0.2003         1.0785     0.1372         0.7389
##         5.6       5     0.0385         1.1170     0.0264         0.7653
##         5.7      32     0.2465         1.3635     0.1689         0.9342
##         5.8      16     0.1233         1.4868     0.0845         1.0187
##           6     112     0.8628         2.3496     0.5912         1.6098
##         6.2      15     0.1156         2.4651     0.0792         1.6890
##         6.3      62     0.4776         2.9428     0.3272         2.0163
##         6.4      14     0.1078         3.0506     0.0739         2.0902
##         6.5      86     0.6625         3.7131     0.4539         2.5441
##         6.6      24     0.1849         3.8980     0.1267         2.6707
##         6.7      64     0.4930         4.3910     0.3378         3.0086
##         6.8      85     0.6548         5.0458     0.4486         3.4572
##           7     288     2.2186         7.2645     1.5201         4.9773
##         7.1       1     0.0077         7.2722     0.0053         4.9826
##         7.2      91     0.7010         7.9732     0.4803         5.4629
##         7.3     230     1.7718         9.7450     1.2140         6.6769
##         7.4     120     0.9244        10.6694     0.6334         7.3103
##         7.5     254     1.9567        12.6261     1.3407         8.6509
##         7.6     154     1.1863        13.8125     0.8128         9.4637
##         7.7     203     1.5638        15.3763     1.0715        10.5352
##         7.8     468     3.6053        18.9816     2.4702        13.0054
##         7.9      12     0.0924        19.0740     0.0633        13.0687
##           8     919     7.0796        26.1536     4.8506        17.9193
##         8.1      15     0.1156        26.2692     0.0792        17.9985
##         8.2     466     3.5899        29.8590     2.4596        20.4581
##         8.3     438     3.3742        33.2332     2.3118        22.7700
##         8.4     368     2.8349        36.0681     1.9424        24.7123
##         8.5     351     2.7040        38.7721     1.8526        26.5650
##         8.6     408     3.1431        41.9151     2.1535        28.7185
##         8.7     301     2.3188        44.2339     1.5887        30.3072
##         8.8     664     5.1152        49.3490     3.5047        33.8119
##         8.9      40     0.3081        49.6572     0.2111        34.0230
##           9     708     5.4541        55.1113     3.7369        37.7599
##         9.1      39     0.3004        55.4118     0.2058        37.9658
##         9.2     568     4.3756        59.7874     2.9980        40.9638
##         9.3     362     2.7887        62.5761     1.9107        42.8745
##         9.4     335     2.5807        65.1568     1.7682        44.6427
##         9.5     331     2.5499        67.7066     1.7471        46.3897
##         9.6     286     2.2032        69.9099     1.5096        47.8993
##         9.7     337     2.5961        72.5060     1.7787        49.6780
##         9.8     495     3.8133        76.3192     2.6127        52.2907
##         9.9      56     0.4314        76.7506     0.2956        52.5863
##          10     535     4.1214        80.8720     2.8238        55.4101
##        10.1      68     0.5238        81.3959     0.3589        55.7690
##        10.2     407     3.1354        84.5312     2.1482        57.9172
##        10.3     316     2.4343        86.9656     1.6679        59.5851
##        10.4     201     1.5484        88.5140     1.0609        60.6460
##        10.5     254     1.9567        90.4707     1.3407        61.9867
##        10.6     159     1.2249        91.6956     0.8392        62.8259
##        10.7     297     2.2880        93.9835     1.5676        64.3935
##        10.8     342     2.6346        96.6181     1.8051        66.1987
##        10.9      62     0.4776        97.0958     0.3272        66.5259
##          11     377     2.9042       100.0000     1.9899        68.5158
##        <NA>    5965                              31.4842       100.0000
##       Total   18946   100.0000       100.0000   100.0000       100.0000
df2 = df1[is.na(df1$pcexgcsecoregrdm1) == FALSE, ]

#check that NA=0
freq(df2$pcexgcsecoregrdm1)
## Frequencies  
## df2$pcexgcsecoregrdm1  
## Type: Numeric  
## 
##                Freq    % Valid   % Valid Cum.    % Total   % Total Cum.
## ----------- ------- ---------- -------------- ---------- --------------
##           4      10     0.0770         0.0770     0.0770         0.0770
##         4.3       3     0.0231         0.1001     0.0231         0.1001
##         4.5      11     0.0847         0.1849     0.0847         0.1849
##         4.7      11     0.0847         0.2696     0.0847         0.2696
##         4.8       1     0.0077         0.2773     0.0077         0.2773
##           5      48     0.3698         0.6471     0.3698         0.6471
##         5.2       3     0.0231         0.6702     0.0231         0.6702
##         5.3      17     0.1310         0.8012     0.1310         0.8012
##         5.4      10     0.0770         0.8782     0.0770         0.8782
##         5.5      26     0.2003         1.0785     0.2003         1.0785
##         5.6       5     0.0385         1.1170     0.0385         1.1170
##         5.7      32     0.2465         1.3635     0.2465         1.3635
##         5.8      16     0.1233         1.4868     0.1233         1.4868
##           6     112     0.8628         2.3496     0.8628         2.3496
##         6.2      15     0.1156         2.4651     0.1156         2.4651
##         6.3      62     0.4776         2.9428     0.4776         2.9428
##         6.4      14     0.1078         3.0506     0.1078         3.0506
##         6.5      86     0.6625         3.7131     0.6625         3.7131
##         6.6      24     0.1849         3.8980     0.1849         3.8980
##         6.7      64     0.4930         4.3910     0.4930         4.3910
##         6.8      85     0.6548         5.0458     0.6548         5.0458
##           7     288     2.2186         7.2645     2.2186         7.2645
##         7.1       1     0.0077         7.2722     0.0077         7.2722
##         7.2      91     0.7010         7.9732     0.7010         7.9732
##         7.3     230     1.7718         9.7450     1.7718         9.7450
##         7.4     120     0.9244        10.6694     0.9244        10.6694
##         7.5     254     1.9567        12.6261     1.9567        12.6261
##         7.6     154     1.1863        13.8125     1.1863        13.8125
##         7.7     203     1.5638        15.3763     1.5638        15.3763
##         7.8     468     3.6053        18.9816     3.6053        18.9816
##         7.9      12     0.0924        19.0740     0.0924        19.0740
##           8     919     7.0796        26.1536     7.0796        26.1536
##         8.1      15     0.1156        26.2692     0.1156        26.2692
##         8.2     466     3.5899        29.8590     3.5899        29.8590
##         8.3     438     3.3742        33.2332     3.3742        33.2332
##         8.4     368     2.8349        36.0681     2.8349        36.0681
##         8.5     351     2.7040        38.7721     2.7040        38.7721
##         8.6     408     3.1431        41.9151     3.1431        41.9151
##         8.7     301     2.3188        44.2339     2.3188        44.2339
##         8.8     664     5.1152        49.3490     5.1152        49.3490
##         8.9      40     0.3081        49.6572     0.3081        49.6572
##           9     708     5.4541        55.1113     5.4541        55.1113
##         9.1      39     0.3004        55.4118     0.3004        55.4118
##         9.2     568     4.3756        59.7874     4.3756        59.7874
##         9.3     362     2.7887        62.5761     2.7887        62.5761
##         9.4     335     2.5807        65.1568     2.5807        65.1568
##         9.5     331     2.5499        67.7066     2.5499        67.7066
##         9.6     286     2.2032        69.9099     2.2032        69.9099
##         9.7     337     2.5961        72.5060     2.5961        72.5060
##         9.8     495     3.8133        76.3192     3.8133        76.3192
##         9.9      56     0.4314        76.7506     0.4314        76.7506
##          10     535     4.1214        80.8720     4.1214        80.8720
##        10.1      68     0.5238        81.3959     0.5238        81.3959
##        10.2     407     3.1354        84.5312     3.1354        84.5312
##        10.3     316     2.4343        86.9656     2.4343        86.9656
##        10.4     201     1.5484        88.5140     1.5484        88.5140
##        10.5     254     1.9567        90.4707     1.9567        90.4707
##        10.6     159     1.2249        91.6956     1.2249        91.6956
##        10.7     297     2.2880        93.9835     2.2880        93.9835
##        10.8     342     2.6346        96.6181     2.6346        96.6181
##        10.9      62     0.4776        97.0958     0.4776        97.0958
##          11     377     2.9042       100.0000     2.9042       100.0000
##        <NA>       0                               0.0000       100.0000
##       Total   12981   100.0000       100.0000   100.0000       100.0000
dim(df2)    #12981    86
## [1] 12981    86
#recode employment status: 2 versions
#old 
    #1=studying; 2=working; 3=apprenticeship; 4=gap year/travelling; 5=unemployed; 6=full-time parent
#new 
#1) nominal (as described in prereg)
    #0=unemployed; 1=working; 2=studying or apprenticeship; 3=full-time parents; 4=gap year/travelling
    df2 <- df2 %>% 
      mutate(status1 = ifelse(u1cstatus1 == 5, 0,
                    ifelse(u1cstatus1 == 2, 1,
                    ifelse(u1cstatus1 %in% c(1,3), 2,
                    ifelse(u1cstatus1 == 6, 3,
                    ifelse(u1cstatus1 == 4, 4, NA))))))
    #check frequencies after recoding
    table(df2$u1cstatus1)
## 
##    1    2    3    4    5    6 
## 2567 3899  288  246  462   57
    table(df2$status1)
## 
##    0    1    2    3    4 
##  462 3899 2855   57  246
#2) binary
    #0 = not in full-time employment (unemployed,parent,gap year); 1 = in education/full-time work
    df2 <- df2 %>% 
      mutate(status_bin = ifelse(u1cstatus1 %in% c(1,2,3), 1,
                          ifelse(u1cstatus1 %in% c(4,5,6), 0, NA)))
    #check frequencies after recoding
    table(df2$u1cstatus1)
## 
##    1    2    3    4    5    6 
## 2567 3899  288  246  462   57
    table(df2$status_bin)
## 
##    0    1 
##  765 6754
#reverse wellbeing  -> so higher = better 
describe(df2$u1cmfqt1) #max = 16
## df2$u1cmfqt1 
##        n  missing distinct     Info     Mean      Gmd      .05      .10 
##     7544     5437       20    0.988    4.332    4.404        0        0 
##      .25      .50      .75      .90      .95 
##        1        3        7       11       13 
## 
## lowest :  0.000000  1.000000  1.142857  2.000000  2.285714
## highest: 12.000000 13.000000 14.000000 15.000000 16.000000
## 
## 0 (1290, 0.171), 1 (1046, 0.139), 1.14285714285714 (1, 0.000), 2 (899, 0.119),
## 2.28571428571429 (2, 0.000), 3 (762, 0.101), 4 (659, 0.087), 5 (530, 0.070), 6
## (415, 0.055), 7 (391, 0.052), 8 (294, 0.039), 9 (253, 0.034), 10 (216, 0.029),
## 10.2857142857143 (1, 0.000), 11 (210, 0.028), 12 (141, 0.019), 13 (130, 0.017),
## 14 (115, 0.015), 15 (95, 0.013), 16 (94, 0.012)
df2 <- df2 %>% 
  mutate(wellb1 = 16 - u1cmfqt1)


#reverse occupational prestige (SOC) -> higher = better
describe(df2$u1csoc1) #max = 9
## df2$u1csoc1 
##        n  missing distinct     Info     Mean      Gmd 
##     3453     9528        9    0.969    4.333     2.55 
## 
## lowest : 1 2 3 4 5, highest: 5 6 7 8 9
##                                                                 
## Value          1     2     3     4     5     6     7     8     9
## Frequency    173   699   859   360   163   339   580    54   226
## Proportion 0.050 0.202 0.249 0.104 0.047 0.098 0.168 0.016 0.065
df2 <- df2 %>% 
  mutate(soc1 = 9 - u1csoc1)



dim(df2) #12981    90
## [1] 12981    90
#standardise variables separately for twin 1 and 2 (random=0/1), then merge datasets again

df_scaled0 <- df2 %>% filter(random == 0) %>%
  mutate(Zgcse = scale(pcexgcsecoregrdm1)) %>%
  mutate(Zhqual = scale(u1chqualp1)) %>%
  mutate(Zdegree = scale(u1cdegr11)) %>%
  mutate(Zsoc = scale(soc1)) %>%
  mutate(Zinc = scale(u1cjobinc1)) %>%
  mutate(Zmon = scale(u1cmonam1)) %>%
  mutate(Zfina = scale(u1cfinam1)) %>%
  mutate(Zwellb = scale(wellb1)) %>%
  mutate(Zanx = scale(u2cganxt1)) %>%
  mutate(Zsdq = scale(u1csdqbeht1)) %>%
  mutate(Zalc = scale(u2calcoaudit1)) %>%
  mutate(Zases = scale(ases)) %>%
  mutate(Zgses = scale(gses)) %>%
  mutate(Zpses = scale(pses)) %>%
  mutate(Zu1pses = scale(u1pses)) %>%
  mutate(Zipincome = scale(ipincome))
  
df_scaled1 <- df2 %>% filter(random == 1) %>%
  mutate(Zgcse = scale(pcexgcsecoregrdm1)) %>%
  mutate(Zhqual = scale(u1chqualp1)) %>%
  mutate(Zdegree = scale(u1cdegr11)) %>%
  mutate(Zsoc = scale(soc1)) %>%
  mutate(Zinc = scale(u1cjobinc1)) %>%
  mutate(Zmon = scale(u1cmonam1)) %>%
  mutate(Zfina = scale(u1cfinam1)) %>%
  mutate(Zwellb = scale(wellb1)) %>%
  mutate(Zanx = scale(u2cganxt1)) %>%
  mutate(Zsdq = scale(u1csdqbeht1)) %>%
  mutate(Zalc = scale(u2calcoaudit1)) %>%
  mutate(Zases = scale(ases)) %>%
  mutate(Zgses = scale(gses)) %>%
  mutate(Zpses = scale(pses)) %>%
  mutate(Zu1pses = scale(u1pses)) %>%
  mutate(Zipincome = scale(ipincome))
  

df3 <- rbind(df_scaled0, df_scaled1)


#create SESscore from SES index 1, 2 & 3 (composite at 1st contact, age 7 and income at age 9)
df3$SESscore <- rowMeans(df3[c("Zipincome", "Zases", "Zgses")], na.rm = TRUE)
 
df3[sapply(df3, is.nan)] <- NA

dim(df3) #12981   107
## [1] 12981   107

Save two versions of prepared dataset for analyses

  1. dataset as is (reduced, after exclusions, non-missing GCSE variable, recodings, with z-standardised variables), with both twins –> for multi-group regressions
  2. same dataset but only one random twin –> for all preliminary analyses and all main regressions
#1) prepared data, both twins 
write.csv(df3, '/Users/cgb538/Library/CloudStorage/GoogleDrive-alexandra.starr@york.ac.uk/My Drive/projects and papers/DevPsych_prediction grades adulthood/data/grades_adulth_prepared_bothtwins.csv', row.names = F, na = 'NA')


#select one random twin per pair
df4 = df3[df3$random==1, ]
dim(df4) #6488  107
## [1] 6488  107
#2) prepared data, one random twin 
write.csv(df4, '/Users/cgb538/Library/CloudStorage/GoogleDrive-alexandra.starr@york.ac.uk/My Drive/projects and papers/DevPsych_prediction grades adulthood/data/grades_adulth_prepared_random1.csv', row.names = F, na = 'NA')

#Step 2: #Preliminary analyses: Descriptives, correlations and Cronbach’s alpha

rm(list=ls())
ls()
## character(0)
#read in random1-dataset for preliminary analyses 
df <- read.csv("/Users/cgb538/Library/CloudStorage/GoogleDrive-alexandra.starr@york.ac.uk/My Drive/projects and papers/DevPsych_prediction grades adulthood/data/grades_adulth_prepared_random1.csv", header = T, strip.white = T,na.strings = c('NA', '', ' '
))


desc = psych::describe(df[, c('pcwebage1', 'pcexgcseage1', 'u1cage1', 'u2cage1',
             'pcexgcsecoregrdm1', 'u1cedat1', 'u1chqualp1', 'u1cdegr11', 'status1', 'status_bin', 'soc1', 'u1cjobinc1', 'u1cbenf11',
             'u1cmonam1', 'u1cfinam1', 'wellb1', 'u2cganxt1', 'u1csdqbeht1', 'u2calcoaudit1')])


write.xlsx(desc, file = "/Users/cgb538/Library/CloudStorage/GoogleDrive-alexandra.starr@york.ac.uk/My Drive/projects and papers/DevPsych_prediction grades adulthood/data/descriptives_grades_adulth.xlsx", col.names = TRUE, row.names = TRUE)

#frequencies for categorical variables
library(summarytools)

freq_hqual <- freq(df$u1chqualp1)
freq_status1 <- freq(df$status1)
freq_status_bin <- freq(df$status_bin)
freq_ocprestige <- freq(df$soc1)
freq_benf <- freq(df$u1cbenf11)
#correlations only for continuous variables

library(tidyverse)
library(ggcorrplot)

corrmatrix <- subset(df, select = c('pcexgcsecoregrdm1', 'u1cedat1', 'u1chqualp1', 'u1cdegr11', 'soc1', 'u1cjobinc1',
             'u1cmonam1', 'u1cfinam1', 'wellb1', 'u2cganxt1', 'u1csdqbeht1', 'u2calcoaudit1'))


corrdata1matrix <- cor(corrmatrix, use = "pairwise.complete.obs", method = c ("pearson")) #produce correlation matrix
ggcorrplot(corrdata1matrix, ggtheme = ggplot2::theme_minimal, type = "lower", show.diag = TRUE,
           lab = TRUE, lab_size = 3, tl.cex = 15, colors = c("#6D9EC1", "white", "red"))

ggsave("corrplot_grades_adulth.png")
## Saving 7 x 5 in image
#cor_pmat(corrdata1matrix) # p-values


#does the same but nicer tables imo
library(corrtable)

dffullcorr <- df %>% select(pcexgcsecoregrdm1, u1cedat1, u1chqualp1, u1cdegr11, soc1, u1cjobinc1,
             u1cmonam1, u1cfinam1, wellb1, u2cganxt1, u1csdqbeht1, u2calcoaudit1)

correlation_matrix(
  dffullcorr,
  use = "lower")
##                   pcexgcsecoregrdm1  u1cedat1    u1chqualp1  u1cdegr11  
## pcexgcsecoregrdm1 " 1.000   "        ""          ""          ""         
## u1cedat1          " 0.535***"        " 1.000   " ""          ""         
## u1chqualp1        " 0.529***"        " 0.967***" " 1.000   " ""         
## u1cdegr11         " 0.284***"        " 0.899***" " 0.147***" " 1.000   "
## soc1              " 0.290***"        " 0.286***" " 0.279***" " 0.124***"
## u1cjobinc1        " 0.181***"        " 0.111***" " 0.094***" " 0.103** "
## u1cmonam1         " 0.050** "        " 0.036*  " " 0.033*  " " 0.076** "
## u1cfinam1         " 0.007   "        "-0.046** " "-0.060***" " 0.095***"
## wellb1            " 0.110***"        " 0.082***" " 0.086***" " 0.035   "
## u2cganxt1         "-0.015   "        "-0.001   " "-0.010   " " 0.020   "
## u1csdqbeht1       "-0.216***"        "-0.181***" "-0.184***" "-0.065** "
## u2calcoaudit1     " 0.033   "        " 0.051** " " 0.045*  " "-0.008   "
##                   soc1        u1cjobinc1  u1cmonam1   u1cfinam1   wellb1     
## pcexgcsecoregrdm1 ""          ""          ""          ""          ""         
## u1cedat1          ""          ""          ""          ""          ""         
## u1chqualp1        ""          ""          ""          ""          ""         
## u1cdegr11         ""          ""          ""          ""          ""         
## soc1              " 1.000   " ""          ""          ""          ""         
## u1cjobinc1        " 0.420***" " 1.000   " ""          ""          ""         
## u1cmonam1         " 0.132***" " 0.125***" " 1.000   " ""          ""         
## u1cfinam1         " 0.183***" " 0.321***" " 0.411***" " 1.000   " ""         
## wellb1            " 0.180***" " 0.149***" " 0.175***" " 0.280***" " 1.000   "
## u2cganxt1         "-0.086** " "-0.126***" "-0.098***" "-0.245***" "-0.561***"
## u1csdqbeht1       "-0.194***" "-0.141***" "-0.206***" "-0.268***" "-0.759***"
## u2calcoaudit1     "-0.036   " " 0.036   " "-0.251***" "-0.138***" "-0.136***"
##                   u2cganxt1   u1csdqbeht1  u2calcoaudit1 
## pcexgcsecoregrdm1 ""          ""           ""            
## u1cedat1          ""          ""           ""            
## u1chqualp1        ""          ""           ""            
## u1cdegr11         ""          ""           ""            
## soc1              ""          ""           ""            
## u1cjobinc1        ""          ""           ""            
## u1cmonam1         ""          ""           ""            
## u1cfinam1         ""          ""           ""            
## wellb1            ""          ""           ""            
## u2cganxt1         " 1.000   " ""           ""            
## u1csdqbeht1       " 0.553***" " 1.000   "  ""            
## u2calcoaudit1     " 0.117***" " 0.095***"  " 1.000   "
save_correlation_matrix(df = dffullcorr,
                        filename = '/Users/cgb538/Library/CloudStorage/GoogleDrive-alexandra.starr@york.ac.uk/My Drive/projects and papers/DevPsych_prediction grades adulthood/data/correlations_grades_adulth.csv',
                        digits = 3,
                        use = 'lower')

Cronbach’s alpha for all psychometric scales used to assess emerging adulthood outcomes (i.e., financial attitudes and behaviour, financial contentment with life, wellbeing, anxiety, behaviour problems)

library(psych)

#financial/money attitudes
monitems <- subset(df, select = c("u1cmona1r1", "u1cmona2r1", "u1cmona31", "u1cmona41", "u1cmona51", "u1cmona6r1"))
psych::alpha(monitems)
## 
## Reliability analysis   
## Call: psych::alpha(x = monitems)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N    ase mean  sd median_r
##       0.71      0.71    0.71      0.29 2.5 0.0054  3.6 0.6      0.3
## 
##     95% confidence boundaries 
##          lower alpha upper
## Feldt      0.7  0.71  0.72
## Duhachek   0.7  0.71  0.72
## 
##  Reliability if an item is dropped:
##            raw_alpha std.alpha G6(smc) average_r S/N alpha se var.r med.r
## u1cmona1r1      0.67      0.67    0.67      0.29 2.1   0.0063 0.024  0.31
## u1cmona2r1      0.64      0.64    0.63      0.26 1.8   0.0070 0.020  0.27
## u1cmona31       0.70      0.70    0.68      0.32 2.3   0.0059 0.016  0.31
## u1cmona41       0.65      0.64    0.62      0.26 1.8   0.0067 0.015  0.27
## u1cmona51       0.67      0.67    0.65      0.29 2.0   0.0063 0.017  0.29
## u1cmona6r1      0.71      0.71    0.69      0.33 2.5   0.0056 0.010  0.31
## 
##  Item statistics 
##               n raw.r std.r r.cor r.drop mean   sd
## u1cmona1r1 3661  0.66  0.64  0.53   0.45  3.5 0.99
## u1cmona2r1 3660  0.73  0.72  0.65   0.55  3.4 1.03
## u1cmona31  3655  0.53  0.58  0.45   0.37  4.3 0.71
## u1cmona41  3658  0.70  0.71  0.66   0.54  3.9 0.91
## u1cmona51  3658  0.67  0.65  0.56   0.46  3.3 1.06
## u1cmona6r1 3659  0.54  0.54  0.39   0.33  2.9 0.90
## 
## Non missing response frequency for each item
##               1    2    3    4    5 miss
## u1cmona1r1 0.02 0.17 0.22 0.45 0.14 0.44
## u1cmona2r1 0.03 0.19 0.22 0.43 0.13 0.44
## u1cmona31  0.00 0.02 0.08 0.50 0.40 0.44
## u1cmona41  0.01 0.09 0.16 0.51 0.23 0.44
## u1cmona51  0.03 0.23 0.26 0.34 0.13 0.44
## u1cmona6r1 0.03 0.31 0.39 0.23 0.04 0.44
#financial contentment with life
finaitems <- subset(df, select = c("u1cfina11", "u1cfina21", "u1cfina31", "u1cfina41", "u1cfina5r1"))
psych::alpha(finaitems)
## 
## Reliability analysis   
## Call: psych::alpha(x = finaitems)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N    ase mean   sd median_r
##       0.83      0.84    0.82      0.51 5.2 0.0033  3.7 0.81     0.49
## 
##     95% confidence boundaries 
##          lower alpha upper
## Feldt     0.83  0.83  0.84
## Duhachek  0.83  0.83  0.84
## 
##  Reliability if an item is dropped:
##            raw_alpha std.alpha G6(smc) average_r S/N alpha se  var.r med.r
## u1cfina11       0.79      0.80    0.75      0.49 3.9   0.0043 0.0070  0.49
## u1cfina21       0.77      0.78    0.74      0.47 3.5   0.0047 0.0083  0.46
## u1cfina31       0.84      0.84    0.80      0.56 5.2   0.0033 0.0075  0.57
## u1cfina41       0.78      0.78    0.75      0.47 3.6   0.0045 0.0111  0.46
## u1cfina5r1      0.82      0.82    0.79      0.54 4.7   0.0038 0.0136  0.54
## 
##  Item statistics 
##               n raw.r std.r r.cor r.drop mean   sd
## u1cfina11  3662  0.80  0.80  0.75   0.67  3.7 1.12
## u1cfina21  3663  0.84  0.84  0.80   0.73  3.4 1.08
## u1cfina31  3662  0.71  0.69  0.56   0.51  3.5 1.18
## u1cfina41  3662  0.82  0.83  0.78   0.72  3.9 0.91
## u1cfina5r1 3661  0.72  0.73  0.62   0.57  3.9 0.95
## 
## Non missing response frequency for each item
##               1    2    3    4    5 miss
## u1cfina11  0.06 0.12 0.13 0.47 0.22 0.44
## u1cfina21  0.06 0.16 0.24 0.41 0.13 0.44
## u1cfina31  0.05 0.18 0.17 0.37 0.23 0.44
## u1cfina41  0.03 0.07 0.11 0.59 0.20 0.44
## u1cfina5r1 0.01 0.09 0.16 0.45 0.29 0.44
#wellbeing
wellbitems <- subset(df, select = c("u1cmfq11", "u1cmfq21", "u1cmfq31", "u1cmfq41", "u1cmfq51", "u1cmfq61", "u1cmfq71", "u1cmfq81"))
psych::alpha(wellbitems)
## 
## Reliability analysis   
## Call: psych::alpha(x = wellbitems)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N    ase mean   sd median_r
##       0.87      0.87    0.87      0.46 6.9 0.0024 0.53 0.51     0.46
## 
##     95% confidence boundaries 
##          lower alpha upper
## Feldt     0.87  0.87  0.88
## Duhachek  0.87  0.87  0.88
## 
##  Reliability if an item is dropped:
##          raw_alpha std.alpha G6(smc) average_r S/N alpha se  var.r med.r
## u1cmfq11      0.84      0.85    0.83      0.44 5.5   0.0030 0.0057  0.43
## u1cmfq21      0.86      0.86    0.86      0.48 6.4   0.0026 0.0074  0.48
## u1cmfq31      0.87      0.87    0.86      0.49 6.6   0.0025 0.0051  0.48
## u1cmfq41      0.86      0.86    0.85      0.47 6.2   0.0027 0.0071  0.46
## u1cmfq51      0.86      0.86    0.85      0.46 6.0   0.0027 0.0085  0.44
## u1cmfq61      0.85      0.85    0.84      0.45 5.7   0.0028 0.0055  0.45
## u1cmfq71      0.85      0.85    0.84      0.46 5.9   0.0028 0.0063  0.45
## u1cmfq81      0.86      0.86    0.85      0.47 6.1   0.0027 0.0063  0.46
## 
##  Item statistics 
##             n raw.r std.r r.cor r.drop mean   sd
## u1cmfq11 3753  0.81  0.81  0.79   0.74 0.63 0.74
## u1cmfq21 3753  0.69  0.68  0.61   0.57 0.77 0.76
## u1cmfq31 3753  0.64  0.64  0.56   0.52 0.51 0.67
## u1cmfq41 3754  0.69  0.70  0.64   0.60 0.29 0.59
## u1cmfq51 3753  0.73  0.74  0.69   0.64 0.50 0.66
## u1cmfq61 3753  0.78  0.78  0.75   0.70 0.35 0.64
## u1cmfq71 3754  0.76  0.76  0.71   0.67 0.55 0.72
## u1cmfq81 3753  0.73  0.72  0.67   0.61 0.66 0.76
## 
## Non missing response frequency for each item
##             0    1    2 miss
## u1cmfq11 0.53 0.32 0.15 0.42
## u1cmfq21 0.43 0.37 0.20 0.42
## u1cmfq31 0.59 0.31 0.10 0.42
## u1cmfq41 0.78 0.15 0.07 0.42
## u1cmfq51 0.59 0.31 0.10 0.42
## u1cmfq61 0.74 0.17 0.09 0.42
## u1cmfq71 0.58 0.28 0.14 0.42
## u1cmfq81 0.52 0.31 0.18 0.42
#anxiety
anxitems <- subset(df, select = c("u2cganx011", "u2cganx021", "u2cganx031", 
             "u2cganx041", "u2cganx051", "u2cganx061", "u2cganx071", "u2cganx081",
             "u2cganx091", "u2cganx101"))
psych::alpha(anxitems)
## 
## Reliability analysis   
## Call: psych::alpha(x = anxitems)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N    ase mean   sd median_r
##       0.91      0.91    0.91      0.51  11 0.0016 0.71 0.72      0.5
## 
##     95% confidence boundaries 
##          lower alpha upper
## Feldt     0.91  0.91  0.91
## Duhachek  0.91  0.91  0.91
## 
##  Reliability if an item is dropped:
##            raw_alpha std.alpha G6(smc) average_r  S/N alpha se  var.r med.r
## u2cganx011      0.90      0.91    0.90      0.52  9.6   0.0017 0.0055  0.50
## u2cganx021      0.90      0.90    0.90      0.50  8.9   0.0019 0.0044  0.48
## u2cganx031      0.90      0.91    0.90      0.52  9.7   0.0017 0.0057  0.50
## u2cganx041      0.90      0.90    0.90      0.51  9.4   0.0018 0.0055  0.49
## u2cganx051      0.90      0.90    0.90      0.51  9.4   0.0018 0.0053  0.49
## u2cganx061      0.90      0.90    0.90      0.51  9.3   0.0018 0.0045  0.49
## u2cganx071      0.90      0.90    0.90      0.51  9.3   0.0018 0.0050  0.49
## u2cganx081      0.90      0.90    0.90      0.50  9.2   0.0018 0.0047  0.49
## u2cganx091      0.91      0.91    0.90      0.52  9.8   0.0017 0.0047  0.51
## u2cganx101      0.91      0.91    0.91      0.53 10.2   0.0017 0.0043  0.51
## 
##  Item statistics 
##               n raw.r std.r r.cor r.drop mean   sd
## u2cganx011 3429  0.71  0.73  0.69   0.65 0.43 0.77
## u2cganx021 3429  0.83  0.83  0.81   0.78 1.35 1.07
## u2cganx031 3429  0.72  0.72  0.68   0.65 0.73 0.97
## u2cganx041 3428  0.74  0.75  0.72   0.68 0.50 0.84
## u2cganx051 3429  0.77  0.76  0.73   0.70 0.92 1.05
## u2cganx061 3429  0.77  0.77  0.75   0.71 0.62 0.95
## u2cganx071 3429  0.76  0.77  0.75   0.71 0.41 0.83
## u2cganx081 3429  0.80  0.79  0.76   0.73 0.83 1.08
## u2cganx091 3429  0.72  0.71  0.67   0.64 0.92 1.07
## u2cganx101 3429  0.65  0.66  0.60   0.57 0.36 0.94
## 
## Non missing response frequency for each item
##               0    1    2    3    4 miss
## u2cganx011 0.69 0.23 0.04 0.03 0.01 0.47
## u2cganx021 0.20 0.46 0.17 0.12 0.05 0.47
## u2cganx031 0.52 0.33 0.08 0.05 0.02 0.47
## u2cganx041 0.66 0.24 0.06 0.03 0.01 0.47
## u2cganx051 0.44 0.34 0.12 0.08 0.03 0.47
## u2cganx061 0.61 0.26 0.07 0.05 0.02 0.47
## u2cganx071 0.74 0.17 0.04 0.03 0.01 0.47
## u2cganx081 0.50 0.30 0.09 0.07 0.03 0.47
## u2cganx091 0.44 0.35 0.10 0.08 0.03 0.47
## u2cganx101 0.83 0.08 0.02 0.03 0.04 0.47
#behaviour problems
SDQitems <- subset(df, select = c("u1csdqemot1", "u1csdqcont1", "u1csdqhypt1", "u1csdqpert1"))
psych::alpha(SDQitems)
## Number of categories should be increased  in order to count frequencies.
## 
## Reliability analysis   
## Call: psych::alpha(x = SDQitems)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N    ase mean  sd median_r
##       0.66      0.67    0.62      0.33   2 0.0062  2.6 1.4     0.34
## 
##     95% confidence boundaries 
##          lower alpha upper
## Feldt     0.64  0.66  0.67
## Duhachek  0.65  0.66  0.67
## 
##  Reliability if an item is dropped:
##             raw_alpha std.alpha G6(smc) average_r S/N alpha se  var.r med.r
## u1csdqemot1      0.54      0.56    0.47      0.30 1.3   0.0092 0.0067  0.30
## u1csdqcont1      0.65      0.66    0.57      0.39 1.9   0.0070 0.0064  0.42
## u1csdqhypt1      0.53      0.55    0.47      0.29 1.2   0.0085 0.0118  0.25
## u1csdqpert1      0.60      0.63    0.54      0.36 1.7   0.0075 0.0108  0.38
## 
##  Item statistics 
##                n raw.r std.r r.cor r.drop mean  sd
## u1csdqemot1 3755  0.82  0.75  0.63   0.53  3.5 2.7
## u1csdqcont1 3755  0.54  0.65  0.45   0.36  1.5 1.2
## u1csdqhypt1 3755  0.77  0.75  0.64   0.52  3.2 2.2
## u1csdqpert1 3755  0.66  0.68  0.51   0.43  2.1 1.7

Compare the average family SES of those who participated at age 16 and those who participated at age 23

#subsetting for study participation at age 16 and 23 (TEDS 21)
data16 = df[df$pcexdata1 == 1, ]
data21a = df[df$u1cdata1 == 1,]
data21 = data21a[data21a$u2cdata1 == 1,]


#compare SES between groups       
t.test(data16$SESscore, data21$SESscore, var.equal=T)
## 
##  Two Sample t-test
## 
## data:  data16$SESscore and data21$SESscore
## t = -4.2019, df = 9639, p-value = 2.67e-05
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -0.12353923 -0.04494211
## sample estimates:
##   mean of x   mean of y 
## -0.02942628  0.05481439
#   Two Sample t-test             <-- SES differs significantly between age 16 and age 23
#
#data:  data16$SESscore and data21$SESscore
#t = -4.2019, df = 9639, p-value = 2.67e-05
#alternative hypothesis: true difference in means is not equal to 0
#95 percent confidence interval:
# -0.12353923 -0.04494211
#sample estimates:
#  mean of x   mean of y 
#-0.02942628  0.05481439 

#Step 3: #Regression models without moderation

IV: Zgcse DVs: linear: Zhqual, Zdegree, Zsoc, Zinc, Zmon, Zfina, Zwellb, Zanx, Zsdq, Zalc logistic: u1cbenf11, status_bin multi-nomial: status1

Model 1: DV ~ sex1 + SESscore Model 2: DV ~ sex1 + SESscore + Zgcse Model 3: DV ~ sex1 + SESscore + Zgcse + Zhqual

#linear regressions (w/o mod)

rm(list=ls())
ls()
## character(0)
#read in random1-dataset with only non-missing GCSE information
df <- read.csv("/Users/cgb538/Library/CloudStorage/GoogleDrive-alexandra.starr@york.ac.uk/My Drive/projects and papers/DevPsych_prediction grades adulthood/data/grades_adulth_prepared_random1.csv", header = T, strip.white = T,na.strings = c('NA', '', ' '
))


model1.hqual <- 'Zhqual ~ sex1 + SESscore'              
model1.hqualfit <- sem(model1.hqual, data = df, missing = "fiml", fixed.x = FALSE)
summary(model1.hqualfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 13 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                               448.950
##   Degrees of freedom                                 2
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -18296.800
##   Loglikelihood unrestricted model (H1)     -18296.800
##                                                       
##   Akaike (AIC)                               36611.599
##   Bayesian (BIC)                             36672.598
##   Sample-size adjusted Bayesian (SABIC)      36643.999
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zhqual ~                                                              
##     sex1             -0.051    0.032   -1.586    0.113   -0.113    0.012
##     SESscore          0.367    0.017   21.898    0.000    0.334    0.399
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.013    0.006    2.281    0.023    0.002    0.025
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zhqual           -0.002    0.020   -0.119    0.905   -0.041    0.036
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.030    0.012   -2.566    0.010   -0.053   -0.007
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zhqual            0.883    0.021   42.874    0.000    0.843    0.924
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.873    0.015   56.380    0.000    0.842    0.903
## 
## R-Square:
##                    Estimate
##     Zhqual            0.117
standardizedsolution(model1.hqualfit)
##        lhs op      rhs est.std    se      z pvalue ci.lower ci.upper
## 1   Zhqual  ~     sex1  -0.025 0.016 -1.587  0.112   -0.056    0.006
## 2   Zhqual  ~ SESscore   0.342 0.015 23.582  0.000    0.314    0.371
## 3   Zhqual ~~   Zhqual   0.883 0.010 88.748  0.000    0.863    0.902
## 4     sex1 ~~     sex1   1.000 0.000     NA     NA    1.000    1.000
## 5     sex1 ~~ SESscore   0.029 0.013  2.284  0.022    0.004    0.053
## 6 SESscore ~~ SESscore   1.000 0.000     NA     NA    1.000    1.000
## 7   Zhqual ~1           -0.002 0.020 -0.119  0.905   -0.041    0.036
## 8     sex1 ~1            0.950 0.015 63.509  0.000    0.920    0.979
## 9 SESscore ~1           -0.032 0.013 -2.565  0.010   -0.057   -0.008
model2.hqual <- 'Zhqual ~ sex1 + SESscore + Zgcse'
model2.hqualfit <- sem(model2.hqual, data = df, missing = "fiml", fixed.x = FALSE)
summary(model2.hqualfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 18 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        14
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                              1271.097
##   Degrees of freedom                                 3
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -26253.556
##   Loglikelihood unrestricted model (H1)     -26253.556
##                                                       
##   Akaike (AIC)                               52535.111
##   Bayesian (BIC)                             52629.999
##   Sample-size adjusted Bayesian (SABIC)      52585.511
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zhqual ~                                                              
##     sex1             -0.038    0.029   -1.319    0.187   -0.093    0.018
##     SESscore          0.133    0.017    7.900    0.000    0.100    0.167
##     Zgcse             0.504    0.017   30.177    0.000    0.472    0.537
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.429    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.432    0.000    0.422    0.473
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zhqual           -0.099    0.018   -5.485    0.000   -0.134   -0.063
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.034    0.012   -2.928    0.003   -0.057   -0.011
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zhqual            0.708    0.016   42.936    0.000    0.676    0.740
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.318    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zhqual            0.319
standardizedsolution(model2.hqualfit)
##         lhs op      rhs est.std    se      z pvalue ci.lower ci.upper
## 1    Zhqual  ~     sex1  -0.018 0.014 -1.320  0.187   -0.046    0.009
## 2    Zhqual  ~ SESscore   0.122 0.015  7.937  0.000    0.092    0.153
## 3    Zhqual  ~    Zgcse   0.495 0.014 34.629  0.000    0.467    0.523
## 4    Zhqual ~~   Zhqual   0.681 0.013 53.043  0.000    0.656    0.706
## 5      sex1 ~~     sex1   1.000 0.000     NA     NA    1.000    1.000
## 6      sex1 ~~ SESscore   0.030 0.012  2.433  0.015    0.006    0.055
## 7      sex1 ~~    Zgcse  -0.053 0.012 -4.249  0.000   -0.077   -0.028
## 8  SESscore ~~ SESscore   1.000 0.000     NA     NA    1.000    1.000
## 9  SESscore ~~    Zgcse   0.478 0.010 49.330  0.000    0.459    0.497
## 10    Zgcse ~~    Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 11   Zhqual ~1           -0.097 0.018 -5.501  0.000   -0.131   -0.062
## 12     sex1 ~1            0.950 0.015 63.510  0.000    0.920    0.979
## 13 SESscore ~1           -0.037 0.013 -2.927  0.003   -0.061   -0.012
## 14    Zgcse ~1            0.000 0.012  0.000  1.000   -0.024    0.024
#get change in R2 for model1 vs. model2, thus the variance explained incrementally by GCSE
(PE.model2.hqual <- parameterEstimates(model2.hqualfit, rsquare = TRUE)) # the R-squared values are in rows where "op" is "r2"
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1    Zhqual  ~     sex1 -0.038 0.029 -1.319  0.187   -0.093    0.018
## 2    Zhqual  ~ SESscore  0.133 0.017  7.900  0.000    0.100    0.167
## 3    Zhqual  ~    Zgcse  0.504 0.017 30.177  0.000    0.472    0.537
## 4    Zhqual ~~   Zhqual  0.708 0.016 42.936  0.000    0.676    0.740
## 5      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 6      sex1 ~~ SESscore  0.014 0.006  2.429  0.015    0.003    0.026
## 7      sex1 ~~    Zgcse -0.026 0.006 -4.232  0.000   -0.038   -0.014
## 8  SESscore ~~ SESscore  0.875 0.016 56.318  0.000    0.844    0.905
## 9  SESscore ~~    Zgcse  0.447 0.013 34.432  0.000    0.422    0.473
## 10    Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 11   Zhqual ~1          -0.099 0.018 -5.485  0.000   -0.134   -0.063
## 12     sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 13 SESscore ~1          -0.034 0.012 -2.928  0.003   -0.057   -0.011
## 14    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 15   Zhqual r2   Zhqual  0.319    NA     NA     NA       NA       NA
PE.model2.hqual$est[PE.model2.hqual$op == "r2"]
## [1] 0.3187157
(PE.model1.hqual <- parameterEstimates(model1.hqualfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1    Zhqual  ~     sex1 -0.051 0.032 -1.586  0.113   -0.113    0.012
## 2    Zhqual  ~ SESscore  0.367 0.017 21.898  0.000    0.334    0.399
## 3    Zhqual ~~   Zhqual  0.883 0.021 42.874  0.000    0.843    0.924
## 4      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 5      sex1 ~~ SESscore  0.013 0.006  2.281  0.023    0.002    0.025
## 6  SESscore ~~ SESscore  0.873 0.015 56.380  0.000    0.842    0.903
## 7    Zhqual ~1          -0.002 0.020 -0.119  0.905   -0.041    0.036
## 8      sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 9  SESscore ~1          -0.030 0.012 -2.566  0.010   -0.053   -0.007
## 10   Zhqual r2   Zhqual  0.117    NA     NA     NA       NA       NA
PE.model1.hqual$est[PE.model1.hqual$op == "r2"]
## [1] 0.1172887
r2diff2.hqual <- (PE.model2.hqual$est[PE.model2.hqual$op == "r2"] - PE.model1.hqual$est[PE.model1.hqual$op == "r2"])
print(r2diff2.hqual)  #difference model1 vs 2, incremental explained variance by GCSE
## [1] 0.2014269
model1.degree <- 'Zdegree ~ sex1 + SESscore'
model1.degreefit <- sem(model1.degree, data = df, missing = "fiml", fixed.x = FALSE)
summary(model1.degreefit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 15 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                26.403
##   Degrees of freedom                                 2
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -15792.225
##   Loglikelihood unrestricted model (H1)     -15792.225
##                                                       
##   Akaike (AIC)                               31602.450
##   Bayesian (BIC)                             31663.449
##   Sample-size adjusted Bayesian (SABIC)      31634.850
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zdegree ~                                                             
##     sex1             -0.056    0.049   -1.138    0.255   -0.153    0.040
##     SESscore          0.138    0.027    5.095    0.000    0.085    0.192
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.013    0.006    2.291    0.022    0.002    0.025
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zdegree          -0.011    0.030   -0.374    0.708   -0.070    0.047
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.030    0.012   -2.520    0.012   -0.052   -0.007
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zdegree           0.984    0.033   29.785    0.000    0.920    1.049
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.873    0.015   56.386    0.000    0.842    0.903
## 
## R-Square:
##                    Estimate
##     Zdegree           0.017
standardizedsolution(model1.degreefit)
##        lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1  Zdegree  ~     sex1  -0.028 0.025  -1.139  0.255   -0.076    0.020
## 2  Zdegree  ~ SESscore   0.129 0.025   5.157  0.000    0.080    0.178
## 3  Zdegree ~~  Zdegree   0.983 0.007 148.601  0.000    0.970    0.996
## 4     sex1 ~~     sex1   1.000 0.000      NA     NA    1.000    1.000
## 5     sex1 ~~ SESscore   0.029 0.013   2.294  0.022    0.004    0.053
## 6 SESscore ~~ SESscore   1.000 0.000      NA     NA    1.000    1.000
## 7  Zdegree ~1           -0.011 0.030  -0.374  0.708   -0.070    0.047
## 8     sex1 ~1            0.950 0.015  63.510  0.000    0.920    0.979
## 9 SESscore ~1           -0.032 0.013  -2.520  0.012   -0.056   -0.007
model2.degree <- 'Zdegree ~ sex1 + SESscore + Zgcse'
model2.degreefit <- sem(model2.degree, data = df, missing = "fiml", fixed.x = FALSE)
summary(model2.degreefit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 21 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        14
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                               152.079
##   Degrees of freedom                                 3
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -24097.216
##   Loglikelihood unrestricted model (H1)     -24097.216
##                                                       
##   Akaike (AIC)                               48222.432
##   Bayesian (BIC)                             48317.320
##   Sample-size adjusted Bayesian (SABIC)      48272.832
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zdegree ~                                                             
##     sex1             -0.080    0.048   -1.673    0.094   -0.173    0.014
##     SESscore          0.014    0.028    0.506    0.613   -0.041    0.070
##     Zgcse             0.375    0.033   11.366    0.000    0.310    0.439
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.433    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.233    0.000   -0.038   -0.014
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.438    0.000    0.422    0.473
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zdegree          -0.170    0.032   -5.308    0.000   -0.232   -0.107
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.034    0.012   -2.928    0.003   -0.057   -0.011
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zdegree           0.917    0.031   29.791    0.000    0.857    0.978
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.312    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.957    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zdegree           0.139
standardizedsolution(model2.degreefit)
##         lhs op      rhs est.std    se      z pvalue ci.lower ci.upper
## 1   Zdegree  ~     sex1  -0.038 0.023 -1.678  0.093   -0.083    0.006
## 2   Zdegree  ~ SESscore   0.013 0.026  0.506  0.613   -0.037    0.064
## 3   Zdegree  ~    Zgcse   0.363 0.029 12.537  0.000    0.306    0.420
## 4   Zdegree ~~  Zdegree   0.861 0.020 43.925  0.000    0.822    0.899
## 5      sex1 ~~     sex1   1.000 0.000     NA     NA    1.000    1.000
## 6      sex1 ~~ SESscore   0.030 0.012  2.436  0.015    0.006    0.055
## 7      sex1 ~~    Zgcse  -0.053 0.012 -4.251  0.000   -0.077   -0.028
## 8  SESscore ~~ SESscore   1.000 0.000     NA     NA    1.000    1.000
## 9  SESscore ~~    Zgcse   0.478 0.010 49.349  0.000    0.459    0.497
## 10    Zgcse ~~    Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 11  Zdegree ~1           -0.164 0.030 -5.408  0.000   -0.224   -0.105
## 12     sex1 ~1            0.950 0.015 63.509  0.000    0.920    0.979
## 13 SESscore ~1           -0.037 0.013 -2.928  0.003   -0.061   -0.012
## 14    Zgcse ~1            0.000 0.012  0.000  1.000   -0.024    0.024
#get change in R2 for model1 vs. model2, thus the variance explained incrementally by GCSE
(PE.model2.degree <- parameterEstimates(model2.degreefit, rsquare = TRUE))
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1   Zdegree  ~     sex1 -0.080 0.048 -1.673  0.094   -0.173    0.014
## 2   Zdegree  ~ SESscore  0.014 0.028  0.506  0.613   -0.041    0.070
## 3   Zdegree  ~    Zgcse  0.375 0.033 11.366  0.000    0.310    0.439
## 4   Zdegree ~~  Zdegree  0.917 0.031 29.791  0.000    0.857    0.978
## 5      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 6      sex1 ~~ SESscore  0.014 0.006  2.433  0.015    0.003    0.026
## 7      sex1 ~~    Zgcse -0.026 0.006 -4.233  0.000   -0.038   -0.014
## 8  SESscore ~~ SESscore  0.875 0.016 56.312  0.000    0.844    0.905
## 9  SESscore ~~    Zgcse  0.447 0.013 34.438  0.000    0.422    0.473
## 10    Zgcse ~~    Zgcse  1.000 0.018 56.957  0.000    0.965    1.034
## 11  Zdegree ~1          -0.170 0.032 -5.308  0.000   -0.232   -0.107
## 12     sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 13 SESscore ~1          -0.034 0.012 -2.928  0.003   -0.057   -0.011
## 14    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 15  Zdegree r2  Zdegree  0.139    NA     NA     NA       NA       NA
PE.model2.degree$est[PE.model2.degree$op == "r2"]
## [1] 0.1393086
(PE.model1.degree <- parameterEstimates(model1.degreefit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1   Zdegree  ~     sex1 -0.056 0.049 -1.138  0.255   -0.153    0.040
## 2   Zdegree  ~ SESscore  0.138 0.027  5.095  0.000    0.085    0.192
## 3   Zdegree ~~  Zdegree  0.984 0.033 29.785  0.000    0.920    1.049
## 4      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 5      sex1 ~~ SESscore  0.013 0.006  2.291  0.022    0.002    0.025
## 6  SESscore ~~ SESscore  0.873 0.015 56.386  0.000    0.842    0.903
## 7   Zdegree ~1          -0.011 0.030 -0.374  0.708   -0.070    0.047
## 8      sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 9  SESscore ~1          -0.030 0.012 -2.520  0.012   -0.052   -0.007
## 10  Zdegree r2  Zdegree  0.017    NA     NA     NA       NA       NA
PE.model1.degree$est[PE.model1.degree$op == "r2"]
## [1] 0.01726796
r2diff2.degree <- (PE.model2.degree$est[PE.model2.degree$op == "r2"] - PE.model1.degree$est[PE.model1.degree$op == "r2"])
print(r2diff2.degree)     #difference model1 vs 2, incremental explained variance by GCSE
## [1] 0.1220407
model1.ocprestige <- 'Zsoc ~ sex1 + SESscore'
model1.ocprestigefit <- sem(model1.ocprestige, data = df, missing = "fiml", fixed.x = FALSE)
summary(model1.ocprestigefit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 18 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                64.154
##   Degrees of freedom                                 2
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -15647.064
##   Loglikelihood unrestricted model (H1)     -15647.064
##                                                       
##   Akaike (AIC)                               31312.128
##   Bayesian (BIC)                             31373.127
##   Sample-size adjusted Bayesian (SABIC)      31344.527
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zsoc ~                                                                
##     sex1              0.156    0.050    3.128    0.002    0.058    0.253
##     SESscore          0.197    0.027    7.361    0.000    0.144    0.249
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.013    0.006    2.291    0.022    0.002    0.025
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsoc             -0.026    0.030   -0.854    0.393   -0.085    0.033
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.030    0.012   -2.538    0.011   -0.053   -0.007
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsoc              0.962    0.033   29.022    0.000    0.897    1.027
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.873    0.015   56.387    0.000    0.842    0.903
## 
## R-Square:
##                    Estimate
##     Zsoc              0.041
standardizedsolution(model1.ocprestigefit)
##        lhs op      rhs est.std    se      z pvalue ci.lower ci.upper
## 1     Zsoc  ~     sex1   0.078 0.025  3.141  0.002    0.029    0.126
## 2     Zsoc  ~ SESscore   0.184 0.024  7.538  0.000    0.136    0.231
## 3     Zsoc ~~     Zsoc   0.959 0.010 98.554  0.000    0.940    0.979
## 4     sex1 ~~     sex1   1.000 0.000     NA     NA    1.000    1.000
## 5     sex1 ~~ SESscore   0.029 0.013  2.294  0.022    0.004    0.053
## 6 SESscore ~~ SESscore   1.000 0.000     NA     NA    1.000    1.000
## 7     Zsoc ~1           -0.026 0.030 -0.854  0.393   -0.085    0.033
## 8     sex1 ~1            0.950 0.015 63.509  0.000    0.920    0.979
## 9 SESscore ~1           -0.032 0.013 -2.537  0.011   -0.056   -0.007
model2.ocprestige <- 'Zsoc ~ sex1 + SESscore + Zgcse'
model2.ocprestigefit <- sem(model2.ocprestige, data = df, missing = "fiml", fixed.x = FALSE)
summary(model2.ocprestigefit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 21 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        14
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                               165.717
##   Degrees of freedom                                 3
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -23964.112
##   Loglikelihood unrestricted model (H1)     -23964.112
##                                                       
##   Akaike (AIC)                               47956.223
##   Bayesian (BIC)                             48051.111
##   Sample-size adjusted Bayesian (SABIC)      48006.623
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zsoc ~                                                                
##     sex1              0.163    0.048    3.385    0.001    0.069    0.258
##     SESscore          0.069    0.029    2.407    0.016    0.013    0.126
##     Zgcse             0.286    0.028   10.148    0.000    0.231    0.342
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.433    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.438    0.000    0.422    0.473
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsoc             -0.042    0.029   -1.422    0.155   -0.099    0.016
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.034    0.012   -2.931    0.003   -0.057   -0.011
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsoc              0.906    0.031   29.033    0.000    0.845    0.967
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.312    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zsoc              0.107
standardizedsolution(model2.ocprestigefit)
##         lhs op      rhs est.std    se      z pvalue ci.lower ci.upper
## 1      Zsoc  ~     sex1   0.081 0.024  3.396  0.001    0.034    0.128
## 2      Zsoc  ~ SESscore   0.065 0.027  2.413  0.016    0.012    0.117
## 3      Zsoc  ~    Zgcse   0.284 0.027 10.644  0.000    0.232    0.337
## 4      Zsoc ~~     Zsoc   0.893 0.015 59.622  0.000    0.864    0.922
## 5      sex1 ~~     sex1   1.000 0.000     NA     NA    1.000    1.000
## 6      sex1 ~~ SESscore   0.030 0.012  2.436  0.015    0.006    0.055
## 7      sex1 ~~    Zgcse  -0.053 0.012 -4.250  0.000   -0.077   -0.028
## 8  SESscore ~~ SESscore   1.000 0.000     NA     NA    1.000    1.000
## 9  SESscore ~~    Zgcse   0.478 0.010 49.350  0.000    0.459    0.497
## 10    Zgcse ~~    Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 11     Zsoc ~1           -0.042 0.029 -1.423  0.155   -0.099    0.016
## 12     sex1 ~1            0.950 0.015 63.510  0.000    0.920    0.979
## 13 SESscore ~1           -0.037 0.013 -2.930  0.003   -0.061   -0.012
## 14    Zgcse ~1            0.000 0.012  0.000  1.000   -0.024    0.024
model3.ocprestige <- 'Zsoc ~ sex1 + SESscore + Zgcse + Zhqual'
model3.ocprestigefit <- sem(model3.ocprestige, data = df, missing = "fiml", fixed.x = FALSE)
summary(model3.ocprestigefit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 24 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        20
## 
##   Number of observations                          6488
##   Number of missing patterns                         7
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                               208.800
##   Degrees of freedom                                 4
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -28540.986
##   Loglikelihood unrestricted model (H1)     -28540.986
##                                                       
##   Akaike (AIC)                               57121.972
##   Bayesian (BIC)                             57257.526
##   Sample-size adjusted Bayesian (SABIC)      57193.971
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zsoc ~                                                                
##     sex1              0.183    0.048    3.824    0.000    0.089    0.276
##     SESscore          0.046    0.029    1.606    0.108   -0.010    0.102
##     Zgcse             0.191    0.031    6.066    0.000    0.129    0.252
##     Zhqual            0.168    0.025    6.601    0.000    0.118    0.218
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.428    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     Zhqual           -0.021    0.008   -2.610    0.009   -0.036   -0.005
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.433    0.000    0.422    0.473
##     Zhqual            0.342    0.015   22.301    0.000    0.312    0.372
##   Zgcse ~~                                                              
##     Zhqual            0.565    0.018   31.575    0.000    0.530    0.601
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsoc             -0.000    0.030   -0.003    0.998   -0.058    0.058
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.034    0.012   -2.930    0.003   -0.057   -0.011
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
##     Zhqual           -0.121    0.016   -7.531    0.000   -0.153   -0.090
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsoc              0.883    0.030   29.022    0.000    0.823    0.942
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.318    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     Zhqual            1.040    0.024   42.563    0.000    0.992    1.088
## 
## R-Square:
##                    Estimate
##     Zsoc              0.122
standardizedsolution(model3.ocprestigefit)
##         lhs op      rhs est.std    se      z pvalue ci.lower ci.upper
## 1      Zsoc  ~     sex1   0.091 0.024  3.841  0.000    0.045    0.137
## 2      Zsoc  ~ SESscore   0.043 0.027  1.608  0.108   -0.009    0.095
## 3      Zsoc  ~    Zgcse   0.190 0.031  6.184  0.000    0.130    0.250
## 4      Zsoc  ~   Zhqual   0.171 0.026  6.649  0.000    0.120    0.221
## 5      Zsoc ~~     Zsoc   0.878 0.015 58.145  0.000    0.849    0.908
## 6      sex1 ~~     sex1   1.000 0.000     NA     NA    1.000    1.000
## 7      sex1 ~~ SESscore   0.030 0.012  2.432  0.015    0.006    0.055
## 8      sex1 ~~    Zgcse  -0.053 0.012 -4.250  0.000   -0.077   -0.028
## 9      sex1 ~~   Zhqual  -0.041 0.016 -2.618  0.009   -0.071   -0.010
## 10 SESscore ~~ SESscore   1.000 0.000     NA     NA    1.000    1.000
## 11 SESscore ~~    Zgcse   0.478 0.010 49.332  0.000    0.459    0.497
## 12 SESscore ~~   Zhqual   0.359 0.014 26.420  0.000    0.332    0.385
## 13    Zgcse ~~    Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 14    Zgcse ~~   Zhqual   0.555 0.012 47.947  0.000    0.532    0.577
## 15   Zhqual ~~   Zhqual   1.000 0.000     NA     NA    1.000    1.000
## 16     Zsoc ~1            0.000 0.030 -0.003  0.998   -0.058    0.058
## 17     sex1 ~1            0.950 0.015 63.509  0.000    0.920    0.979
## 18 SESscore ~1           -0.037 0.013 -2.929  0.003   -0.061   -0.012
## 19    Zgcse ~1            0.000 0.012  0.000  1.000   -0.024    0.024
## 20   Zhqual ~1           -0.119 0.016 -7.597  0.000   -0.150   -0.088
#get change in R2 for model1 vs. model2 vs. model3
(PE.model3.ocprestige <- parameterEstimates(model3.ocprestigefit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1      Zsoc  ~     sex1  0.183 0.048  3.824  0.000    0.089    0.276
## 2      Zsoc  ~ SESscore  0.046 0.029  1.606  0.108   -0.010    0.102
## 3      Zsoc  ~    Zgcse  0.191 0.031  6.066  0.000    0.129    0.252
## 4      Zsoc  ~   Zhqual  0.168 0.025  6.601  0.000    0.118    0.218
## 5      Zsoc ~~     Zsoc  0.883 0.030 29.022  0.000    0.823    0.942
## 6      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 7      sex1 ~~ SESscore  0.014 0.006  2.428  0.015    0.003    0.026
## 8      sex1 ~~    Zgcse -0.026 0.006 -4.232  0.000   -0.038   -0.014
## 9      sex1 ~~   Zhqual -0.021 0.008 -2.610  0.009   -0.036   -0.005
## 10 SESscore ~~ SESscore  0.875 0.016 56.318  0.000    0.844    0.905
## 11 SESscore ~~    Zgcse  0.447 0.013 34.433  0.000    0.422    0.473
## 12 SESscore ~~   Zhqual  0.342 0.015 22.301  0.000    0.312    0.372
## 13    Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 14    Zgcse ~~   Zhqual  0.565 0.018 31.575  0.000    0.530    0.601
## 15   Zhqual ~~   Zhqual  1.040 0.024 42.563  0.000    0.992    1.088
## 16     Zsoc ~1           0.000 0.030 -0.003  0.998   -0.058    0.058
## 17     sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 18 SESscore ~1          -0.034 0.012 -2.930  0.003   -0.057   -0.011
## 19    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 20   Zhqual ~1          -0.121 0.016 -7.531  0.000   -0.153   -0.090
## 21     Zsoc r2     Zsoc  0.122    NA     NA     NA       NA       NA
PE.model3.ocprestige$est[PE.model3.ocprestige$op == "r2"]
## [1] 0.1216973
(PE.model2.ocprestige <- parameterEstimates(model2.ocprestigefit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1      Zsoc  ~     sex1  0.163 0.048  3.385  0.001    0.069    0.258
## 2      Zsoc  ~ SESscore  0.069 0.029  2.407  0.016    0.013    0.126
## 3      Zsoc  ~    Zgcse  0.286 0.028 10.148  0.000    0.231    0.342
## 4      Zsoc ~~     Zsoc  0.906 0.031 29.033  0.000    0.845    0.967
## 5      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 6      sex1 ~~ SESscore  0.014 0.006  2.433  0.015    0.003    0.026
## 7      sex1 ~~    Zgcse -0.026 0.006 -4.232  0.000   -0.038   -0.014
## 8  SESscore ~~ SESscore  0.875 0.016 56.312  0.000    0.844    0.905
## 9  SESscore ~~    Zgcse  0.447 0.013 34.438  0.000    0.422    0.473
## 10    Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 11     Zsoc ~1          -0.042 0.029 -1.422  0.155   -0.099    0.016
## 12     sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 13 SESscore ~1          -0.034 0.012 -2.931  0.003   -0.057   -0.011
## 14    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 15     Zsoc r2     Zsoc  0.107    NA     NA     NA       NA       NA
PE.model2.ocprestige$est[PE.model2.ocprestige$op == "r2"]
## [1] 0.1070241
(PE.model1.ocprestige <- parameterEstimates(model1.ocprestigefit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1      Zsoc  ~     sex1  0.156 0.050  3.128  0.002    0.058    0.253
## 2      Zsoc  ~ SESscore  0.197 0.027  7.361  0.000    0.144    0.249
## 3      Zsoc ~~     Zsoc  0.962 0.033 29.022  0.000    0.897    1.027
## 4      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 5      sex1 ~~ SESscore  0.013 0.006  2.291  0.022    0.002    0.025
## 6  SESscore ~~ SESscore  0.873 0.015 56.387  0.000    0.842    0.903
## 7      Zsoc ~1          -0.026 0.030 -0.854  0.393   -0.085    0.033
## 8      sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 9  SESscore ~1          -0.030 0.012 -2.538  0.011   -0.053   -0.007
## 10     Zsoc r2     Zsoc  0.041    NA     NA     NA       NA       NA
PE.model1.ocprestige$est[PE.model1.ocprestige$op == "r2"]
## [1] 0.04052599
r2diff2.ocprestige <- (PE.model2.ocprestige$est[PE.model2.ocprestige$op == "r2"] - PE.model1.ocprestige$est[PE.model1.ocprestige$op == "r2"])
print(r2diff2.ocprestige)    #difference model1 vs 2, incremental explained variance by GCSE
## [1] 0.06649815
r2diff3.ocprestige <- (PE.model3.ocprestige$est[PE.model3.ocprestige$op == "r2"] - PE.model2.ocprestige$est[PE.model2.ocprestige$op == "r2"])
print(r2diff3.ocprestige)    #difference model2 vs 3, incremental explained variance by highest qualification
## [1] 0.01467316
model1.inc <- 'Zinc ~ sex1 + SESscore'
model1.incfit <- sem(model1.inc, data = df, missing = "fiml", fixed.x = FALSE)
summary(model1.incfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 17 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                91.241
##   Degrees of freedom                                 2
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -15910.213
##   Loglikelihood unrestricted model (H1)     -15910.213
##                                                       
##   Akaike (AIC)                               31838.427
##   Bayesian (BIC)                             31899.426
##   Sample-size adjusted Bayesian (SABIC)      31870.826
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zinc ~                                                                
##     sex1              0.385    0.047    8.197    0.000    0.293    0.477
##     SESscore          0.123    0.025    4.895    0.000    0.074    0.172
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.013    0.006    2.286    0.022    0.002    0.025
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zinc             -0.120    0.028   -4.246    0.000   -0.176   -0.065
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.030    0.012   -2.525    0.012   -0.053   -0.007
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zinc              0.952    0.031   30.663    0.000    0.891    1.013
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.873    0.015   56.388    0.000    0.842    0.903
## 
## R-Square:
##                    Estimate
##     Zinc              0.051
standardizedsolution(model1.incfit)
##        lhs op      rhs est.std    se      z pvalue ci.lower ci.upper
## 1     Zinc  ~     sex1   0.192 0.023  8.413  0.000    0.147    0.236
## 2     Zinc  ~ SESscore   0.115 0.023  4.939  0.000    0.069    0.160
## 3     Zinc ~~     Zinc   0.949 0.010 92.864  0.000    0.929    0.969
## 4     sex1 ~~     sex1   1.000 0.000     NA     NA    1.000    1.000
## 5     sex1 ~~ SESscore   0.029 0.013  2.289  0.022    0.004    0.053
## 6 SESscore ~~ SESscore   1.000 0.000     NA     NA    1.000    1.000
## 7     Zinc ~1           -0.120 0.028 -4.278  0.000   -0.175   -0.065
## 8     sex1 ~1            0.950 0.015 63.510  0.000    0.920    0.979
## 9 SESscore ~1           -0.032 0.013 -2.525  0.012   -0.056   -0.007
model2.inc <- 'Zinc ~ sex1 + SESscore + Zgcse'
model2.incfit <- sem(model2.inc, data = df, missing = "fiml", fixed.x = FALSE)
summary(model2.incfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 22 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        14
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                               133.447
##   Degrees of freedom                                 3
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -24256.940
##   Loglikelihood unrestricted model (H1)     -24256.940
##                                                       
##   Akaike (AIC)                               48541.879
##   Bayesian (BIC)                             48636.767
##   Sample-size adjusted Bayesian (SABIC)      48592.279
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zinc ~                                                                
##     sex1              0.386    0.046    8.315    0.000    0.295    0.477
##     SESscore          0.044    0.028    1.590    0.112   -0.010    0.098
##     Zgcse             0.173    0.027    6.504    0.000    0.121    0.225
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.432    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.437    0.000    0.422    0.473
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zinc             -0.126    0.028   -4.475    0.000   -0.181   -0.071
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.034    0.012   -2.930    0.003   -0.057   -0.011
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zinc              0.931    0.030   30.667    0.000    0.871    0.991
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.312    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zinc              0.072
standardizedsolution(model2.incfit)
##         lhs op      rhs est.std    se      z pvalue ci.lower ci.upper
## 1      Zinc  ~     sex1   0.192 0.023  8.515  0.000    0.148    0.237
## 2      Zinc  ~ SESscore   0.041 0.026  1.592  0.111   -0.010    0.092
## 3      Zinc  ~    Zgcse   0.173 0.026  6.603  0.000    0.122    0.224
## 4      Zinc ~~     Zinc   0.928 0.012 79.277  0.000    0.905    0.951
## 5      sex1 ~~     sex1   1.000 0.000     NA     NA    1.000    1.000
## 6      sex1 ~~ SESscore   0.030 0.012  2.436  0.015    0.006    0.055
## 7      sex1 ~~    Zgcse  -0.053 0.012 -4.250  0.000   -0.077   -0.028
## 8  SESscore ~~ SESscore   1.000 0.000     NA     NA    1.000    1.000
## 9  SESscore ~~    Zgcse   0.478 0.010 49.347  0.000    0.459    0.497
## 10    Zgcse ~~    Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 11     Zinc ~1           -0.125 0.028 -4.508  0.000   -0.180   -0.071
## 12     sex1 ~1            0.950 0.015 63.509  0.000    0.920    0.979
## 13 SESscore ~1           -0.037 0.013 -2.929  0.003   -0.061   -0.012
## 14    Zgcse ~1            0.000 0.012  0.000  1.000   -0.024    0.024
model3.inc <- 'Zinc ~ sex1 + SESscore + Zgcse + Zhqual'
model3.incfit <- sem(model3.inc, data = df, missing = "fiml", fixed.x = FALSE)
summary(model3.incfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 26 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        20
## 
##   Number of observations                          6488
##   Number of missing patterns                         7
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                               134.088
##   Degrees of freedom                                 4
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -28855.035
##   Loglikelihood unrestricted model (H1)     -28855.035
##                                                       
##   Akaike (AIC)                               57750.069
##   Bayesian (BIC)                             57885.624
##   Sample-size adjusted Bayesian (SABIC)      57822.069
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zinc ~                                                                
##     sex1              0.388    0.046    8.350    0.000    0.297    0.479
##     SESscore          0.041    0.028    1.482    0.138   -0.013    0.096
##     Zgcse             0.162    0.030    5.404    0.000    0.103    0.221
##     Zhqual            0.020    0.025    0.802    0.423   -0.029    0.069
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.427    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     Zhqual           -0.021    0.008   -2.607    0.009   -0.036   -0.005
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.432    0.000    0.422    0.473
##     Zhqual            0.342    0.015   22.279    0.000    0.312    0.372
##   Zgcse ~~                                                              
##     Zhqual            0.565    0.018   31.552    0.000    0.530    0.600
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zinc             -0.121    0.029   -4.210    0.000   -0.177   -0.065
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.034    0.012   -2.929    0.003   -0.057   -0.011
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
##     Zhqual           -0.121    0.016   -7.517    0.000   -0.153   -0.089
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zinc              0.931    0.030   30.666    0.000    0.871    0.990
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.318    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     Zhqual            1.040    0.024   42.569    0.000    0.992    1.087
## 
## R-Square:
##                    Estimate
##     Zinc              0.073
standardizedsolution(model3.incfit)
##         lhs op      rhs est.std    se      z pvalue ci.lower ci.upper
## 1      Zinc  ~     sex1   0.194 0.023  8.553  0.000    0.149    0.238
## 2      Zinc  ~ SESscore   0.039 0.026  1.484  0.138   -0.012    0.090
## 3      Zinc  ~    Zgcse   0.162 0.030  5.462  0.000    0.104    0.220
## 4      Zinc  ~   Zhqual   0.020 0.025  0.802  0.423   -0.029    0.070
## 5      Zinc ~~     Zinc   0.927 0.012 79.254  0.000    0.904    0.950
## 6      sex1 ~~     sex1   1.000 0.000     NA     NA    1.000    1.000
## 7      sex1 ~~ SESscore   0.030 0.012  2.431  0.015    0.006    0.055
## 8      sex1 ~~    Zgcse  -0.053 0.012 -4.250  0.000   -0.077   -0.028
## 9      sex1 ~~   Zhqual  -0.041 0.016 -2.616  0.009   -0.071   -0.010
## 10 SESscore ~~ SESscore   1.000 0.000     NA     NA    1.000    1.000
## 11 SESscore ~~    Zgcse   0.478 0.010 49.330  0.000    0.459    0.497
## 12 SESscore ~~   Zhqual   0.359 0.014 26.384  0.000    0.332    0.385
## 13    Zgcse ~~    Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 14    Zgcse ~~   Zhqual   0.554 0.012 47.878  0.000    0.532    0.577
## 15   Zhqual ~~   Zhqual   1.000 0.000     NA     NA    1.000    1.000
## 16     Zinc ~1           -0.121 0.028 -4.238  0.000   -0.176   -0.065
## 17     sex1 ~1            0.950 0.015 63.510  0.000    0.920    0.979
## 18 SESscore ~1           -0.037 0.013 -2.928  0.003   -0.061   -0.012
## 19    Zgcse ~1            0.000 0.012  0.000  1.000   -0.024    0.024
## 20   Zhqual ~1           -0.119 0.016 -7.582  0.000   -0.149   -0.088
#get change in R2 for model1 vs. model2 vs. model3
(PE.model3.inc <- parameterEstimates(model3.incfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1      Zinc  ~     sex1  0.388 0.046  8.350  0.000    0.297    0.479
## 2      Zinc  ~ SESscore  0.041 0.028  1.482  0.138   -0.013    0.096
## 3      Zinc  ~    Zgcse  0.162 0.030  5.404  0.000    0.103    0.221
## 4      Zinc  ~   Zhqual  0.020 0.025  0.802  0.423   -0.029    0.069
## 5      Zinc ~~     Zinc  0.931 0.030 30.666  0.000    0.871    0.990
## 6      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 7      sex1 ~~ SESscore  0.014 0.006  2.427  0.015    0.003    0.026
## 8      sex1 ~~    Zgcse -0.026 0.006 -4.232  0.000   -0.038   -0.014
## 9      sex1 ~~   Zhqual -0.021 0.008 -2.607  0.009   -0.036   -0.005
## 10 SESscore ~~ SESscore  0.875 0.016 56.318  0.000    0.844    0.905
## 11 SESscore ~~    Zgcse  0.447 0.013 34.432  0.000    0.422    0.473
## 12 SESscore ~~   Zhqual  0.342 0.015 22.279  0.000    0.312    0.372
## 13    Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 14    Zgcse ~~   Zhqual  0.565 0.018 31.552  0.000    0.530    0.600
## 15   Zhqual ~~   Zhqual  1.040 0.024 42.569  0.000    0.992    1.087
## 16     Zinc ~1          -0.121 0.029 -4.210  0.000   -0.177   -0.065
## 17     sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 18 SESscore ~1          -0.034 0.012 -2.929  0.003   -0.057   -0.011
## 19    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 20   Zhqual ~1          -0.121 0.016 -7.517  0.000   -0.153   -0.089
## 21     Zinc r2     Zinc  0.073    NA     NA     NA       NA       NA
PE.model3.inc$est[PE.model3.inc$op == "r2"]
## [1] 0.07256701
(PE.model2.inc <- parameterEstimates(model2.incfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1      Zinc  ~     sex1  0.386 0.046  8.315  0.000    0.295    0.477
## 2      Zinc  ~ SESscore  0.044 0.028  1.590  0.112   -0.010    0.098
## 3      Zinc  ~    Zgcse  0.173 0.027  6.504  0.000    0.121    0.225
## 4      Zinc ~~     Zinc  0.931 0.030 30.667  0.000    0.871    0.991
## 5      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 6      sex1 ~~ SESscore  0.014 0.006  2.432  0.015    0.003    0.026
## 7      sex1 ~~    Zgcse -0.026 0.006 -4.232  0.000   -0.038   -0.014
## 8  SESscore ~~ SESscore  0.875 0.016 56.312  0.000    0.844    0.905
## 9  SESscore ~~    Zgcse  0.447 0.013 34.437  0.000    0.422    0.473
## 10    Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 11     Zinc ~1          -0.126 0.028 -4.475  0.000   -0.181   -0.071
## 12     sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 13 SESscore ~1          -0.034 0.012 -2.930  0.003   -0.057   -0.011
## 14    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 15     Zinc r2     Zinc  0.072    NA     NA     NA       NA       NA
PE.model2.inc$est[PE.model2.inc$op == "r2"]
## [1] 0.07238421
(PE.model1.inc <- parameterEstimates(model1.incfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1      Zinc  ~     sex1  0.385 0.047  8.197  0.000    0.293    0.477
## 2      Zinc  ~ SESscore  0.123 0.025  4.895  0.000    0.074    0.172
## 3      Zinc ~~     Zinc  0.952 0.031 30.663  0.000    0.891    1.013
## 4      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 5      sex1 ~~ SESscore  0.013 0.006  2.286  0.022    0.002    0.025
## 6  SESscore ~~ SESscore  0.873 0.015 56.388  0.000    0.842    0.903
## 7      Zinc ~1          -0.120 0.028 -4.246  0.000   -0.176   -0.065
## 8      sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 9  SESscore ~1          -0.030 0.012 -2.525  0.012   -0.053   -0.007
## 10     Zinc r2     Zinc  0.051    NA     NA     NA       NA       NA
PE.model1.inc$est[PE.model1.inc$op == "r2"]
## [1] 0.05123494
r2diff2.inc <- (PE.model2.inc$est[PE.model2.inc$op == "r2"] - PE.model1.inc$est[PE.model1.inc$op == "r2"])
print(r2diff2.inc)    #difference model1 vs 2, incremental explained variance by GCSE
## [1] 0.02114927
r2diff3.inc <- (PE.model3.inc$est[PE.model3.inc$op == "r2"] - PE.model2.inc$est[PE.model2.inc$op == "r2"])
print(r2diff3.inc)    #difference model2 vs 3, incremental explained variance by highest qualification
## [1] 0.0001827967
model1.mon <- 'Zmon ~ sex1 + SESscore'
model1.monfit <- sem(model1.mon, data = df, missing = "fiml", fixed.x = FALSE)
summary(model1.monfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 16 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                56.036
##   Degrees of freedom                                 2
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -18452.108
##   Loglikelihood unrestricted model (H1)     -18452.108
##                                                       
##   Akaike (AIC)                               36922.215
##   Bayesian (BIC)                             36983.215
##   Sample-size adjusted Bayesian (SABIC)      36954.615
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zmon ~                                                                
##     sex1             -0.232    0.034   -6.887    0.000   -0.298   -0.166
##     SESscore         -0.047    0.018   -2.652    0.008   -0.082   -0.012
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.013    0.006    2.288    0.022    0.002    0.025
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zmon              0.093    0.021    4.422    0.000    0.052    0.134
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.029    0.012   -2.514    0.012   -0.052   -0.006
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zmon              0.985    0.023   42.777    0.000    0.939    1.030
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.873    0.015   56.387    0.000    0.842    0.903
## 
## R-Square:
##                    Estimate
##     Zmon              0.016
standardizedsolution(model1.monfit)
##        lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1     Zmon  ~     sex1  -0.116 0.017  -6.945  0.000   -0.149   -0.083
## 2     Zmon  ~ SESscore  -0.044 0.017  -2.654  0.008   -0.077   -0.012
## 3     Zmon ~~     Zmon   0.984 0.004 237.936  0.000    0.976    0.992
## 4     sex1 ~~     sex1   1.000 0.000      NA     NA    1.000    1.000
## 5     sex1 ~~ SESscore   0.029 0.013   2.290  0.022    0.004    0.053
## 6 SESscore ~~ SESscore   1.000 0.000      NA     NA    1.000    1.000
## 7     Zmon ~1            0.093 0.021   4.441  0.000    0.052    0.133
## 8     sex1 ~1            0.950 0.015  63.510  0.000    0.920    0.979
## 9 SESscore ~1           -0.032 0.013  -2.514  0.012   -0.056   -0.007
model2.mon <- 'Zmon ~ sex1 + SESscore + Zgcse'
model2.monfit <- sem(model2.mon, data = df, missing = "fiml", fixed.x = FALSE)
summary(model2.monfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 17 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        14
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                78.621
##   Degrees of freedom                                 3
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -26808.644
##   Loglikelihood unrestricted model (H1)     -26808.644
##                                                       
##   Akaike (AIC)                               53645.288
##   Bayesian (BIC)                             53740.176
##   Sample-size adjusted Bayesian (SABIC)      53695.688
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zmon ~                                                                
##     sex1             -0.230    0.034   -6.850    0.000   -0.296   -0.164
##     SESscore         -0.090    0.020   -4.476    0.000   -0.129   -0.051
##     Zgcse             0.096    0.020    4.866    0.000    0.057    0.134
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.431    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.428    0.000    0.422    0.473
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zmon              0.075    0.021    3.519    0.000    0.033    0.116
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.034    0.012   -2.925    0.003   -0.057   -0.011
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zmon              0.978    0.023   42.774    0.000    0.934    1.023
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.321    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zmon              0.023
standardizedsolution(model2.monfit)
##         lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1      Zmon  ~     sex1  -0.115 0.017  -6.911  0.000   -0.148   -0.082
## 2      Zmon  ~ SESscore  -0.084 0.019  -4.491  0.000   -0.121   -0.047
## 3      Zmon  ~    Zgcse   0.095 0.020   4.890  0.000    0.057    0.134
## 4      Zmon ~~     Zmon   0.977 0.005 188.026  0.000    0.966    0.987
## 5      sex1 ~~     sex1   1.000 0.000      NA     NA    1.000    1.000
## 6      sex1 ~~ SESscore   0.030 0.012   2.434  0.015    0.006    0.055
## 7      sex1 ~~    Zgcse  -0.053 0.012  -4.250  0.000   -0.077   -0.028
## 8  SESscore ~~ SESscore   1.000 0.000      NA     NA    1.000    1.000
## 9  SESscore ~~    Zgcse   0.478 0.010  49.317  0.000    0.459    0.497
## 10    Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 11     Zmon ~1            0.075 0.021   3.528  0.000    0.033    0.116
## 12     sex1 ~1            0.950 0.015  63.509  0.000    0.920    0.979
## 13 SESscore ~1           -0.037 0.013  -2.924  0.003   -0.061   -0.012
## 14    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
model3.mon <- 'Zmon ~ sex1 + SESscore + Zgcse + Zhqual'
model3.monfit <- sem(model3.mon, data = df, missing = "fiml", fixed.x = FALSE)
summary(model3.monfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 19 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        20
## 
##   Number of observations                          6488
##   Number of missing patterns                         7
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                80.248
##   Degrees of freedom                                 4
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -31406.247
##   Loglikelihood unrestricted model (H1)     -31406.247
##                                                       
##   Akaike (AIC)                               62852.494
##   Bayesian (BIC)                             62988.048
##   Sample-size adjusted Bayesian (SABIC)      62924.493
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zmon ~                                                                
##     sex1             -0.230    0.034   -6.828    0.000   -0.295   -0.164
##     SESscore         -0.093    0.020   -4.613    0.000   -0.133   -0.054
##     Zgcse             0.084    0.022    3.807    0.000    0.041    0.127
##     Zhqual            0.024    0.020    1.208    0.227   -0.015    0.062
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.426    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     Zhqual           -0.021    0.008   -2.603    0.009   -0.036   -0.005
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.423    0.000    0.422    0.472
##     Zhqual            0.342    0.015   22.278    0.000    0.312    0.372
##   Zgcse ~~                                                              
##     Zhqual            0.565    0.018   31.554    0.000    0.530    0.600
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zmon              0.077    0.021    3.618    0.000    0.035    0.119
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.034    0.012   -2.924    0.003   -0.057   -0.011
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
##     Zhqual           -0.121    0.016   -7.517    0.000   -0.153   -0.089
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zmon              0.978    0.023   42.774    0.000    0.933    1.023
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.874    0.016   56.325    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     Zhqual            1.040    0.024   42.571    0.000    0.992    1.087
## 
## R-Square:
##                    Estimate
##     Zmon              0.024
standardizedsolution(model3.monfit)
##         lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1      Zmon  ~     sex1  -0.115 0.017  -6.888  0.000   -0.147   -0.082
## 2      Zmon  ~ SESscore  -0.087 0.019  -4.630  0.000   -0.124   -0.050
## 3      Zmon  ~    Zgcse   0.084 0.022   3.819  0.000    0.041    0.127
## 4      Zmon  ~   Zhqual   0.024 0.020   1.209  0.227   -0.015    0.063
## 5      Zmon ~~     Zmon   0.976 0.005 186.320  0.000    0.966    0.986
## 6      sex1 ~~     sex1   1.000 0.000      NA     NA    1.000    1.000
## 7      sex1 ~~ SESscore   0.030 0.012   2.429  0.015    0.006    0.055
## 8      sex1 ~~    Zgcse  -0.053 0.012  -4.250  0.000   -0.077   -0.028
## 9      sex1 ~~   Zhqual  -0.041 0.016  -2.612  0.009   -0.071   -0.010
## 10 SESscore ~~ SESscore   1.000 0.000      NA     NA    1.000    1.000
## 11 SESscore ~~    Zgcse   0.478 0.010  49.299  0.000    0.459    0.497
## 12 SESscore ~~   Zhqual   0.359 0.014  26.383  0.000    0.332    0.385
## 13    Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 14    Zgcse ~~   Zhqual   0.554 0.012  47.880  0.000    0.532    0.577
## 15   Zhqual ~~   Zhqual   1.000 0.000      NA     NA    1.000    1.000
## 16     Zmon ~1            0.077 0.021   3.628  0.000    0.035    0.119
## 17     sex1 ~1            0.950 0.015  63.509  0.000    0.920    0.979
## 18 SESscore ~1           -0.037 0.013  -2.924  0.003   -0.061   -0.012
## 19    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
## 20   Zhqual ~1           -0.119 0.016  -7.582  0.000   -0.149   -0.088
#get change in R2 for model1 vs. model2 vs. model3
(PE.model3.mon <- parameterEstimates(model3.monfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1      Zmon  ~     sex1 -0.230 0.034 -6.828  0.000   -0.295   -0.164
## 2      Zmon  ~ SESscore -0.093 0.020 -4.613  0.000   -0.133   -0.054
## 3      Zmon  ~    Zgcse  0.084 0.022  3.807  0.000    0.041    0.127
## 4      Zmon  ~   Zhqual  0.024 0.020  1.208  0.227   -0.015    0.062
## 5      Zmon ~~     Zmon  0.978 0.023 42.774  0.000    0.933    1.023
## 6      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 7      sex1 ~~ SESscore  0.014 0.006  2.426  0.015    0.003    0.026
## 8      sex1 ~~    Zgcse -0.026 0.006 -4.232  0.000   -0.038   -0.014
## 9      sex1 ~~   Zhqual -0.021 0.008 -2.603  0.009   -0.036   -0.005
## 10 SESscore ~~ SESscore  0.874 0.016 56.325  0.000    0.844    0.905
## 11 SESscore ~~    Zgcse  0.447 0.013 34.423  0.000    0.422    0.472
## 12 SESscore ~~   Zhqual  0.342 0.015 22.278  0.000    0.312    0.372
## 13    Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 14    Zgcse ~~   Zhqual  0.565 0.018 31.554  0.000    0.530    0.600
## 15   Zhqual ~~   Zhqual  1.040 0.024 42.571  0.000    0.992    1.087
## 16     Zmon ~1           0.077 0.021  3.618  0.000    0.035    0.119
## 17     sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 18 SESscore ~1          -0.034 0.012 -2.924  0.003   -0.057   -0.011
## 19    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 20   Zhqual ~1          -0.121 0.016 -7.517  0.000   -0.153   -0.089
## 21     Zmon r2     Zmon  0.024    NA     NA     NA       NA       NA
PE.model3.mon$est[PE.model3.mon$op == "r2"]
## [1] 0.02390799
(PE.model2.mon <- parameterEstimates(model2.monfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1      Zmon  ~     sex1 -0.230 0.034 -6.850  0.000   -0.296   -0.164
## 2      Zmon  ~ SESscore -0.090 0.020 -4.476  0.000   -0.129   -0.051
## 3      Zmon  ~    Zgcse  0.096 0.020  4.866  0.000    0.057    0.134
## 4      Zmon ~~     Zmon  0.978 0.023 42.774  0.000    0.934    1.023
## 5      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 6      sex1 ~~ SESscore  0.014 0.006  2.431  0.015    0.003    0.026
## 7      sex1 ~~    Zgcse -0.026 0.006 -4.232  0.000   -0.038   -0.014
## 8  SESscore ~~ SESscore  0.875 0.016 56.321  0.000    0.844    0.905
## 9  SESscore ~~    Zgcse  0.447 0.013 34.428  0.000    0.422    0.473
## 10    Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 11     Zmon ~1           0.075 0.021  3.519  0.000    0.033    0.116
## 12     sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 13 SESscore ~1          -0.034 0.012 -2.925  0.003   -0.057   -0.011
## 14    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 15     Zmon r2     Zmon  0.023    NA     NA     NA       NA       NA
PE.model2.mon$est[PE.model2.mon$op == "r2"]
## [1] 0.0234538
(PE.model1.mon <- parameterEstimates(model1.monfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1      Zmon  ~     sex1 -0.232 0.034 -6.887  0.000   -0.298   -0.166
## 2      Zmon  ~ SESscore -0.047 0.018 -2.652  0.008   -0.082   -0.012
## 3      Zmon ~~     Zmon  0.985 0.023 42.777  0.000    0.939    1.030
## 4      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 5      sex1 ~~ SESscore  0.013 0.006  2.288  0.022    0.002    0.025
## 6  SESscore ~~ SESscore  0.873 0.015 56.387  0.000    0.842    0.903
## 7      Zmon ~1           0.093 0.021  4.422  0.000    0.052    0.134
## 8      sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 9  SESscore ~1          -0.029 0.012 -2.514  0.012   -0.052   -0.006
## 10     Zmon r2     Zmon  0.016    NA     NA     NA       NA       NA
PE.model1.mon$est[PE.model1.mon$op == "r2"]
## [1] 0.01569144
r2diff2.mon <- (PE.model2.mon$est[PE.model2.mon$op == "r2"] - PE.model1.mon$est[PE.model1.mon$op == "r2"])
print(r2diff2.mon)    #difference model1 vs 2, incremental explained variance by GCSE
## [1] 0.007762354
r2diff3.mon <- (PE.model3.mon$est[PE.model3.mon$op == "r2"] - PE.model2.mon$est[PE.model2.mon$op == "r2"])
print(r2diff3.mon)    #difference model2 vs 3, incremental explained variance by highest qualification
## [1] 0.0004541953
model1.fina <- 'Zfina ~ sex1 + SESscore'
model1.finafit <- sem(model1.fina, data = df, missing = "fiml", fixed.x = FALSE)
summary(model1.finafit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 14 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                14.266
##   Degrees of freedom                                 2
##   P-value                                        0.001
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -18475.831
##   Loglikelihood unrestricted model (H1)     -18475.831
##                                                       
##   Akaike (AIC)                               36969.661
##   Bayesian (BIC)                             37030.661
##   Sample-size adjusted Bayesian (SABIC)      37002.061
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zfina ~                                                               
##     sex1              0.065    0.034    1.909    0.056   -0.002    0.131
##     SESscore         -0.060    0.018   -3.357    0.001   -0.095   -0.025
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.013    0.006    2.285    0.022    0.002    0.025
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zfina            -0.021    0.021   -1.015    0.310   -0.063    0.020
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.029    0.012   -2.506    0.012   -0.052   -0.006
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zfina             0.996    0.023   42.788    0.000    0.950    1.041
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.873    0.015   56.387    0.000    0.842    0.903
## 
## R-Square:
##                    Estimate
##     Zfina             0.004
standardizedsolution(model1.finafit)
##        lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1    Zfina  ~     sex1   0.032 0.017   1.910  0.056   -0.001    0.066
## 2    Zfina  ~ SESscore  -0.056 0.017  -3.364  0.001   -0.089   -0.023
## 3    Zfina ~~    Zfina   0.996 0.002 461.108  0.000    0.992    1.000
## 4     sex1 ~~     sex1   1.000 0.000      NA     NA    1.000    1.000
## 5     sex1 ~~ SESscore   0.029 0.013   2.288  0.022    0.004    0.053
## 6 SESscore ~~ SESscore   1.000 0.000      NA     NA    1.000    1.000
## 7    Zfina ~1           -0.021 0.021  -1.015  0.310   -0.063    0.020
## 8     sex1 ~1            0.950 0.015  63.509  0.000    0.920    0.979
## 9 SESscore ~1           -0.031 0.013  -2.505  0.012   -0.056   -0.007
model2.fina <- 'Zfina ~ sex1 + SESscore + Zgcse'
model2.finafit <- sem(model2.fina, data = df, missing = "fiml", fixed.x = FALSE)
summary(model2.finafit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 17 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        14
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                18.258
##   Degrees of freedom                                 3
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -26841.664
##   Loglikelihood unrestricted model (H1)     -26841.664
##                                                       
##   Akaike (AIC)                               53711.327
##   Bayesian (BIC)                             53806.215
##   Sample-size adjusted Bayesian (SABIC)      53761.727
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zfina ~                                                               
##     sex1              0.066    0.034    1.933    0.053   -0.001    0.132
##     SESscore         -0.079    0.020   -3.887    0.000   -0.118   -0.039
##     Zgcse             0.044    0.020    2.202    0.028    0.005    0.082
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.430    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.431    0.000    0.422    0.473
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zfina            -0.030    0.021   -1.389    0.165   -0.072    0.012
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.034    0.012   -2.916    0.004   -0.057   -0.011
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zfina             0.995    0.023   42.787    0.000    0.949    1.040
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.318    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zfina             0.005
standardizedsolution(model2.finafit)
##         lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1     Zfina  ~     sex1   0.033 0.017   1.934  0.053    0.000    0.066
## 2     Zfina  ~ SESscore  -0.074 0.019  -3.897  0.000   -0.111   -0.037
## 3     Zfina  ~    Zgcse   0.044 0.020   2.204  0.028    0.005    0.082
## 4     Zfina ~~    Zfina   0.995 0.002 424.388  0.000    0.990    1.000
## 5      sex1 ~~     sex1   1.000 0.000      NA     NA    1.000    1.000
## 6      sex1 ~~ SESscore   0.030 0.012   2.433  0.015    0.006    0.055
## 7      sex1 ~~    Zgcse  -0.053 0.012  -4.250  0.000   -0.077   -0.028
## 8  SESscore ~~ SESscore   1.000 0.000      NA     NA    1.000    1.000
## 9  SESscore ~~    Zgcse   0.478 0.010  49.329  0.000    0.459    0.497
## 10    Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 11    Zfina ~1           -0.030 0.021  -1.390  0.165   -0.072    0.012
## 12     sex1 ~1            0.950 0.015  63.510  0.000    0.920    0.979
## 13 SESscore ~1           -0.036 0.013  -2.916  0.004   -0.061   -0.012
## 14    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
model3.fina <- 'Zfina ~ sex1 + SESscore + Zgcse + Zhqual'
model3.finafit <- sem(model3.fina, data = df, missing = "fiml", fixed.x = FALSE)
summary(model3.finafit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 21 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        20
## 
##   Number of observations                          6488
##   Number of missing patterns                         7
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                34.517
##   Degrees of freedom                                 4
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -31431.950
##   Loglikelihood unrestricted model (H1)     -31431.950
##                                                       
##   Akaike (AIC)                               62903.900
##   Bayesian (BIC)                             63039.454
##   Sample-size adjusted Bayesian (SABIC)      62975.899
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zfina ~                                                               
##     sex1              0.063    0.034    1.863    0.062   -0.003    0.129
##     SESscore         -0.069    0.020   -3.376    0.001   -0.109   -0.029
##     Zgcse             0.084    0.022    3.788    0.000    0.040    0.127
##     Zhqual           -0.079    0.020   -4.007    0.000   -0.118   -0.040
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.425    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     Zhqual           -0.021    0.008   -2.595    0.009   -0.036   -0.005
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.428    0.000    0.422    0.473
##     Zhqual            0.342    0.015   22.274    0.000    0.312    0.372
##   Zgcse ~~                                                              
##     Zhqual            0.565    0.018   31.549    0.000    0.530    0.600
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zfina            -0.038    0.021   -1.768    0.077   -0.080    0.004
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.034    0.012   -2.918    0.004   -0.057   -0.011
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
##     Zhqual           -0.121    0.016   -7.527    0.000   -0.153   -0.090
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zfina             0.990    0.023   42.784    0.000    0.945    1.036
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.321    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     Zhqual            1.039    0.024   42.579    0.000    0.991    1.087
## 
## R-Square:
##                    Estimate
##     Zfina             0.010
standardizedsolution(model3.finafit)
##         lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1     Zfina  ~     sex1   0.031 0.017   1.864  0.062   -0.002    0.065
## 2     Zfina  ~ SESscore  -0.064 0.019  -3.382  0.001   -0.102   -0.027
## 3     Zfina  ~    Zgcse   0.084 0.022   3.797  0.000    0.041    0.127
## 4     Zfina  ~   Zhqual  -0.081 0.020  -4.016  0.000   -0.120   -0.041
## 5     Zfina ~~    Zfina   0.990 0.003 307.110  0.000    0.984    0.997
## 6      sex1 ~~     sex1   1.000 0.000      NA     NA    1.000    1.000
## 7      sex1 ~~ SESscore   0.030 0.012   2.428  0.015    0.006    0.055
## 8      sex1 ~~    Zgcse  -0.053 0.012  -4.250  0.000   -0.077   -0.028
## 9      sex1 ~~   Zhqual  -0.041 0.016  -2.603  0.009   -0.071   -0.010
## 10 SESscore ~~ SESscore   1.000 0.000      NA     NA    1.000    1.000
## 11 SESscore ~~    Zgcse   0.478 0.010  49.315  0.000    0.459    0.497
## 12 SESscore ~~   Zhqual   0.358 0.014  26.375  0.000    0.332    0.385
## 13    Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 14    Zgcse ~~   Zhqual   0.554 0.012  47.858  0.000    0.531    0.577
## 15   Zhqual ~~   Zhqual   1.000 0.000      NA     NA    1.000    1.000
## 16    Zfina ~1           -0.038 0.021  -1.769  0.077   -0.080    0.004
## 17     sex1 ~1            0.950 0.015  63.509  0.000    0.920    0.979
## 18 SESscore ~1           -0.037 0.013  -2.917  0.004   -0.061   -0.012
## 19    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
## 20   Zhqual ~1           -0.119 0.016  -7.593  0.000   -0.150   -0.088
#get change in R2 for model1 vs. model2 vs. model3
(PE.model3.fina <- parameterEstimates(model3.finafit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1     Zfina  ~     sex1  0.063 0.034  1.863  0.062   -0.003    0.129
## 2     Zfina  ~ SESscore -0.069 0.020 -3.376  0.001   -0.109   -0.029
## 3     Zfina  ~    Zgcse  0.084 0.022  3.788  0.000    0.040    0.127
## 4     Zfina  ~   Zhqual -0.079 0.020 -4.007  0.000   -0.118   -0.040
## 5     Zfina ~~    Zfina  0.990 0.023 42.784  0.000    0.945    1.036
## 6      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 7      sex1 ~~ SESscore  0.014 0.006  2.425  0.015    0.003    0.026
## 8      sex1 ~~    Zgcse -0.026 0.006 -4.232  0.000   -0.038   -0.014
## 9      sex1 ~~   Zhqual -0.021 0.008 -2.595  0.009   -0.036   -0.005
## 10 SESscore ~~ SESscore  0.875 0.016 56.321  0.000    0.844    0.905
## 11 SESscore ~~    Zgcse  0.447 0.013 34.428  0.000    0.422    0.473
## 12 SESscore ~~   Zhqual  0.342 0.015 22.274  0.000    0.312    0.372
## 13    Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 14    Zgcse ~~   Zhqual  0.565 0.018 31.549  0.000    0.530    0.600
## 15   Zhqual ~~   Zhqual  1.039 0.024 42.579  0.000    0.991    1.087
## 16    Zfina ~1          -0.038 0.021 -1.768  0.077   -0.080    0.004
## 17     sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 18 SESscore ~1          -0.034 0.012 -2.918  0.004   -0.057   -0.011
## 19    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 20   Zhqual ~1          -0.121 0.016 -7.527  0.000   -0.153   -0.090
## 21    Zfina r2    Zfina  0.010    NA     NA     NA       NA       NA
PE.model3.fina$est[PE.model3.fina$op == "r2"]
## [1] 0.009545627
(PE.model2.fina <- parameterEstimates(model2.finafit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1     Zfina  ~     sex1  0.066 0.034  1.933  0.053   -0.001    0.132
## 2     Zfina  ~ SESscore -0.079 0.020 -3.887  0.000   -0.118   -0.039
## 3     Zfina  ~    Zgcse  0.044 0.020  2.202  0.028    0.005    0.082
## 4     Zfina ~~    Zfina  0.995 0.023 42.787  0.000    0.949    1.040
## 5      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 6      sex1 ~~ SESscore  0.014 0.006  2.430  0.015    0.003    0.026
## 7      sex1 ~~    Zgcse -0.026 0.006 -4.232  0.000   -0.038   -0.014
## 8  SESscore ~~ SESscore  0.875 0.016 56.318  0.000    0.844    0.905
## 9  SESscore ~~    Zgcse  0.447 0.013 34.431  0.000    0.422    0.473
## 10    Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 11    Zfina ~1          -0.030 0.021 -1.389  0.165   -0.072    0.012
## 12     sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 13 SESscore ~1          -0.034 0.012 -2.916  0.004   -0.057   -0.011
## 14    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 15    Zfina r2    Zfina  0.005    NA     NA     NA       NA       NA
PE.model2.fina$est[PE.model2.fina$op == "r2"]
## [1] 0.005030792
(PE.model1.fina <- parameterEstimates(model1.finafit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1     Zfina  ~     sex1  0.065 0.034  1.909  0.056   -0.002    0.131
## 2     Zfina  ~ SESscore -0.060 0.018 -3.357  0.001   -0.095   -0.025
## 3     Zfina ~~    Zfina  0.996 0.023 42.788  0.000    0.950    1.041
## 4      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 5      sex1 ~~ SESscore  0.013 0.006  2.285  0.022    0.002    0.025
## 6  SESscore ~~ SESscore  0.873 0.015 56.387  0.000    0.842    0.903
## 7     Zfina ~1          -0.021 0.021 -1.015  0.310   -0.063    0.020
## 8      sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 9  SESscore ~1          -0.029 0.012 -2.506  0.012   -0.052   -0.006
## 10    Zfina r2    Zfina  0.004    NA     NA     NA       NA       NA
PE.model1.fina$est[PE.model1.fina$op == "r2"]
## [1] 0.004092698
r2diff2.fina <- (PE.model2.fina$est[PE.model2.fina$op == "r2"] - PE.model1.fina$est[PE.model1.fina$op == "r2"])
print(r2diff2.fina)    #difference model1 vs 2, incremental explained variance by GCSE
## [1] 0.0009380946
r2diff3.fina <- (PE.model3.fina$est[PE.model3.fina$op == "r2"] - PE.model2.fina$est[PE.model2.fina$op == "r2"])
print(r2diff3.fina)    #difference model2 vs 3, incremental explained variance by highest qualification
## [1] 0.004514834
model1.wellb <- 'Zwellb ~ sex1 + SESscore'
model1.wellbfit <- sem(model1.wellb, data = df, missing = "fiml", fixed.x = FALSE)
summary(model1.wellbfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 15 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                77.198
##   Degrees of freedom                                 2
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -18574.907
##   Loglikelihood unrestricted model (H1)     -18574.907
##                                                       
##   Akaike (AIC)                               37167.813
##   Bayesian (BIC)                             37228.813
##   Sample-size adjusted Bayesian (SABIC)      37200.213
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zwellb ~                                                              
##     sex1              0.261    0.033    7.851    0.000    0.196    0.326
##     SESscore          0.064    0.017    3.653    0.000    0.030    0.098
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.013    0.006    2.299    0.022    0.002    0.025
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zwellb           -0.104    0.021   -5.042    0.000   -0.144   -0.063
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.030    0.012   -2.524    0.012   -0.053   -0.007
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zwellb            0.979    0.023   43.322    0.000    0.935    1.024
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.873    0.015   56.386    0.000    0.842    0.903
## 
## R-Square:
##                    Estimate
##     Zwellb            0.021
standardizedsolution(model1.wellbfit)
##        lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1   Zwellb  ~     sex1   0.130 0.016   7.934  0.000    0.098    0.163
## 2   Zwellb  ~ SESscore   0.060 0.016   3.660  0.000    0.028    0.091
## 3   Zwellb ~~   Zwellb   0.979 0.005 208.510  0.000    0.970    0.988
## 4     sex1 ~~     sex1   1.000 0.000      NA     NA    1.000    1.000
## 5     sex1 ~~ SESscore   0.029 0.013   2.302  0.021    0.004    0.053
## 6 SESscore ~~ SESscore   1.000 0.000      NA     NA    1.000    1.000
## 7   Zwellb ~1           -0.104 0.020  -5.068  0.000   -0.144   -0.064
## 8     sex1 ~1            0.950 0.015  63.510  0.000    0.920    0.979
## 9 SESscore ~1           -0.032 0.013  -2.524  0.012   -0.056   -0.007
model2.wellb <- 'Zwellb ~ sex1 + SESscore + Zgcse'
model2.wellbfit <- sem(model2.wellb, data = df, missing = "fiml", fixed.x = FALSE)
summary(model2.wellbfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 19 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        14
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                               109.853
##   Degrees of freedom                                 3
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -26926.409
##   Loglikelihood unrestricted model (H1)     -26926.409
##                                                       
##   Akaike (AIC)                               53880.818
##   Bayesian (BIC)                             53975.706
##   Sample-size adjusted Bayesian (SABIC)      53931.217
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zwellb ~                                                              
##     sex1              0.264    0.033    7.962    0.000    0.199    0.329
##     SESscore          0.013    0.020    0.669    0.503   -0.025    0.052
##     Zgcse             0.109    0.019    5.644    0.000    0.071    0.147
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.436    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.437    0.000    0.422    0.473
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zwellb           -0.124    0.021   -5.946    0.000   -0.164   -0.083
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.034    0.012   -2.929    0.003   -0.057   -0.011
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zwellb            0.971    0.022   43.324    0.000    0.927    1.015
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.311    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zwellb            0.029
standardizedsolution(model2.wellbfit)
##         lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1    Zwellb  ~     sex1   0.132 0.016   8.041  0.000    0.100    0.164
## 2    Zwellb  ~ SESscore   0.012 0.018   0.669  0.503   -0.024    0.048
## 3    Zwellb  ~    Zgcse   0.109 0.019   5.674  0.000    0.071    0.147
## 4    Zwellb ~~   Zwellb   0.971 0.005 178.297  0.000    0.960    0.981
## 5      sex1 ~~     sex1   1.000 0.000      NA     NA    1.000    1.000
## 6      sex1 ~~ SESscore   0.030 0.012   2.439  0.015    0.006    0.055
## 7      sex1 ~~    Zgcse  -0.053 0.012  -4.249  0.000   -0.077   -0.028
## 8  SESscore ~~ SESscore   1.000 0.000      NA     NA    1.000    1.000
## 9  SESscore ~~    Zgcse   0.478 0.010  49.349  0.000    0.459    0.497
## 10    Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 11   Zwellb ~1           -0.124 0.021  -5.987  0.000   -0.164   -0.083
## 12     sex1 ~1            0.950 0.015  63.509  0.000    0.920    0.979
## 13 SESscore ~1           -0.037 0.013  -2.928  0.003   -0.061   -0.012
## 14    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
model3.wellb <- 'Zwellb ~ sex1 + SESscore + Zgcse + Zhqual'
model3.wellbfit <- sem(model3.wellb, data = df, missing = "fiml", fixed.x = FALSE)
summary(model3.wellbfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 18 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        20
## 
##   Number of observations                          6488
##   Number of missing patterns                         8
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                               115.841
##   Degrees of freedom                                 4
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -31521.830
##   Loglikelihood unrestricted model (H1)     -31521.830
##                                                       
##   Akaike (AIC)                               63083.661
##   Bayesian (BIC)                             63219.215
##   Sample-size adjusted Bayesian (SABIC)      63155.660
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zwellb ~                                                              
##     sex1              0.266    0.033    8.034    0.000    0.201    0.331
##     SESscore          0.006    0.020    0.316    0.752   -0.033    0.045
##     Zgcse             0.085    0.022    3.953    0.000    0.043    0.128
##     Zhqual            0.048    0.019    2.455    0.014    0.010    0.086
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.430    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     Zhqual           -0.021    0.008   -2.600    0.009   -0.036   -0.005
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.433    0.000    0.422    0.473
##     Zhqual            0.342    0.015   22.281    0.000    0.312    0.372
##   Zgcse ~~                                                              
##     Zhqual            0.565    0.018   31.557    0.000    0.530    0.600
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zwellb           -0.119    0.021   -5.712    0.000   -0.160   -0.078
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.034    0.012   -2.929    0.003   -0.057   -0.011
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
##     Zhqual           -0.121    0.016   -7.523    0.000   -0.153   -0.090
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zwellb            0.969    0.022   43.322    0.000    0.925    1.013
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.318    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     Zhqual            1.040    0.024   42.569    0.000    0.992    1.088
## 
## R-Square:
##                    Estimate
##     Zwellb            0.031
standardizedsolution(model3.wellbfit)
##         lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1    Zwellb  ~     sex1   0.133 0.016   8.115  0.000    0.101    0.165
## 2    Zwellb  ~ SESscore   0.006 0.019   0.316  0.752   -0.031    0.042
## 3    Zwellb  ~    Zgcse   0.085 0.022   3.963  0.000    0.043    0.128
## 4    Zwellb  ~   Zhqual   0.049 0.020   2.456  0.014    0.010    0.087
## 5    Zwellb ~~   Zwellb   0.969 0.006 173.064  0.000    0.958    0.980
## 6      sex1 ~~     sex1   1.000 0.000      NA     NA    1.000    1.000
## 7      sex1 ~~ SESscore   0.030 0.012   2.433  0.015    0.006    0.055
## 8      sex1 ~~    Zgcse  -0.053 0.012  -4.250  0.000   -0.077   -0.028
## 9      sex1 ~~   Zhqual  -0.041 0.016  -2.608  0.009   -0.071   -0.010
## 10 SESscore ~~ SESscore   1.000 0.000      NA     NA    1.000    1.000
## 11 SESscore ~~    Zgcse   0.478 0.010  49.332  0.000    0.459    0.497
## 12 SESscore ~~   Zhqual   0.359 0.014  26.387  0.000    0.332    0.385
## 13    Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 14    Zgcse ~~   Zhqual   0.554 0.012  47.893  0.000    0.532    0.577
## 15   Zhqual ~~   Zhqual   1.000 0.000      NA     NA    1.000    1.000
## 16   Zwellb ~1           -0.119 0.021  -5.749  0.000   -0.160   -0.078
## 17     sex1 ~1            0.950 0.015  63.509  0.000    0.920    0.979
## 18 SESscore ~1           -0.037 0.013  -2.928  0.003   -0.061   -0.012
## 19    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
## 20   Zhqual ~1           -0.119 0.016  -7.588  0.000   -0.149   -0.088
#get change in R2 for model1 vs. model2 vs. model3
(PE.model3.wellb <- parameterEstimates(model3.wellbfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1    Zwellb  ~     sex1  0.266 0.033  8.034  0.000    0.201    0.331
## 2    Zwellb  ~ SESscore  0.006 0.020  0.316  0.752   -0.033    0.045
## 3    Zwellb  ~    Zgcse  0.085 0.022  3.953  0.000    0.043    0.128
## 4    Zwellb  ~   Zhqual  0.048 0.019  2.455  0.014    0.010    0.086
## 5    Zwellb ~~   Zwellb  0.969 0.022 43.322  0.000    0.925    1.013
## 6      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 7      sex1 ~~ SESscore  0.014 0.006  2.430  0.015    0.003    0.026
## 8      sex1 ~~    Zgcse -0.026 0.006 -4.232  0.000   -0.038   -0.014
## 9      sex1 ~~   Zhqual -0.021 0.008 -2.600  0.009   -0.036   -0.005
## 10 SESscore ~~ SESscore  0.875 0.016 56.318  0.000    0.844    0.905
## 11 SESscore ~~    Zgcse  0.447 0.013 34.433  0.000    0.422    0.473
## 12 SESscore ~~   Zhqual  0.342 0.015 22.281  0.000    0.312    0.372
## 13    Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 14    Zgcse ~~   Zhqual  0.565 0.018 31.557  0.000    0.530    0.600
## 15   Zhqual ~~   Zhqual  1.040 0.024 42.569  0.000    0.992    1.088
## 16   Zwellb ~1          -0.119 0.021 -5.712  0.000   -0.160   -0.078
## 17     sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 18 SESscore ~1          -0.034 0.012 -2.929  0.003   -0.057   -0.011
## 19    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 20   Zhqual ~1          -0.121 0.016 -7.523  0.000   -0.153   -0.090
## 21   Zwellb r2   Zwellb  0.031    NA     NA     NA       NA       NA
PE.model3.wellb$est[PE.model3.wellb$op == "r2"]
## [1] 0.03093895
(PE.model2.wellb <- parameterEstimates(model2.wellbfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1    Zwellb  ~     sex1  0.264 0.033  7.962  0.000    0.199    0.329
## 2    Zwellb  ~ SESscore  0.013 0.020  0.669  0.503   -0.025    0.052
## 3    Zwellb  ~    Zgcse  0.109 0.019  5.644  0.000    0.071    0.147
## 4    Zwellb ~~   Zwellb  0.971 0.022 43.324  0.000    0.927    1.015
## 5      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 6      sex1 ~~ SESscore  0.014 0.006  2.436  0.015    0.003    0.026
## 7      sex1 ~~    Zgcse -0.026 0.006 -4.232  0.000   -0.038   -0.014
## 8  SESscore ~~ SESscore  0.875 0.016 56.311  0.000    0.844    0.905
## 9  SESscore ~~    Zgcse  0.447 0.013 34.437  0.000    0.422    0.473
## 10    Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 11   Zwellb ~1          -0.124 0.021 -5.946  0.000   -0.164   -0.083
## 12     sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 13 SESscore ~1          -0.034 0.012 -2.929  0.003   -0.057   -0.011
## 14    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 15   Zwellb r2   Zwellb  0.029    NA     NA     NA       NA       NA
PE.model2.wellb$est[PE.model2.wellb$op == "r2"]
## [1] 0.02926232
(PE.model1.wellb <- parameterEstimates(model1.wellbfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1    Zwellb  ~     sex1  0.261 0.033  7.851  0.000    0.196    0.326
## 2    Zwellb  ~ SESscore  0.064 0.017  3.653  0.000    0.030    0.098
## 3    Zwellb ~~   Zwellb  0.979 0.023 43.322  0.000    0.935    1.024
## 4      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 5      sex1 ~~ SESscore  0.013 0.006  2.299  0.022    0.002    0.025
## 6  SESscore ~~ SESscore  0.873 0.015 56.386  0.000    0.842    0.903
## 7    Zwellb ~1          -0.104 0.021 -5.042  0.000   -0.144   -0.063
## 8      sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 9  SESscore ~1          -0.030 0.012 -2.524  0.012   -0.053   -0.007
## 10   Zwellb r2   Zwellb  0.021    NA     NA     NA       NA       NA
PE.model1.wellb$est[PE.model1.wellb$op == "r2"]
## [1] 0.0209988
r2diff2.wellb <- (PE.model2.wellb$est[PE.model2.wellb$op == "r2"] - PE.model1.wellb$est[PE.model1.wellb$op == "r2"])
print(r2diff2.wellb)    #difference model1 vs 2, incremental explained variance by GCSE
## [1] 0.008263516
r2diff3.wellb <- (PE.model3.wellb$est[PE.model3.wellb$op == "r2"] - PE.model2.wellb$est[PE.model2.wellb$op == "r2"])
print(r2diff3.wellb)    #difference model2 vs 3, incremental explained variance by highest qualification
## [1] 0.001676632
model1.anx <- 'Zanx ~ sex1 + SESscore'
model1.anxfit <- sem(model1.anx, data = df, missing = "fiml", fixed.x = FALSE)
summary(model1.anxfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 16 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                90.978
##   Degrees of freedom                                 2
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -18106.862
##   Loglikelihood unrestricted model (H1)     -18106.862
##                                                       
##   Akaike (AIC)                               36231.724
##   Bayesian (BIC)                             36292.723
##   Sample-size adjusted Bayesian (SABIC)      36264.124
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zanx ~                                                                
##     sex1             -0.333    0.035   -9.525    0.000   -0.402   -0.265
##     SESscore         -0.012    0.018   -0.637    0.524   -0.047    0.024
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.013    0.006    2.290    0.022    0.002    0.025
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zanx              0.124    0.021    5.829    0.000    0.082    0.165
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.029    0.012   -2.518    0.012   -0.052   -0.007
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zanx              0.974    0.024   41.406    0.000    0.927    1.020
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.873    0.015   56.387    0.000    0.842    0.903
## 
## R-Square:
##                    Estimate
##     Zanx              0.028
standardizedsolution(model1.anxfit)
##        lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1     Zanx  ~     sex1  -0.166 0.017  -9.697  0.000   -0.200   -0.133
## 2     Zanx  ~ SESscore  -0.011 0.017  -0.637  0.524   -0.044    0.023
## 3     Zanx ~~     Zanx   0.972 0.006 170.592  0.000    0.961    0.983
## 4     sex1 ~~     sex1   1.000 0.000      NA     NA    1.000    1.000
## 5     sex1 ~~ SESscore   0.029 0.013   2.293  0.022    0.004    0.053
## 6 SESscore ~~ SESscore   1.000 0.000      NA     NA    1.000    1.000
## 7     Zanx ~1            0.124 0.021   5.875  0.000    0.082    0.165
## 8     sex1 ~1            0.950 0.015  63.509  0.000    0.920    0.979
## 9 SESscore ~1           -0.032 0.013  -2.517  0.012   -0.056   -0.007
model2.anx <- 'Zanx ~ sex1 + SESscore + Zgcse'
model2.anxfit <- sem(model2.anx, data = df, missing = "fiml", fixed.x = FALSE)
summary(model2.anxfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 19 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        14
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                90.985
##   Degrees of freedom                                 3
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -26474.688
##   Loglikelihood unrestricted model (H1)     -26474.688
##                                                       
##   Akaike (AIC)                               52977.375
##   Bayesian (BIC)                             53072.263
##   Sample-size adjusted Bayesian (SABIC)      53027.775
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zanx ~                                                                
##     sex1             -0.333    0.035   -9.531    0.000   -0.402   -0.265
##     SESscore         -0.005    0.021   -0.243    0.808   -0.046    0.036
##     Zgcse            -0.008    0.020   -0.405    0.686   -0.048    0.031
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.434    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.436    0.000    0.422    0.473
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zanx              0.125    0.022    5.814    0.000    0.083    0.167
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.034    0.012   -2.928    0.003   -0.057   -0.011
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zanx              0.974    0.024   41.406    0.000    0.927    1.020
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.312    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zanx              0.028
standardizedsolution(model2.anxfit)
##         lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1      Zanx  ~     sex1  -0.166 0.017  -9.703  0.000   -0.200   -0.133
## 2      Zanx  ~ SESscore  -0.005 0.019  -0.243  0.808   -0.043    0.033
## 3      Zanx  ~    Zgcse  -0.008 0.020  -0.405  0.686   -0.048    0.031
## 4      Zanx ~~     Zanx   0.972 0.006 171.014  0.000    0.961    0.983
## 5      sex1 ~~     sex1   1.000 0.000      NA     NA    1.000    1.000
## 6      sex1 ~~ SESscore   0.030 0.012   2.438  0.015    0.006    0.055
## 7      sex1 ~~    Zgcse  -0.053 0.012  -4.250  0.000   -0.077   -0.028
## 8  SESscore ~~ SESscore   1.000 0.000      NA     NA    1.000    1.000
## 9  SESscore ~~    Zgcse   0.478 0.010  49.346  0.000    0.459    0.497
## 10    Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 11     Zanx ~1            0.125 0.021   5.858  0.000    0.083    0.167
## 12     sex1 ~1            0.950 0.015  63.510  0.000    0.920    0.979
## 13 SESscore ~1           -0.037 0.013  -2.928  0.003   -0.061   -0.012
## 14    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
model3.anx <- 'Zanx ~ sex1 + SESscore + Zgcse + Zhqual'
model3.anxfit <- sem(model3.anx, data = df, missing = "fiml", fixed.x = FALSE)
summary(model3.anxfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 19 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        20
## 
##   Number of observations                          6488
##   Number of missing patterns                         8
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                91.203
##   Degrees of freedom                                 4
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -31072.994
##   Loglikelihood unrestricted model (H1)     -31072.994
##                                                       
##   Akaike (AIC)                               62185.989
##   Bayesian (BIC)                             62321.543
##   Sample-size adjusted Bayesian (SABIC)      62257.988
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zanx ~                                                                
##     sex1             -0.334    0.035   -9.541    0.000   -0.402   -0.265
##     SESscore         -0.003    0.021   -0.161    0.872   -0.044    0.038
##     Zgcse            -0.003    0.023   -0.146    0.884   -0.048    0.041
##     Zhqual           -0.010    0.021   -0.478    0.633   -0.051    0.031
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.429    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     Zhqual           -0.021    0.008   -2.604    0.009   -0.036   -0.005
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.432    0.000    0.422    0.473
##     Zhqual            0.342    0.015   22.275    0.000    0.312    0.372
##   Zgcse ~~                                                              
##     Zhqual            0.565    0.018   31.550    0.000    0.530    0.600
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zanx              0.124    0.022    5.753    0.000    0.082    0.167
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.034    0.012   -2.928    0.003   -0.057   -0.011
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
##     Zhqual           -0.121    0.016   -7.515    0.000   -0.153   -0.089
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zanx              0.973    0.024   41.406    0.000    0.927    1.020
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.318    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     Zhqual            1.039    0.024   42.573    0.000    0.992    1.087
## 
## R-Square:
##                    Estimate
##     Zanx              0.028
standardizedsolution(model3.anxfit)
##         lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1      Zanx  ~     sex1  -0.167 0.017  -9.713  0.000   -0.200   -0.133
## 2      Zanx  ~ SESscore  -0.003 0.020  -0.161  0.872   -0.042    0.035
## 3      Zanx  ~    Zgcse  -0.003 0.023  -0.146  0.884   -0.048    0.041
## 4      Zanx  ~   Zhqual  -0.010 0.022  -0.478  0.633   -0.052    0.032
## 5      Zanx ~~     Zanx   0.972 0.006 170.791  0.000    0.961    0.983
## 6      sex1 ~~     sex1   1.000 0.000      NA     NA    1.000    1.000
## 7      sex1 ~~ SESscore   0.030 0.012   2.433  0.015    0.006    0.055
## 8      sex1 ~~    Zgcse  -0.053 0.012  -4.250  0.000   -0.077   -0.028
## 9      sex1 ~~   Zhqual  -0.041 0.016  -2.613  0.009   -0.071   -0.010
## 10 SESscore ~~ SESscore   1.000 0.000      NA     NA    1.000    1.000
## 11 SESscore ~~    Zgcse   0.478 0.010  49.330  0.000    0.459    0.497
## 12 SESscore ~~   Zhqual   0.358 0.014  26.376  0.000    0.332    0.385
## 13    Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 14    Zgcse ~~   Zhqual   0.554 0.012  47.867  0.000    0.531    0.577
## 15   Zhqual ~~   Zhqual   1.000 0.000      NA     NA    1.000    1.000
## 16     Zanx ~1            0.124 0.021   5.795  0.000    0.082    0.166
## 17     sex1 ~1            0.950 0.015  63.509  0.000    0.920    0.979
## 18 SESscore ~1           -0.037 0.013  -2.927  0.003   -0.061   -0.012
## 19    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
## 20   Zhqual ~1           -0.119 0.016  -7.580  0.000   -0.149   -0.088
#get change in R2 for model1 vs. model2 vs. model3
(PE.model3.anx <- parameterEstimates(model3.anxfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1      Zanx  ~     sex1 -0.334 0.035 -9.541  0.000   -0.402   -0.265
## 2      Zanx  ~ SESscore -0.003 0.021 -0.161  0.872   -0.044    0.038
## 3      Zanx  ~    Zgcse -0.003 0.023 -0.146  0.884   -0.048    0.041
## 4      Zanx  ~   Zhqual -0.010 0.021 -0.478  0.633   -0.051    0.031
## 5      Zanx ~~     Zanx  0.973 0.024 41.406  0.000    0.927    1.020
## 6      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 7      sex1 ~~ SESscore  0.014 0.006  2.429  0.015    0.003    0.026
## 8      sex1 ~~    Zgcse -0.026 0.006 -4.232  0.000   -0.038   -0.014
## 9      sex1 ~~   Zhqual -0.021 0.008 -2.604  0.009   -0.036   -0.005
## 10 SESscore ~~ SESscore  0.875 0.016 56.318  0.000    0.844    0.905
## 11 SESscore ~~    Zgcse  0.447 0.013 34.432  0.000    0.422    0.473
## 12 SESscore ~~   Zhqual  0.342 0.015 22.275  0.000    0.312    0.372
## 13    Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 14    Zgcse ~~   Zhqual  0.565 0.018 31.550  0.000    0.530    0.600
## 15   Zhqual ~~   Zhqual  1.039 0.024 42.573  0.000    0.992    1.087
## 16     Zanx ~1           0.124 0.022  5.753  0.000    0.082    0.167
## 17     sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 18 SESscore ~1          -0.034 0.012 -2.928  0.003   -0.057   -0.011
## 19    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 20   Zhqual ~1          -0.121 0.016 -7.515  0.000   -0.153   -0.089
## 21     Zanx r2     Zanx  0.028    NA     NA     NA       NA       NA
PE.model3.anx$est[PE.model3.anx$op == "r2"]
## [1] 0.02776333
(PE.model2.anx <- parameterEstimates(model2.anxfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1      Zanx  ~     sex1 -0.333 0.035 -9.531  0.000   -0.402   -0.265
## 2      Zanx  ~ SESscore -0.005 0.021 -0.243  0.808   -0.046    0.036
## 3      Zanx  ~    Zgcse -0.008 0.020 -0.405  0.686   -0.048    0.031
## 4      Zanx ~~     Zanx  0.974 0.024 41.406  0.000    0.927    1.020
## 5      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 6      sex1 ~~ SESscore  0.014 0.006  2.434  0.015    0.003    0.026
## 7      sex1 ~~    Zgcse -0.026 0.006 -4.232  0.000   -0.038   -0.014
## 8  SESscore ~~ SESscore  0.875 0.016 56.312  0.000    0.844    0.905
## 9  SESscore ~~    Zgcse  0.447 0.013 34.436  0.000    0.422    0.473
## 10    Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 11     Zanx ~1           0.125 0.022  5.814  0.000    0.083    0.167
## 12     sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 13 SESscore ~1          -0.034 0.012 -2.928  0.003   -0.057   -0.011
## 14    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 15     Zanx r2     Zanx  0.028    NA     NA     NA       NA       NA
PE.model2.anx$est[PE.model2.anx$op == "r2"]
## [1] 0.02769291
(PE.model1.anx <- parameterEstimates(model1.anxfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1      Zanx  ~     sex1 -0.333 0.035 -9.525  0.000   -0.402   -0.265
## 2      Zanx  ~ SESscore -0.012 0.018 -0.637  0.524   -0.047    0.024
## 3      Zanx ~~     Zanx  0.974 0.024 41.406  0.000    0.927    1.020
## 4      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 5      sex1 ~~ SESscore  0.013 0.006  2.290  0.022    0.002    0.025
## 6  SESscore ~~ SESscore  0.873 0.015 56.387  0.000    0.842    0.903
## 7      Zanx ~1           0.124 0.021  5.829  0.000    0.082    0.165
## 8      sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 9  SESscore ~1          -0.029 0.012 -2.518  0.012   -0.052   -0.007
## 10     Zanx r2     Zanx  0.028    NA     NA     NA       NA       NA
PE.model1.anx$est[PE.model1.anx$op == "r2"]
## [1] 0.02784133
r2diff2.anx <- (PE.model2.anx$est[PE.model2.anx$op == "r2"] - PE.model1.anx$est[PE.model1.anx$op == "r2"])
print(r2diff2.anx)    #difference model1 vs 2, incremental explained variance by GCSE
## [1] -0.0001484237
r2diff3.anx <- (PE.model3.anx$est[PE.model3.anx$op == "r2"] - PE.model2.anx$est[PE.model2.anx$op == "r2"])
print(r2diff3.anx)    #difference model2 vs 3, incremental explained variance by highest qualification
## [1] 7.042342e-05
model1.sdq <- 'Zsdq ~ sex1 + SESscore'
model1.sdqfit <- sem(model1.sdq, data = df, missing = "fiml", fixed.x = FALSE)
summary(model1.sdqfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 15 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                86.719
##   Degrees of freedom                                 2
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -18571.565
##   Loglikelihood unrestricted model (H1)     -18571.565
##                                                       
##   Akaike (AIC)                               37161.130
##   Bayesian (BIC)                             37222.130
##   Sample-size adjusted Bayesian (SABIC)      37193.530
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zsdq ~                                                                
##     sex1             -0.187    0.033   -5.618    0.000   -0.252   -0.121
##     SESscore         -0.126    0.017   -7.214    0.000   -0.160   -0.092
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.013    0.006    2.303    0.021    0.002    0.025
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsdq              0.079    0.021    3.831    0.000    0.038    0.119
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.030    0.012   -2.533    0.011   -0.053   -0.007
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsdq              0.977    0.023   43.317    0.000    0.932    1.021
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.873    0.015   56.383    0.000    0.842    0.903
## 
## R-Square:
##                    Estimate
##     Zsdq              0.023
standardizedsolution(model1.sdqfit)
##        lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1     Zsdq  ~     sex1  -0.093 0.016  -5.647  0.000   -0.126   -0.061
## 2     Zsdq  ~ SESscore  -0.118 0.016  -7.271  0.000   -0.150   -0.086
## 3     Zsdq ~~     Zsdq   0.977 0.005 200.154  0.000    0.967    0.986
## 4     sex1 ~~     sex1   1.000 0.000      NA     NA    1.000    1.000
## 5     sex1 ~~ SESscore   0.029 0.013   2.306  0.021    0.004    0.053
## 6 SESscore ~~ SESscore   1.000 0.000      NA     NA    1.000    1.000
## 7     Zsdq ~1            0.079 0.020   3.842  0.000    0.039    0.119
## 8     sex1 ~1            0.950 0.015  63.510  0.000    0.920    0.979
## 9 SESscore ~1           -0.032 0.013  -2.532  0.011   -0.056   -0.007
model2.sdq <- 'Zsdq ~ sex1 + SESscore + Zgcse'
model2.sdqfit <- sem(model2.sdq, data = df, missing = "fiml", fixed.x = FALSE)
summary(model2.sdqfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 17 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        14
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                               215.457
##   Degrees of freedom                                 3
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -26875.026
##   Loglikelihood unrestricted model (H1)     -26875.026
##                                                       
##   Akaike (AIC)                               53778.051
##   Bayesian (BIC)                             53872.939
##   Sample-size adjusted Bayesian (SABIC)      53828.451
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zsdq ~                                                                
##     sex1             -0.192    0.033   -5.874    0.000   -0.256   -0.128
##     SESscore         -0.024    0.019   -1.253    0.210   -0.063    0.014
##     Zgcse            -0.216    0.019  -11.322    0.000   -0.253   -0.178
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.436    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.438    0.000    0.422    0.473
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsdq              0.118    0.020    5.758    0.000    0.078    0.158
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.034    0.012   -2.930    0.003   -0.057   -0.011
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsdq              0.944    0.022   43.329    0.000    0.901    0.987
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.310    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zsdq              0.059
standardizedsolution(model2.sdqfit)
##         lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1      Zsdq  ~     sex1  -0.096 0.016  -5.899  0.000   -0.127   -0.064
## 2      Zsdq  ~ SESscore  -0.023 0.018  -1.253  0.210   -0.058    0.013
## 3      Zsdq  ~    Zgcse  -0.215 0.019 -11.584  0.000   -0.252   -0.179
## 4      Zsdq ~~     Zsdq   0.941 0.008 123.615  0.000    0.926    0.956
## 5      sex1 ~~     sex1   1.000 0.000      NA     NA    1.000    1.000
## 6      sex1 ~~ SESscore   0.030 0.012   2.440  0.015    0.006    0.055
## 7      sex1 ~~    Zgcse  -0.053 0.012  -4.250  0.000   -0.077   -0.028
## 8  SESscore ~~ SESscore   1.000 0.000      NA     NA    1.000    1.000
## 9  SESscore ~~    Zgcse   0.478 0.010  49.352  0.000    0.459    0.497
## 10    Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 11     Zsdq ~1            0.118 0.020   5.792  0.000    0.078    0.158
## 12     sex1 ~1            0.950 0.015  63.509  0.000    0.920    0.979
## 13 SESscore ~1           -0.037 0.013  -2.929  0.003   -0.061   -0.012
## 14    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
model3.sdq <- 'Zsdq ~ sex1 + SESscore + Zgcse + Zhqual'
model3.sdqfit <- sem(model3.sdq, data = df, missing = "fiml", fixed.x = FALSE)
summary(model3.sdqfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 19 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        20
## 
##   Number of observations                          6488
##   Number of missing patterns                         8
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                               245.717
##   Degrees of freedom                                 4
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -31458.311
##   Loglikelihood unrestricted model (H1)     -31458.311
##                                                       
##   Akaike (AIC)                               62956.622
##   Bayesian (BIC)                             63092.176
##   Sample-size adjusted Bayesian (SABIC)      63028.622
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zsdq ~                                                                
##     sex1             -0.197    0.033   -6.046    0.000   -0.260   -0.133
##     SESscore         -0.010    0.020   -0.489    0.625   -0.048    0.029
##     Zgcse            -0.163    0.021   -7.685    0.000   -0.205   -0.122
##     Zhqual           -0.105    0.019   -5.520    0.000   -0.143   -0.068
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.429    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     Zhqual           -0.021    0.008   -2.594    0.009   -0.036   -0.005
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.433    0.000    0.422    0.473
##     Zhqual            0.342    0.015   22.287    0.000    0.312    0.372
##   Zgcse ~~                                                              
##     Zhqual            0.565    0.018   31.574    0.000    0.530    0.601
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsdq              0.108    0.020    5.268    0.000    0.068    0.148
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.034    0.012   -2.929    0.003   -0.057   -0.011
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
##     Zhqual           -0.121    0.016   -7.530    0.000   -0.153   -0.090
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsdq              0.936    0.022   43.319    0.000    0.894    0.979
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.317    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     Zhqual            1.040    0.024   42.565    0.000    0.992    1.088
## 
## R-Square:
##                    Estimate
##     Zsdq              0.067
standardizedsolution(model3.sdqfit)
##         lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1      Zsdq  ~     sex1  -0.098 0.016  -6.073  0.000   -0.130   -0.066
## 2      Zsdq  ~ SESscore  -0.009 0.018  -0.489  0.625   -0.045    0.027
## 3      Zsdq  ~    Zgcse  -0.163 0.021  -7.768  0.000   -0.204   -0.122
## 4      Zsdq  ~   Zhqual  -0.107 0.019  -5.539  0.000   -0.145   -0.069
## 5      Zsdq ~~     Zsdq   0.933 0.008 115.922  0.000    0.917    0.949
## 6      sex1 ~~     sex1   1.000 0.000      NA     NA    1.000    1.000
## 7      sex1 ~~ SESscore   0.030 0.012   2.433  0.015    0.006    0.055
## 8      sex1 ~~    Zgcse  -0.053 0.012  -4.250  0.000   -0.077   -0.028
## 9      sex1 ~~   Zhqual  -0.041 0.016  -2.603  0.009   -0.071   -0.010
## 10 SESscore ~~ SESscore   1.000 0.000      NA     NA    1.000    1.000
## 11 SESscore ~~    Zgcse   0.478 0.010  49.334  0.000    0.459    0.497
## 12 SESscore ~~   Zhqual   0.359 0.014  26.394  0.000    0.332    0.385
## 13    Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 14    Zgcse ~~   Zhqual   0.555 0.012  47.946  0.000    0.532    0.577
## 15   Zhqual ~~   Zhqual   1.000 0.000      NA     NA    1.000    1.000
## 16     Zsdq ~1            0.108 0.020   5.294  0.000    0.068    0.148
## 17     sex1 ~1            0.950 0.015  63.509  0.000    0.920    0.979
## 18 SESscore ~1           -0.037 0.013  -2.928  0.003   -0.061   -0.012
## 19    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
## 20   Zhqual ~1           -0.119 0.016  -7.596  0.000   -0.150   -0.088
#get change in R2 for model1 vs. model2 vs. model3
(PE.model3.sdq <- parameterEstimates(model3.sdqfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1      Zsdq  ~     sex1 -0.197 0.033 -6.046  0.000   -0.260   -0.133
## 2      Zsdq  ~ SESscore -0.010 0.020 -0.489  0.625   -0.048    0.029
## 3      Zsdq  ~    Zgcse -0.163 0.021 -7.685  0.000   -0.205   -0.122
## 4      Zsdq  ~   Zhqual -0.105 0.019 -5.520  0.000   -0.143   -0.068
## 5      Zsdq ~~     Zsdq  0.936 0.022 43.319  0.000    0.894    0.979
## 6      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 7      sex1 ~~ SESscore  0.014 0.006  2.429  0.015    0.003    0.026
## 8      sex1 ~~    Zgcse -0.026 0.006 -4.232  0.000   -0.038   -0.014
## 9      sex1 ~~   Zhqual -0.021 0.008 -2.594  0.009   -0.036   -0.005
## 10 SESscore ~~ SESscore  0.875 0.016 56.317  0.000    0.844    0.905
## 11 SESscore ~~    Zgcse  0.447 0.013 34.433  0.000    0.422    0.473
## 12 SESscore ~~   Zhqual  0.342 0.015 22.287  0.000    0.312    0.372
## 13    Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 14    Zgcse ~~   Zhqual  0.565 0.018 31.574  0.000    0.530    0.601
## 15   Zhqual ~~   Zhqual  1.040 0.024 42.565  0.000    0.992    1.088
## 16     Zsdq ~1           0.108 0.020  5.268  0.000    0.068    0.148
## 17     sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 18 SESscore ~1          -0.034 0.012 -2.929  0.003   -0.057   -0.011
## 19    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 20   Zhqual ~1          -0.121 0.016 -7.530  0.000   -0.153   -0.090
## 21     Zsdq r2     Zsdq  0.067    NA     NA     NA       NA       NA
PE.model3.sdq$est[PE.model3.sdq$op == "r2"]
## [1] 0.06673514
(PE.model2.sdq <- parameterEstimates(model2.sdqfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se       z pvalue ci.lower ci.upper
## 1      Zsdq  ~     sex1 -0.192 0.033  -5.874  0.000   -0.256   -0.128
## 2      Zsdq  ~ SESscore -0.024 0.019  -1.253  0.210   -0.063    0.014
## 3      Zsdq  ~    Zgcse -0.216 0.019 -11.322  0.000   -0.253   -0.178
## 4      Zsdq ~~     Zsdq  0.944 0.022  43.329  0.000    0.901    0.987
## 5      sex1 ~~     sex1  0.249 0.004  56.956  0.000    0.241    0.258
## 6      sex1 ~~ SESscore  0.014 0.006   2.436  0.015    0.003    0.026
## 7      sex1 ~~    Zgcse -0.026 0.006  -4.232  0.000   -0.038   -0.014
## 8  SESscore ~~ SESscore  0.875 0.016  56.310  0.000    0.844    0.905
## 9  SESscore ~~    Zgcse  0.447 0.013  34.438  0.000    0.422    0.473
## 10    Zgcse ~~    Zgcse  1.000 0.018  56.956  0.000    0.965    1.034
## 11     Zsdq ~1           0.118 0.020   5.758  0.000    0.078    0.158
## 12     sex1 ~1           0.474 0.006  76.503  0.000    0.462    0.486
## 13 SESscore ~1          -0.034 0.012  -2.930  0.003   -0.057   -0.011
## 14    Zgcse ~1           0.000 0.012   0.000  1.000   -0.024    0.024
## 15     Zsdq r2     Zsdq  0.059    NA      NA     NA       NA       NA
PE.model2.sdq$est[PE.model2.sdq$op == "r2"]
## [1] 0.05875481
(PE.model1.sdq <- parameterEstimates(model1.sdqfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1      Zsdq  ~     sex1 -0.187 0.033 -5.618  0.000   -0.252   -0.121
## 2      Zsdq  ~ SESscore -0.126 0.017 -7.214  0.000   -0.160   -0.092
## 3      Zsdq ~~     Zsdq  0.977 0.023 43.317  0.000    0.932    1.021
## 4      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 5      sex1 ~~ SESscore  0.013 0.006  2.303  0.021    0.002    0.025
## 6  SESscore ~~ SESscore  0.873 0.015 56.383  0.000    0.842    0.903
## 7      Zsdq ~1           0.079 0.021  3.831  0.000    0.038    0.119
## 8      sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 9  SESscore ~1          -0.030 0.012 -2.533  0.011   -0.053   -0.007
## 10     Zsdq r2     Zsdq  0.023    NA     NA     NA       NA       NA
PE.model1.sdq$est[PE.model1.sdq$op == "r2"]
## [1] 0.02318273
r2diff2.sdq <- (PE.model2.sdq$est[PE.model2.sdq$op == "r2"] - PE.model1.sdq$est[PE.model1.sdq$op == "r2"])
print(r2diff2.sdq)    #difference model1 vs 2, incremental explained variance by GCSE
## [1] 0.03557208
r2diff3.sdq <- (PE.model3.sdq$est[PE.model3.sdq$op == "r2"] - PE.model2.sdq$est[PE.model2.sdq$op == "r2"])
print(r2diff3.sdq)    #difference model2 vs 3, incremental explained variance by highest qualification
## [1] 0.007980322
model1.alc <- 'Zalc ~ sex1 + SESscore'
model1.alcfit <- sem(model1.alc, data = df, missing = "fiml", fixed.x = FALSE)
summary(model1.alcfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 16 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                68.423
##   Degrees of freedom                                 2
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -17749.215
##   Loglikelihood unrestricted model (H1)     -17749.215
##                                                       
##   Akaike (AIC)                               35516.431
##   Bayesian (BIC)                             35577.430
##   Sample-size adjusted Bayesian (SABIC)      35548.830
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zalc ~                                                                
##     sex1              0.223    0.036    6.124    0.000    0.151    0.294
##     SESscore          0.101    0.019    5.275    0.000    0.064    0.139
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.013    0.006    2.286    0.022    0.002    0.025
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zalc             -0.091    0.022   -4.076    0.000   -0.134   -0.047
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.029    0.012   -2.512    0.012   -0.052   -0.006
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zalc              0.978    0.025   39.800    0.000    0.930    1.026
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.873    0.015   56.386    0.000    0.842    0.903
## 
## R-Square:
##                    Estimate
##     Zalc              0.022
standardizedsolution(model1.alcfit)
##        lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1     Zalc  ~     sex1   0.111 0.018   6.172  0.000    0.076    0.146
## 2     Zalc  ~ SESscore   0.095 0.018   5.303  0.000    0.060    0.130
## 3     Zalc ~~     Zalc   0.978 0.005 188.225  0.000    0.968    0.988
## 4     sex1 ~~     sex1   1.000 0.000      NA     NA    1.000    1.000
## 5     sex1 ~~ SESscore   0.029 0.013   2.289  0.022    0.004    0.053
## 6 SESscore ~~ SESscore   1.000 0.000      NA     NA    1.000    1.000
## 7     Zalc ~1           -0.091 0.022  -4.092  0.000   -0.134   -0.047
## 8     sex1 ~1            0.950 0.015  63.510  0.000    0.920    0.979
## 9 SESscore ~1           -0.031 0.013  -2.511  0.012   -0.056   -0.007
model2.alc <- 'Zalc ~ sex1 + SESscore + Zgcse'
model2.alcfit <- sem(model2.alc, data = df, missing = "fiml", fixed.x = FALSE)
summary(model2.alcfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 19 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        14
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                70.049
##   Degrees of freedom                                 3
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -26116.231
##   Loglikelihood unrestricted model (H1)     -26116.231
##                                                       
##   Akaike (AIC)                               52260.463
##   Bayesian (BIC)                             52355.351
##   Sample-size adjusted Bayesian (SABIC)      52310.862
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zalc ~                                                                
##     sex1              0.222    0.036    6.119    0.000    0.151    0.294
##     SESscore          0.112    0.022    5.152    0.000    0.069    0.154
##     Zgcse            -0.020    0.021   -0.923    0.356   -0.061    0.022
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.431    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.442    0.000    0.422    0.473
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zalc             -0.087    0.023   -3.831    0.000   -0.131   -0.042
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.034    0.012   -2.923    0.003   -0.057   -0.011
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zalc              0.978    0.025   39.800    0.000    0.930    1.026
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.308    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zalc              0.023
standardizedsolution(model2.alcfit)
##         lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1      Zalc  ~     sex1   0.111 0.018   6.167  0.000    0.076    0.146
## 2      Zalc  ~ SESscore   0.105 0.020   5.179  0.000    0.065    0.144
## 3      Zalc  ~    Zgcse  -0.020 0.021  -0.923  0.356   -0.061    0.022
## 4      Zalc ~~     Zalc   0.977 0.005 184.172  0.000    0.967    0.988
## 5      sex1 ~~     sex1   1.000 0.000      NA     NA    1.000    1.000
## 6      sex1 ~~ SESscore   0.030 0.012   2.434  0.015    0.006    0.055
## 7      sex1 ~~    Zgcse  -0.053 0.012  -4.250  0.000   -0.077   -0.028
## 8  SESscore ~~ SESscore   1.000 0.000      NA     NA    1.000    1.000
## 9  SESscore ~~    Zgcse   0.478 0.010  49.364  0.000    0.459    0.497
## 10    Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 11     Zalc ~1           -0.087 0.023  -3.844  0.000   -0.131   -0.042
## 12     sex1 ~1            0.950 0.015  63.509  0.000    0.920    0.979
## 13 SESscore ~1           -0.037 0.013  -2.922  0.003   -0.061   -0.012
## 14    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
model3.alc <- 'Zalc ~ sex1 + SESscore + Zgcse + Zhqual'
model3.alcfit <- sem(model3.alc, data = df, missing = "fiml", fixed.x = FALSE)
summary(model3.alcfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 18 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        20
## 
##   Number of observations                          6488
##   Number of missing patterns                         8
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                71.629
##   Degrees of freedom                                 4
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -30713.857
##   Loglikelihood unrestricted model (H1)     -30713.857
##                                                       
##   Akaike (AIC)                               61467.714
##   Bayesian (BIC)                             61603.269
##   Sample-size adjusted Bayesian (SABIC)      61539.714
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zalc ~                                                                
##     sex1              0.224    0.036    6.158    0.000    0.153    0.295
##     SESscore          0.109    0.022    5.007    0.000    0.067    0.152
##     Zgcse            -0.033    0.024   -1.386    0.166   -0.080    0.014
##     Zhqual            0.027    0.022    1.207    0.227   -0.017    0.071
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.426    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     Zhqual           -0.021    0.008   -2.597    0.009   -0.036   -0.005
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.438    0.000    0.422    0.473
##     Zhqual            0.342    0.015   22.280    0.000    0.312    0.372
##   Zgcse ~~                                                              
##     Zhqual            0.565    0.018   31.542    0.000    0.530    0.600
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zalc             -0.085    0.023   -3.736    0.000   -0.129   -0.040
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.034    0.012   -2.922    0.003   -0.057   -0.011
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
##     Zhqual           -0.121    0.016   -7.507    0.000   -0.152   -0.089
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zalc              0.977    0.025   39.799    0.000    0.929    1.025
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.313    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     Zhqual            1.039    0.024   42.578    0.000    0.991    1.087
## 
## R-Square:
##                    Estimate
##     Zalc              0.023
standardizedsolution(model3.alcfit)
##         lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1      Zalc  ~     sex1   0.112 0.018   6.208  0.000    0.076    0.147
## 2      Zalc  ~ SESscore   0.102 0.020   5.032  0.000    0.062    0.142
## 3      Zalc  ~    Zgcse  -0.033 0.024  -1.387  0.165   -0.080    0.014
## 4      Zalc  ~   Zhqual   0.028 0.023   1.207  0.227   -0.017    0.072
## 5      Zalc ~~     Zalc   0.977 0.005 180.075  0.000    0.966    0.987
## 6      sex1 ~~     sex1   1.000 0.000      NA     NA    1.000    1.000
## 7      sex1 ~~ SESscore   0.030 0.012   2.429  0.015    0.006    0.055
## 8      sex1 ~~    Zgcse  -0.053 0.012  -4.250  0.000   -0.077   -0.028
## 9      sex1 ~~   Zhqual  -0.041 0.016  -2.605  0.009   -0.071   -0.010
## 10 SESscore ~~ SESscore   1.000 0.000      NA     NA    1.000    1.000
## 11 SESscore ~~    Zgcse   0.478 0.010  49.348  0.000    0.459    0.497
## 12 SESscore ~~   Zhqual   0.359 0.014  26.385  0.000    0.332    0.385
## 13    Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 14    Zgcse ~~   Zhqual   0.554 0.012  47.839  0.000    0.531    0.577
## 15   Zhqual ~~   Zhqual   1.000 0.000      NA     NA    1.000    1.000
## 16     Zalc ~1           -0.085 0.023  -3.748  0.000   -0.129   -0.040
## 17     sex1 ~1            0.950 0.015  63.510  0.000    0.920    0.979
## 18 SESscore ~1           -0.037 0.013  -2.922  0.003   -0.061   -0.012
## 19    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
## 20   Zhqual ~1           -0.119 0.016  -7.572  0.000   -0.149   -0.088
#get change in R2 for model1 vs. model2 vs. model3
(PE.model3.alc <- parameterEstimates(model3.alcfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1      Zalc  ~     sex1  0.224 0.036  6.158  0.000    0.153    0.295
## 2      Zalc  ~ SESscore  0.109 0.022  5.007  0.000    0.067    0.152
## 3      Zalc  ~    Zgcse -0.033 0.024 -1.386  0.166   -0.080    0.014
## 4      Zalc  ~   Zhqual  0.027 0.022  1.207  0.227   -0.017    0.071
## 5      Zalc ~~     Zalc  0.977 0.025 39.799  0.000    0.929    1.025
## 6      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 7      sex1 ~~ SESscore  0.014 0.006  2.426  0.015    0.003    0.026
## 8      sex1 ~~    Zgcse -0.026 0.006 -4.232  0.000   -0.038   -0.014
## 9      sex1 ~~   Zhqual -0.021 0.008 -2.597  0.009   -0.036   -0.005
## 10 SESscore ~~ SESscore  0.875 0.016 56.313  0.000    0.844    0.905
## 11 SESscore ~~    Zgcse  0.447 0.013 34.438  0.000    0.422    0.473
## 12 SESscore ~~   Zhqual  0.342 0.015 22.280  0.000    0.312    0.372
## 13    Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 14    Zgcse ~~   Zhqual  0.565 0.018 31.542  0.000    0.530    0.600
## 15   Zhqual ~~   Zhqual  1.039 0.024 42.578  0.000    0.991    1.087
## 16     Zalc ~1          -0.085 0.023 -3.736  0.000   -0.129   -0.040
## 17     sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 18 SESscore ~1          -0.034 0.012 -2.922  0.003   -0.057   -0.011
## 19    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 20   Zhqual ~1          -0.121 0.016 -7.507  0.000   -0.152   -0.089
## 21     Zalc r2     Zalc  0.023    NA     NA     NA       NA       NA
PE.model3.alc$est[PE.model3.alc$op == "r2"]
## [1] 0.02338286
(PE.model2.alc <- parameterEstimates(model2.alcfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1      Zalc  ~     sex1  0.222 0.036  6.119  0.000    0.151    0.294
## 2      Zalc  ~ SESscore  0.112 0.022  5.152  0.000    0.069    0.154
## 3      Zalc  ~    Zgcse -0.020 0.021 -0.923  0.356   -0.061    0.022
## 4      Zalc ~~     Zalc  0.978 0.025 39.800  0.000    0.930    1.026
## 5      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 6      sex1 ~~ SESscore  0.014 0.006  2.431  0.015    0.003    0.026
## 7      sex1 ~~    Zgcse -0.026 0.006 -4.232  0.000   -0.038   -0.014
## 8  SESscore ~~ SESscore  0.875 0.016 56.308  0.000    0.844    0.905
## 9  SESscore ~~    Zgcse  0.447 0.013 34.442  0.000    0.422    0.473
## 10    Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 11     Zalc ~1          -0.087 0.023 -3.831  0.000   -0.131   -0.042
## 12     sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 13 SESscore ~1          -0.034 0.012 -2.923  0.003   -0.057   -0.011
## 14    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 15     Zalc r2     Zalc  0.023    NA     NA     NA       NA       NA
PE.model2.alc$est[PE.model2.alc$op == "r2"]
## [1] 0.02263004
(PE.model1.alc <- parameterEstimates(model1.alcfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1      Zalc  ~     sex1  0.223 0.036  6.124  0.000    0.151    0.294
## 2      Zalc  ~ SESscore  0.101 0.019  5.275  0.000    0.064    0.139
## 3      Zalc ~~     Zalc  0.978 0.025 39.800  0.000    0.930    1.026
## 4      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 5      sex1 ~~ SESscore  0.013 0.006  2.286  0.022    0.002    0.025
## 6  SESscore ~~ SESscore  0.873 0.015 56.386  0.000    0.842    0.903
## 7      Zalc ~1          -0.091 0.022 -4.076  0.000   -0.134   -0.047
## 8      sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 9  SESscore ~1          -0.029 0.012 -2.512  0.012   -0.052   -0.006
## 10     Zalc r2     Zalc  0.022    NA     NA     NA       NA       NA
PE.model1.alc$est[PE.model1.alc$op == "r2"]
## [1] 0.02191005
r2diff2.alc <- (PE.model2.alc$est[PE.model2.alc$op == "r2"] - PE.model1.alc$est[PE.model1.alc$op == "r2"])
print(r2diff2.alc)    #difference model1 vs 2, incremental explained variance by GCSE
## [1] 0.0007199847
r2diff3.alc <- (PE.model3.alc$est[PE.model3.alc$op == "r2"] - PE.model2.alc$est[PE.model2.alc$op == "r2"])
print(r2diff3.alc)    #difference model2 vs 3, incremental explained variance by highest qualification
## [1] 0.0007528224

#Logistic and multi-nominal regression for categorical outcomes (w/o moderation)

logistic regression (ordered sub-command) doesn’t work with FIML in sem-function, we use listwise deletion here instead

logistic regression usually uses logit link, but not (yet) implemented in lavaan, instead probit is suggested “You can get approximate logits from probits as Beta_logit=1.7xBeta_probit. Then, OR =exp(Beta_logit).” (according to lavaan forum online)

Logit transforms probabilities into log-odds, whereas probit transforms probabilities into z-scores from a standard normal distribution (e.g., a probability of 50% is associated with a z-score of 0, and probability of 84% is associated with a z-score of 1). Effects can be interpeted as changes in units of SD for the transformed outcome variable.

How many missings are there for benefit status and employment status?

freq_status <- freq(df$status1)   #3743 valid cases, 2745 missing
freq_benf <- freq(df$u1cbenf11)   #3735 valid cases, 2752 missing
model1.benf <- 'u1cbenf11 ~ sex1 + SESscore'
model1.benffit <- sem(model1.benf, data = df, ordered = c("u1cbenf11"), missing = "listwise")
summary(model1.benffit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 11 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         3
## 
##                                                   Used       Total
##   Number of observations                          3691        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   u1cbenf11 ~                                                           
##     sex1             -0.173    0.077   -2.239    0.025   -0.325   -0.022
##     SESscore         -0.244    0.038   -6.359    0.000   -0.319   -0.169
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .u1cbenf11         0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     u1cbenf11|t1      1.644    0.045   36.465    0.000    1.555    1.732
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .u1cbenf11         1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     u1cbenf11         1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     u1cbenf11         0.057
standardizedsolution(model1.benffit)
##          lhs  op       rhs est.std    se      z pvalue ci.lower ci.upper
## 1  u1cbenf11   ~      sex1  -0.082 0.036 -2.254  0.024   -0.153   -0.011
## 2  u1cbenf11   ~  SESscore  -0.221 0.033 -6.684  0.000   -0.286   -0.156
## 3  u1cbenf11   |        t1   1.596 0.046 34.636  0.000    1.505    1.686
## 4  u1cbenf11  ~~ u1cbenf11   0.943 0.016 59.461  0.000    0.911    0.974
## 5       sex1  ~~      sex1   1.000 0.000     NA     NA    1.000    1.000
## 6       sex1  ~~  SESscore   0.050 0.000     NA     NA    0.050    0.050
## 7   SESscore  ~~  SESscore   1.000 0.000     NA     NA    1.000    1.000
## 8  u1cbenf11 ~*~ u1cbenf11   1.000 0.000     NA     NA    1.000    1.000
## 9  u1cbenf11  ~1             0.000 0.000     NA     NA    0.000    0.000
## 10      sex1  ~1             0.788 0.000     NA     NA    0.788    0.788
## 11  SESscore  ~1             0.060 0.000     NA     NA    0.060    0.060
model2.benf <- 'u1cbenf11 ~ sex1 + SESscore + Zgcse'
model2.benffit <- sem(model2.benf, data = df, ordered = c("u1cbenf11"), missing = "listwise")
summary(model2.benffit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 14 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         4
## 
##                                                   Used       Total
##   Number of observations                          3691        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   u1cbenf11 ~                                                           
##     sex1             -0.180    0.078   -2.299    0.022   -0.333   -0.027
##     SESscore         -0.136    0.043   -3.165    0.002   -0.220   -0.052
##     Zgcse            -0.234    0.041   -5.656    0.000   -0.315   -0.153
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .u1cbenf11         0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     u1cbenf11|t1      1.633    0.046   35.662    0.000    1.544    1.723
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .u1cbenf11         1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     u1cbenf11         1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     u1cbenf11         0.091
standardizedsolution(model2.benffit)
##          lhs  op       rhs est.std    se      z pvalue ci.lower ci.upper
## 1  u1cbenf11   ~      sex1  -0.083 0.036 -2.315  0.021   -0.154   -0.013
## 2  u1cbenf11   ~  SESscore  -0.121 0.038 -3.207  0.001   -0.195   -0.047
## 3  u1cbenf11   ~     Zgcse  -0.210 0.036 -5.862  0.000   -0.281   -0.140
## 4  u1cbenf11   |        t1   1.557 0.047 33.393  0.000    1.466    1.649
## 5  u1cbenf11  ~~ u1cbenf11   0.909 0.019 47.316  0.000    0.871    0.947
## 6       sex1  ~~      sex1   1.000 0.000     NA     NA    1.000    1.000
## 7       sex1  ~~  SESscore   0.050 0.000     NA     NA    0.050    0.050
## 8       sex1  ~~     Zgcse   0.012 0.000     NA     NA    0.012    0.012
## 9   SESscore  ~~  SESscore   1.000 0.000     NA     NA    1.000    1.000
## 10  SESscore  ~~     Zgcse   0.466 0.000     NA     NA    0.466    0.466
## 11     Zgcse  ~~     Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 12 u1cbenf11 ~*~ u1cbenf11   1.000 0.000     NA     NA    1.000    1.000
## 13 u1cbenf11  ~1             0.000 0.000     NA     NA    0.000    0.000
## 14      sex1  ~1             0.788 0.000     NA     NA    0.788    0.788
## 15  SESscore  ~1             0.060 0.000     NA     NA    0.060    0.060
## 16     Zgcse  ~1             0.212 0.000     NA     NA    0.212    0.212
model3.benf <- 'u1cbenf11 ~ sex1 + SESscore + Zgcse + Zhqual'
model3.benffit <- sem(model3.benf, data = df, ordered = c("u1cbenf11"), missing = "listwise")
summary(model3.benffit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 19 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         5
## 
##                                                   Used       Total
##   Number of observations                          3628        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   u1cbenf11 ~                                                           
##     sex1             -0.178    0.080   -2.235    0.025   -0.335   -0.022
##     SESscore         -0.119    0.044   -2.683    0.007   -0.206   -0.032
##     Zgcse            -0.107    0.048   -2.224    0.026   -0.201   -0.013
##     Zhqual           -0.204    0.037   -5.571    0.000   -0.275   -0.132
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .u1cbenf11         0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     u1cbenf11|t1      1.688    0.050   33.832    0.000    1.590    1.785
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .u1cbenf11         1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     u1cbenf11         1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     u1cbenf11         0.106
standardizedsolution(model3.benffit)
##          lhs  op       rhs est.std    se      z pvalue ci.lower ci.upper
## 1  u1cbenf11   ~      sex1  -0.082 0.036 -2.248  0.025   -0.154   -0.011
## 2  u1cbenf11   ~  SESscore  -0.105 0.039 -2.712  0.007   -0.180   -0.029
## 3  u1cbenf11   ~     Zgcse  -0.094 0.042 -2.244  0.025   -0.176   -0.012
## 4  u1cbenf11   ~    Zhqual  -0.192 0.034 -5.685  0.000   -0.259   -0.126
## 5  u1cbenf11   |        t1   1.596 0.049 32.887  0.000    1.500    1.691
## 6  u1cbenf11  ~~ u1cbenf11   0.894 0.020 44.880  0.000    0.855    0.933
## 7       sex1  ~~      sex1   1.000 0.000     NA     NA    1.000    1.000
## 8       sex1  ~~  SESscore   0.049 0.000     NA     NA    0.049    0.049
## 9       sex1  ~~     Zgcse   0.009 0.000     NA     NA    0.009    0.009
## 10      sex1  ~~    Zhqual  -0.007 0.000     NA     NA   -0.007   -0.007
## 11  SESscore  ~~  SESscore   1.000 0.000     NA     NA    1.000    1.000
## 12  SESscore  ~~     Zgcse   0.458 0.000     NA     NA    0.458    0.458
## 13  SESscore  ~~    Zhqual   0.340 0.000     NA     NA    0.340    0.340
## 14     Zgcse  ~~     Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 15     Zgcse  ~~    Zhqual   0.529 0.000     NA     NA    0.529    0.529
## 16    Zhqual  ~~    Zhqual   1.000 0.000     NA     NA    1.000    1.000
## 17 u1cbenf11 ~*~ u1cbenf11   1.000 0.000     NA     NA    1.000    1.000
## 18 u1cbenf11  ~1             0.000 0.000     NA     NA    0.000    0.000
## 19      sex1  ~1             0.791 0.000     NA     NA    0.791    0.791
## 20  SESscore  ~1             0.068 0.000     NA     NA    0.068    0.068
## 21     Zgcse  ~1             0.230 0.000     NA     NA    0.230    0.230
## 22    Zhqual  ~1             0.003 0.000     NA     NA    0.003    0.003
#get change in R2 for model1 vs. model2 vs. model3
(PE.model3.benf <- parameterEstimates(model3.benffit, rsquare = TRUE)) 
##          lhs  op       rhs    est    se      z pvalue ci.lower ci.upper
## 1  u1cbenf11   ~      sex1 -0.178 0.080 -2.235  0.025   -0.335   -0.022
## 2  u1cbenf11   ~  SESscore -0.119 0.044 -2.683  0.007   -0.206   -0.032
## 3  u1cbenf11   ~     Zgcse -0.107 0.048 -2.224  0.026   -0.201   -0.013
## 4  u1cbenf11   ~    Zhqual -0.204 0.037 -5.571  0.000   -0.275   -0.132
## 5  u1cbenf11   |        t1  1.688 0.050 33.832  0.000    1.590    1.785
## 6  u1cbenf11  ~~ u1cbenf11  1.000 0.000     NA     NA    1.000    1.000
## 7       sex1  ~~      sex1  0.237 0.000     NA     NA    0.237    0.237
## 8       sex1  ~~  SESscore  0.022 0.000     NA     NA    0.022    0.022
## 9       sex1  ~~     Zgcse  0.004 0.000     NA     NA    0.004    0.004
## 10      sex1  ~~    Zhqual -0.004 0.000     NA     NA   -0.004   -0.004
## 11  SESscore  ~~  SESscore  0.865 0.000     NA     NA    0.865    0.865
## 12  SESscore  ~~     Zgcse  0.397 0.000     NA     NA    0.397    0.397
## 13  SESscore  ~~    Zhqual  0.316 0.000     NA     NA    0.316    0.316
## 14     Zgcse  ~~     Zgcse  0.868 0.000     NA     NA    0.868    0.868
## 15     Zgcse  ~~    Zhqual  0.492 0.000     NA     NA    0.492    0.492
## 16    Zhqual  ~~    Zhqual  0.998 0.000     NA     NA    0.998    0.998
## 17 u1cbenf11 ~*~ u1cbenf11  1.000 0.000     NA     NA    1.000    1.000
## 18 u1cbenf11  ~1            0.000 0.000     NA     NA    0.000    0.000
## 19      sex1  ~1            0.385 0.000     NA     NA    0.385    0.385
## 20  SESscore  ~1            0.063 0.000     NA     NA    0.063    0.063
## 21     Zgcse  ~1            0.215 0.000     NA     NA    0.215    0.215
## 22    Zhqual  ~1            0.003 0.000     NA     NA    0.003    0.003
## 23 u1cbenf11  r2 u1cbenf11  0.106    NA     NA     NA       NA       NA
PE.model3.benf$est[PE.model3.benf$op == "r2"]
## [1] 0.1061686
(PE.model2.benf <- parameterEstimates(model2.benffit, rsquare = TRUE)) 
##          lhs  op       rhs    est    se      z pvalue ci.lower ci.upper
## 1  u1cbenf11   ~      sex1 -0.180 0.078 -2.299  0.022   -0.333   -0.027
## 2  u1cbenf11   ~  SESscore -0.136 0.043 -3.165  0.002   -0.220   -0.052
## 3  u1cbenf11   ~     Zgcse -0.234 0.041 -5.656  0.000   -0.315   -0.153
## 4  u1cbenf11   |        t1  1.633 0.046 35.662  0.000    1.544    1.723
## 5  u1cbenf11  ~~ u1cbenf11  1.000 0.000     NA     NA    1.000    1.000
## 6       sex1  ~~      sex1  0.236 0.000     NA     NA    0.236    0.236
## 7       sex1  ~~  SESscore  0.023 0.000     NA     NA    0.023    0.023
## 8       sex1  ~~     Zgcse  0.006 0.000     NA     NA    0.006    0.006
## 9   SESscore  ~~  SESscore  0.871 0.000     NA     NA    0.871    0.871
## 10  SESscore  ~~     Zgcse  0.410 0.000     NA     NA    0.410    0.410
## 11     Zgcse  ~~     Zgcse  0.891 0.000     NA     NA    0.891    0.891
## 12 u1cbenf11 ~*~ u1cbenf11  1.000 0.000     NA     NA    1.000    1.000
## 13 u1cbenf11  ~1            0.000 0.000     NA     NA    0.000    0.000
## 14      sex1  ~1            0.383 0.000     NA     NA    0.383    0.383
## 15  SESscore  ~1            0.056 0.000     NA     NA    0.056    0.056
## 16     Zgcse  ~1            0.201 0.000     NA     NA    0.201    0.201
## 17 u1cbenf11  r2 u1cbenf11  0.091    NA     NA     NA       NA       NA
PE.model2.benf$est[PE.model2.benf$op == "r2"]
## [1] 0.09107141
(PE.model1.benf <- parameterEstimates(model1.benffit, rsquare = TRUE)) 
##          lhs  op       rhs    est    se      z pvalue ci.lower ci.upper
## 1  u1cbenf11   ~      sex1 -0.173 0.077 -2.239  0.025   -0.325   -0.022
## 2  u1cbenf11   ~  SESscore -0.244 0.038 -6.359  0.000   -0.319   -0.169
## 3  u1cbenf11   |        t1  1.644 0.045 36.465  0.000    1.555    1.732
## 4  u1cbenf11  ~~ u1cbenf11  1.000 0.000     NA     NA    1.000    1.000
## 5       sex1  ~~      sex1  0.236 0.000     NA     NA    0.236    0.236
## 6       sex1  ~~  SESscore  0.023 0.000     NA     NA    0.023    0.023
## 7   SESscore  ~~  SESscore  0.871 0.000     NA     NA    0.871    0.871
## 8  u1cbenf11 ~*~ u1cbenf11  1.000 0.000     NA     NA    1.000    1.000
## 9  u1cbenf11  ~1            0.000 0.000     NA     NA    0.000    0.000
## 10      sex1  ~1            0.383 0.000     NA     NA    0.383    0.383
## 11  SESscore  ~1            0.056 0.000     NA     NA    0.056    0.056
## 12 u1cbenf11  r2 u1cbenf11  0.057    NA     NA     NA       NA       NA
PE.model1.benf$est[PE.model1.benf$op == "r2"]
## [1] 0.05743743
r2diff2.benf <- (PE.model2.benf$est[PE.model2.benf$op == "r2"] - PE.model1.benf$est[PE.model1.benf$op == "r2"])
print(r2diff2.benf)    #difference model1 vs 2, incremental explained variance by GCSE
## [1] 0.03363398
r2diff3.benf <- (PE.model3.benf$est[PE.model3.benf$op == "r2"] - PE.model2.benf$est[PE.model2.benf$op == "r2"])
print(r2diff3.benf)    #difference model2 vs 3, incremental explained variance by highest qualification
## [1] 0.01509724
model1.status_bin <- 'status_bin ~ sex1 + SESscore'
model1.status_binfit <- sem(model1.status_bin, data = df, ordered = c("status_bin"), missing = "listwise")
summary(model1.status_binfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 5 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         3
## 
##                                                   Used       Total
##   Number of observations                          3698        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   status_bin ~                                                          
##     sex1             -0.012    0.057   -0.203    0.839   -0.124    0.101
##     SESscore         -0.059    0.029   -2.026    0.043   -0.116   -0.002
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .status_bin        0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     status_bin|t1    -1.274    0.036  -35.695    0.000   -1.344   -1.204
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .status_bin        1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     status_bin        1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     status_bin        0.003
standardizedsolution(model1.status_binfit)
##           lhs  op        rhs est.std    se       z pvalue ci.lower ci.upper
## 1  status_bin   ~       sex1  -0.006 0.028  -0.203  0.839   -0.060    0.049
## 2  status_bin   ~   SESscore  -0.055 0.027  -2.032  0.042   -0.109   -0.002
## 3  status_bin   |         t1  -1.272 0.035 -35.924  0.000   -1.342   -1.203
## 4  status_bin  ~~ status_bin   0.997 0.003 329.135  0.000    0.991    1.003
## 5        sex1  ~~       sex1   1.000 0.000      NA     NA    1.000    1.000
## 6        sex1  ~~   SESscore   0.052 0.000      NA     NA    0.052    0.052
## 7    SESscore  ~~   SESscore   1.000 0.000      NA     NA    1.000    1.000
## 8  status_bin ~*~ status_bin   1.000 0.000      NA     NA    1.000    1.000
## 9  status_bin  ~1              0.000 0.000      NA     NA    0.000    0.000
## 10       sex1  ~1              0.789 0.000      NA     NA    0.789    0.789
## 11   SESscore  ~1              0.059 0.000      NA     NA    0.059    0.059
model2.status_bin <- 'status_bin ~ sex1 + SESscore + Zgcse'
model2.status_binfit <- sem(model2.status_bin, data = df, ordered = c("status_bin"), missing = "listwise")
summary(model2.status_binfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 10 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         4
## 
##                                                   Used       Total
##   Number of observations                          3698        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   status_bin ~                                                          
##     sex1             -0.011    0.057   -0.200    0.841   -0.124    0.101
##     SESscore         -0.064    0.034   -1.880    0.060   -0.131    0.003
##     Zgcse             0.011    0.033    0.319    0.750   -0.054    0.076
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .status_bin        0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     status_bin|t1    -1.272    0.036  -35.294    0.000   -1.343   -1.202
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .status_bin        1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     status_bin        1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     status_bin        0.003
standardizedsolution(model2.status_binfit)
##           lhs  op        rhs est.std    se       z pvalue ci.lower ci.upper
## 1  status_bin   ~       sex1  -0.006 0.028  -0.200  0.841   -0.060    0.049
## 2  status_bin   ~   SESscore  -0.060 0.032  -1.885  0.059   -0.122    0.002
## 3  status_bin   ~      Zgcse   0.010 0.031   0.319  0.750   -0.051    0.071
## 4  status_bin   |         t1  -1.270 0.036 -35.453  0.000   -1.340   -1.200
## 5  status_bin  ~~ status_bin   0.997 0.003 319.453  0.000    0.991    1.003
## 6        sex1  ~~       sex1   1.000 0.000      NA     NA    1.000    1.000
## 7        sex1  ~~   SESscore   0.052 0.000      NA     NA    0.052    0.052
## 8        sex1  ~~      Zgcse   0.014 0.000      NA     NA    0.014    0.014
## 9    SESscore  ~~   SESscore   1.000 0.000      NA     NA    1.000    1.000
## 10   SESscore  ~~      Zgcse   0.467 0.000      NA     NA    0.467    0.467
## 11      Zgcse  ~~      Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 12 status_bin ~*~ status_bin   1.000 0.000      NA     NA    1.000    1.000
## 13 status_bin  ~1              0.000 0.000      NA     NA    0.000    0.000
## 14       sex1  ~1              0.789 0.000      NA     NA    0.789    0.789
## 15   SESscore  ~1              0.059 0.000      NA     NA    0.059    0.059
## 16      Zgcse  ~1              0.216 0.000      NA     NA    0.216    0.216
model3.status_bin <- 'status_bin ~ sex1 + SESscore + Zgcse + Zhqual'
model3.status_binfit <- sem(model3.status_bin, data = df, ordered = c("status_bin"), missing = "listwise")
summary(model3.status_binfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 12 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         5
## 
##                                                   Used       Total
##   Number of observations                          3635        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   status_bin ~                                                          
##     sex1             -0.008    0.058   -0.142    0.887   -0.122    0.105
##     SESscore         -0.069    0.035   -1.984    0.047   -0.138   -0.001
##     Zgcse            -0.039    0.037   -1.051    0.293   -0.112    0.034
##     Zhqual            0.100    0.033    3.030    0.002    0.035    0.165
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .status_bin        0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     status_bin|t1    -1.284    0.037  -34.269    0.000   -1.357   -1.210
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .status_bin        1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     status_bin        1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     status_bin        0.009
standardizedsolution(model3.status_binfit)
##           lhs  op        rhs est.std    se       z pvalue ci.lower ci.upper
## 1  status_bin   ~       sex1  -0.004 0.028  -0.142  0.887   -0.059    0.051
## 2  status_bin   ~   SESscore  -0.064 0.032  -1.990  0.047   -0.128   -0.001
## 3  status_bin   ~      Zgcse  -0.036 0.034  -1.051  0.293   -0.104    0.031
## 4  status_bin   ~     Zhqual   0.099 0.033   3.051  0.002    0.036    0.163
## 5  status_bin   |         t1  -1.278 0.037 -34.896  0.000   -1.349   -1.206
## 6  status_bin  ~~ status_bin   0.991 0.005 184.027  0.000    0.980    1.001
## 7        sex1  ~~       sex1   1.000 0.000      NA     NA    1.000    1.000
## 8        sex1  ~~   SESscore   0.051 0.000      NA     NA    0.051    0.051
## 9        sex1  ~~      Zgcse   0.011 0.000      NA     NA    0.011    0.011
## 10       sex1  ~~     Zhqual  -0.006 0.000      NA     NA   -0.006   -0.006
## 11   SESscore  ~~   SESscore   1.000 0.000      NA     NA    1.000    1.000
## 12   SESscore  ~~      Zgcse   0.459 0.000      NA     NA    0.459    0.459
## 13   SESscore  ~~     Zhqual   0.340 0.000      NA     NA    0.340    0.340
## 14      Zgcse  ~~      Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 15      Zgcse  ~~     Zhqual   0.528 0.000      NA     NA    0.528    0.528
## 16     Zhqual  ~~     Zhqual   1.000 0.000      NA     NA    1.000    1.000
## 17 status_bin ~*~ status_bin   1.000 0.000      NA     NA    1.000    1.000
## 18 status_bin  ~1              0.000 0.000      NA     NA    0.000    0.000
## 19       sex1  ~1              0.792 0.000      NA     NA    0.792    0.792
## 20   SESscore  ~1              0.066 0.000      NA     NA    0.066    0.066
## 21      Zgcse  ~1              0.233 0.000      NA     NA    0.233    0.233
## 22     Zhqual  ~1              0.005 0.000      NA     NA    0.005    0.005
#get change in R2 for model1 vs. model2 vs. model3
(PE.model3.status_bin <- parameterEstimates(model3.status_binfit, rsquare = TRUE)) 
##           lhs  op        rhs    est    se       z pvalue ci.lower ci.upper
## 1  status_bin   ~       sex1 -0.008 0.058  -0.142  0.887   -0.122    0.105
## 2  status_bin   ~   SESscore -0.069 0.035  -1.984  0.047   -0.138   -0.001
## 3  status_bin   ~      Zgcse -0.039 0.037  -1.051  0.293   -0.112    0.034
## 4  status_bin   ~     Zhqual  0.100 0.033   3.030  0.002    0.035    0.165
## 5  status_bin   |         t1 -1.284 0.037 -34.269  0.000   -1.357   -1.210
## 6  status_bin  ~~ status_bin  1.000 0.000      NA     NA    1.000    1.000
## 7        sex1  ~~       sex1  0.237 0.000      NA     NA    0.237    0.237
## 8        sex1  ~~   SESscore  0.023 0.000      NA     NA    0.023    0.023
## 9        sex1  ~~      Zgcse  0.005 0.000      NA     NA    0.005    0.005
## 10       sex1  ~~     Zhqual -0.003 0.000      NA     NA   -0.003   -0.003
## 11   SESscore  ~~   SESscore  0.868 0.000      NA     NA    0.868    0.868
## 12   SESscore  ~~      Zgcse  0.398 0.000      NA     NA    0.398    0.398
## 13   SESscore  ~~     Zhqual  0.316 0.000      NA     NA    0.316    0.316
## 14      Zgcse  ~~      Zgcse  0.865 0.000      NA     NA    0.865    0.865
## 15      Zgcse  ~~     Zhqual  0.490 0.000      NA     NA    0.490    0.490
## 16     Zhqual  ~~     Zhqual  0.997 0.000      NA     NA    0.997    0.997
## 17 status_bin ~*~ status_bin  1.000 0.000      NA     NA    1.000    1.000
## 18 status_bin  ~1             0.000 0.000      NA     NA    0.000    0.000
## 19       sex1  ~1             0.385 0.000      NA     NA    0.385    0.385
## 20   SESscore  ~1             0.062 0.000      NA     NA    0.062    0.062
## 21      Zgcse  ~1             0.217 0.000      NA     NA    0.217    0.217
## 22     Zhqual  ~1             0.005 0.000      NA     NA    0.005    0.005
## 23 status_bin  r2 status_bin  0.009    NA      NA     NA       NA       NA
PE.model3.status_bin$est[PE.model3.status_bin$op == "r2"]
## [1] 0.009364356
(PE.model2.status_bin <- parameterEstimates(model2.status_binfit, rsquare = TRUE)) 
##           lhs  op        rhs    est    se       z pvalue ci.lower ci.upper
## 1  status_bin   ~       sex1 -0.011 0.057  -0.200  0.841   -0.124    0.101
## 2  status_bin   ~   SESscore -0.064 0.034  -1.880  0.060   -0.131    0.003
## 3  status_bin   ~      Zgcse  0.011 0.033   0.319  0.750   -0.054    0.076
## 4  status_bin   |         t1 -1.272 0.036 -35.294  0.000   -1.343   -1.202
## 5  status_bin  ~~ status_bin  1.000 0.000      NA     NA    1.000    1.000
## 6        sex1  ~~       sex1  0.237 0.000      NA     NA    0.237    0.237
## 7        sex1  ~~   SESscore  0.024 0.000      NA     NA    0.024    0.024
## 8        sex1  ~~      Zgcse  0.007 0.000      NA     NA    0.007    0.007
## 9    SESscore  ~~   SESscore  0.874 0.000      NA     NA    0.874    0.874
## 10   SESscore  ~~      Zgcse  0.411 0.000      NA     NA    0.411    0.411
## 11      Zgcse  ~~      Zgcse  0.888 0.000      NA     NA    0.888    0.888
## 12 status_bin ~*~ status_bin  1.000 0.000      NA     NA    1.000    1.000
## 13 status_bin  ~1             0.000 0.000      NA     NA    0.000    0.000
## 14       sex1  ~1             0.384 0.000      NA     NA    0.384    0.384
## 15   SESscore  ~1             0.055 0.000      NA     NA    0.055    0.055
## 16      Zgcse  ~1             0.203 0.000      NA     NA    0.203    0.203
## 17 status_bin  r2 status_bin  0.003    NA      NA     NA       NA       NA
PE.model2.status_bin$est[PE.model2.status_bin$op == "r2"]
## [1] 0.003209703
(PE.model1.status_bin <- parameterEstimates(model1.status_binfit, rsquare = TRUE)) 
##           lhs  op        rhs    est    se       z pvalue ci.lower ci.upper
## 1  status_bin   ~       sex1 -0.012 0.057  -0.203  0.839   -0.124    0.101
## 2  status_bin   ~   SESscore -0.059 0.029  -2.026  0.043   -0.116   -0.002
## 3  status_bin   |         t1 -1.274 0.036 -35.695  0.000   -1.344   -1.204
## 4  status_bin  ~~ status_bin  1.000 0.000      NA     NA    1.000    1.000
## 5        sex1  ~~       sex1  0.237 0.000      NA     NA    0.237    0.237
## 6        sex1  ~~   SESscore  0.024 0.000      NA     NA    0.024    0.024
## 7    SESscore  ~~   SESscore  0.874 0.000      NA     NA    0.874    0.874
## 8  status_bin ~*~ status_bin  1.000 0.000      NA     NA    1.000    1.000
## 9  status_bin  ~1             0.000 0.000      NA     NA    0.000    0.000
## 10       sex1  ~1             0.384 0.000      NA     NA    0.384    0.384
## 11   SESscore  ~1             0.055 0.000      NA     NA    0.055    0.055
## 12 status_bin  r2 status_bin  0.003    NA      NA     NA       NA       NA
PE.model1.status_bin$est[PE.model1.status_bin$op == "r2"]
## [1] 0.003117604
r2diff2.status_bin <- (PE.model2.status_bin$est[PE.model2.status_bin$op == "r2"] - PE.model1.status_bin$est[PE.model1.status_bin$op == "r2"])
print(r2diff2.status_bin)    #difference model1 vs 2, incremental explained variance by GCSE
## [1] 9.209957e-05
r2diff3.status_bin <- (PE.model3.status_bin$est[PE.model3.status_bin$op == "r2"] - PE.model2.status_bin$est[PE.model2.status_bin$op == "r2"])
print(r2diff3.status_bin)    #difference model2 vs 3, incremental explained variance by highest qualification
## [1] 0.006154653

“Multinomial” regression for nominal version of employment status (w/o moderation)

employment status variable is nominal (according to coding specified in prereg): 0=unemployed; 1=working; 2=studying or apprenticeship; 3=full-time parents; 4=gap year/travelling

true multinomial regression is not available in lavaan and the status variable can’t be included in SEM model in the logistic way with the ordered command, because it is neither binary nor are the categories ordered –> needs to be dummy coded into 4 variables before entering into 4 separate logistic regression analyses

#dummy code status variable
#specify status as factor, create  4 dummy variables for originally 5 categories (unemployed is always set as the reference category), and bind new variables to df
df$status1 = as.factor(df$status1)

st_working <- ifelse(df$status1 == '1', 1, 0)
st_studying <- ifelse(df$status1 == '2', 1, 0)
st_parent <- ifelse(df$status1 == '3', 1, 0)
st_gapyear <- ifelse(df$status1 == '4', 1, 0)

df_dummy = cbind(df, st_working, st_studying, st_parent, st_gapyear)

write.csv(df_dummy, '/Users/cgb538/Library/CloudStorage/GoogleDrive-alexandra.starr@york.ac.uk/My Drive/projects and papers/DevPsych_prediction grades adulthood/data/grades_adulth_prepared_random1_dummy.csv', row.names = F, na = 'NA')
##employment status: working vs. unemployed
model1.st_working <- 'st_working ~ sex1 + SESscore'
model1.st_workingfit <- sem(model1.st_working, data = df_dummy, ordered = c("st_working"), missing = "listwise")
summary(model1.st_workingfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 7 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         3
## 
##                                                   Used       Total
##   Number of observations                          3698        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_working ~                                                          
##     sex1             -0.105    0.043   -2.443    0.015   -0.190   -0.021
##     SESscore         -0.305    0.023  -13.412    0.000   -0.350   -0.260
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_working        0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_working|t1    -0.094    0.027   -3.512    0.000   -0.146   -0.041
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_working        1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_working        1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_working        0.079
standardizedsolution(model1.st_workingfit)
##           lhs  op        rhs est.std    se       z pvalue ci.lower ci.upper
## 1  st_working   ~       sex1  -0.049 0.020  -2.449  0.014   -0.088   -0.010
## 2  st_working   ~   SESscore  -0.274 0.019 -14.498  0.000   -0.311   -0.237
## 3  st_working   |         t1  -0.090 0.025  -3.523  0.000   -0.140   -0.040
## 4  st_working  ~~ st_working   0.921 0.011  87.040  0.000    0.901    0.942
## 5        sex1  ~~       sex1   1.000 0.000      NA     NA    1.000    1.000
## 6        sex1  ~~   SESscore   0.052 0.000      NA     NA    0.052    0.052
## 7    SESscore  ~~   SESscore   1.000 0.000      NA     NA    1.000    1.000
## 8  st_working ~*~ st_working   1.000 0.000      NA     NA    1.000    1.000
## 9  st_working  ~1              0.000 0.000      NA     NA    0.000    0.000
## 10       sex1  ~1              0.789 0.000      NA     NA    0.789    0.789
## 11   SESscore  ~1              0.059 0.000      NA     NA    0.059    0.059
model2.st_working <- 'st_working ~ sex1 + SESscore + Zgcse'
model2.st_workingfit <- sem(model2.st_working, data = df_dummy, ordered = c("st_working"), missing = "listwise")
summary(model2.st_workingfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 10 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         4
## 
##                                                   Used       Total
##   Number of observations                          3698        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_working ~                                                          
##     sex1             -0.112    0.043   -2.567    0.010   -0.197   -0.026
##     SESscore         -0.180    0.025   -7.062    0.000   -0.230   -0.130
##     Zgcse            -0.277    0.025  -11.290    0.000   -0.326   -0.229
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_working        0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_working|t1    -0.148    0.027   -5.407    0.000   -0.201   -0.094
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_working        1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_working        1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_working        0.124
standardizedsolution(model2.st_workingfit)
##           lhs  op        rhs est.std    se       z pvalue ci.lower ci.upper
## 1  st_working   ~       sex1  -0.051 0.020  -2.573   0.01   -0.089   -0.012
## 2  st_working   ~   SESscore  -0.157 0.022  -7.204   0.00   -0.200   -0.115
## 3  st_working   ~      Zgcse  -0.245 0.021 -11.816   0.00   -0.285   -0.204
## 4  st_working   |         t1  -0.138 0.025  -5.447   0.00   -0.188   -0.088
## 5  st_working  ~~ st_working   0.876 0.012  72.464   0.00    0.852    0.899
## 6        sex1  ~~       sex1   1.000 0.000      NA     NA    1.000    1.000
## 7        sex1  ~~   SESscore   0.052 0.000      NA     NA    0.052    0.052
## 8        sex1  ~~      Zgcse   0.014 0.000      NA     NA    0.014    0.014
## 9    SESscore  ~~   SESscore   1.000 0.000      NA     NA    1.000    1.000
## 10   SESscore  ~~      Zgcse   0.467 0.000      NA     NA    0.467    0.467
## 11      Zgcse  ~~      Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 12 st_working ~*~ st_working   1.000 0.000      NA     NA    1.000    1.000
## 13 st_working  ~1              0.000 0.000      NA     NA    0.000    0.000
## 14       sex1  ~1              0.789 0.000      NA     NA    0.789    0.789
## 15   SESscore  ~1              0.059 0.000      NA     NA    0.059    0.059
## 16      Zgcse  ~1              0.216 0.000      NA     NA    0.216    0.216
model3.st_working <- 'st_working ~ sex1 + SESscore + Zgcse + Zhqual'
model3.st_workingfit <- sem(model3.st_working, data = df_dummy, ordered = c("st_working"), missing = "listwise")
summary(model3.st_workingfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 12 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         5
## 
##                                                   Used       Total
##   Number of observations                          3635        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_working ~                                                          
##     sex1             -0.122    0.045   -2.720    0.007   -0.209   -0.034
##     SESscore         -0.141    0.026   -5.392    0.000   -0.192   -0.090
##     Zgcse            -0.112    0.029   -3.923    0.000   -0.168   -0.056
##     Zhqual           -0.361    0.025  -14.477    0.000   -0.410   -0.312
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_working        0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_working|t1    -0.123    0.028   -4.413    0.000   -0.178   -0.069
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_working        1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_working        1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_working        0.198
standardizedsolution(model3.st_workingfit)
##           lhs  op        rhs est.std    se       z pvalue ci.lower ci.upper
## 1  st_working   ~       sex1  -0.053 0.019  -2.726  0.006   -0.091   -0.015
## 2  st_working   ~   SESscore  -0.117 0.022  -5.457  0.000   -0.160   -0.075
## 3  st_working   ~      Zgcse  -0.093 0.024  -3.935  0.000   -0.140   -0.047
## 4  st_working   ~     Zhqual  -0.323 0.021 -15.468  0.000   -0.364   -0.282
## 5  st_working   |         t1  -0.111 0.025  -4.422  0.000   -0.160   -0.062
## 6  st_working  ~~ st_working   0.802 0.013  61.695  0.000    0.776    0.827
## 7        sex1  ~~       sex1   1.000 0.000      NA     NA    1.000    1.000
## 8        sex1  ~~   SESscore   0.051 0.000      NA     NA    0.051    0.051
## 9        sex1  ~~      Zgcse   0.011 0.000      NA     NA    0.011    0.011
## 10       sex1  ~~     Zhqual  -0.006 0.000      NA     NA   -0.006   -0.006
## 11   SESscore  ~~   SESscore   1.000 0.000      NA     NA    1.000    1.000
## 12   SESscore  ~~      Zgcse   0.459 0.000      NA     NA    0.459    0.459
## 13   SESscore  ~~     Zhqual   0.340 0.000      NA     NA    0.340    0.340
## 14      Zgcse  ~~      Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 15      Zgcse  ~~     Zhqual   0.528 0.000      NA     NA    0.528    0.528
## 16     Zhqual  ~~     Zhqual   1.000 0.000      NA     NA    1.000    1.000
## 17 st_working ~*~ st_working   1.000 0.000      NA     NA    1.000    1.000
## 18 st_working  ~1              0.000 0.000      NA     NA    0.000    0.000
## 19       sex1  ~1              0.792 0.000      NA     NA    0.792    0.792
## 20   SESscore  ~1              0.066 0.000      NA     NA    0.066    0.066
## 21      Zgcse  ~1              0.233 0.000      NA     NA    0.233    0.233
## 22     Zhqual  ~1              0.005 0.000      NA     NA    0.005    0.005
#get change in R2 for model1 vs. model2 vs. model3
(PE.model3.st_working <- parameterEstimates(model3.st_workingfit, rsquare = TRUE)) 
##           lhs  op        rhs    est    se       z pvalue ci.lower ci.upper
## 1  st_working   ~       sex1 -0.122 0.045  -2.720  0.007   -0.209   -0.034
## 2  st_working   ~   SESscore -0.141 0.026  -5.392  0.000   -0.192   -0.090
## 3  st_working   ~      Zgcse -0.112 0.029  -3.923  0.000   -0.168   -0.056
## 4  st_working   ~     Zhqual -0.361 0.025 -14.477  0.000   -0.410   -0.312
## 5  st_working   |         t1 -0.123 0.028  -4.413  0.000   -0.178   -0.069
## 6  st_working  ~~ st_working  1.000 0.000      NA     NA    1.000    1.000
## 7        sex1  ~~       sex1  0.237 0.000      NA     NA    0.237    0.237
## 8        sex1  ~~   SESscore  0.023 0.000      NA     NA    0.023    0.023
## 9        sex1  ~~      Zgcse  0.005 0.000      NA     NA    0.005    0.005
## 10       sex1  ~~     Zhqual -0.003 0.000      NA     NA   -0.003   -0.003
## 11   SESscore  ~~   SESscore  0.868 0.000      NA     NA    0.868    0.868
## 12   SESscore  ~~      Zgcse  0.398 0.000      NA     NA    0.398    0.398
## 13   SESscore  ~~     Zhqual  0.316 0.000      NA     NA    0.316    0.316
## 14      Zgcse  ~~      Zgcse  0.865 0.000      NA     NA    0.865    0.865
## 15      Zgcse  ~~     Zhqual  0.490 0.000      NA     NA    0.490    0.490
## 16     Zhqual  ~~     Zhqual  0.997 0.000      NA     NA    0.997    0.997
## 17 st_working ~*~ st_working  1.000 0.000      NA     NA    1.000    1.000
## 18 st_working  ~1             0.000 0.000      NA     NA    0.000    0.000
## 19       sex1  ~1             0.385 0.000      NA     NA    0.385    0.385
## 20   SESscore  ~1             0.062 0.000      NA     NA    0.062    0.062
## 21      Zgcse  ~1             0.217 0.000      NA     NA    0.217    0.217
## 22     Zhqual  ~1             0.005 0.000      NA     NA    0.005    0.005
## 23 st_working  r2 st_working  0.198    NA      NA     NA       NA       NA
PE.model3.st_working$est[PE.model3.st_working$op == "r2"]
## [1] 0.1980484
(PE.model2.st_working <- parameterEstimates(model2.st_workingfit, rsquare = TRUE)) 
##           lhs  op        rhs    est    se       z pvalue ci.lower ci.upper
## 1  st_working   ~       sex1 -0.112 0.043  -2.567   0.01   -0.197   -0.026
## 2  st_working   ~   SESscore -0.180 0.025  -7.062   0.00   -0.230   -0.130
## 3  st_working   ~      Zgcse -0.277 0.025 -11.290   0.00   -0.326   -0.229
## 4  st_working   |         t1 -0.148 0.027  -5.407   0.00   -0.201   -0.094
## 5  st_working  ~~ st_working  1.000 0.000      NA     NA    1.000    1.000
## 6        sex1  ~~       sex1  0.237 0.000      NA     NA    0.237    0.237
## 7        sex1  ~~   SESscore  0.024 0.000      NA     NA    0.024    0.024
## 8        sex1  ~~      Zgcse  0.007 0.000      NA     NA    0.007    0.007
## 9    SESscore  ~~   SESscore  0.874 0.000      NA     NA    0.874    0.874
## 10   SESscore  ~~      Zgcse  0.411 0.000      NA     NA    0.411    0.411
## 11      Zgcse  ~~      Zgcse  0.888 0.000      NA     NA    0.888    0.888
## 12 st_working ~*~ st_working  1.000 0.000      NA     NA    1.000    1.000
## 13 st_working  ~1             0.000 0.000      NA     NA    0.000    0.000
## 14       sex1  ~1             0.384 0.000      NA     NA    0.384    0.384
## 15   SESscore  ~1             0.055 0.000      NA     NA    0.055    0.055
## 16      Zgcse  ~1             0.203 0.000      NA     NA    0.203    0.203
## 17 st_working  r2 st_working  0.124    NA      NA     NA       NA       NA
PE.model2.st_working$est[PE.model2.st_working$op == "r2"]
## [1] 0.1243634
(PE.model1.st_working <- parameterEstimates(model1.st_workingfit, rsquare = TRUE)) 
##           lhs  op        rhs    est    se       z pvalue ci.lower ci.upper
## 1  st_working   ~       sex1 -0.105 0.043  -2.443  0.015   -0.190   -0.021
## 2  st_working   ~   SESscore -0.305 0.023 -13.412  0.000   -0.350   -0.260
## 3  st_working   |         t1 -0.094 0.027  -3.512  0.000   -0.146   -0.041
## 4  st_working  ~~ st_working  1.000 0.000      NA     NA    1.000    1.000
## 5        sex1  ~~       sex1  0.237 0.000      NA     NA    0.237    0.237
## 6        sex1  ~~   SESscore  0.024 0.000      NA     NA    0.024    0.024
## 7    SESscore  ~~   SESscore  0.874 0.000      NA     NA    0.874    0.874
## 8  st_working ~*~ st_working  1.000 0.000      NA     NA    1.000    1.000
## 9  st_working  ~1             0.000 0.000      NA     NA    0.000    0.000
## 10       sex1  ~1             0.384 0.000      NA     NA    0.384    0.384
## 11   SESscore  ~1             0.055 0.000      NA     NA    0.055    0.055
## 12 st_working  r2 st_working  0.079    NA      NA     NA       NA       NA
PE.model1.st_working$est[PE.model1.st_working$op == "r2"]
## [1] 0.07868862
r2diff2.st_working <- (PE.model2.st_working$est[PE.model2.st_working$op == "r2"] - PE.model1.st_working$est[PE.model1.st_working$op == "r2"])
print(r2diff2.st_working)    #difference model1 vs 2, incremental explained variance by GCSE
## [1] 0.04567473
r2diff3.st_working <- (PE.model3.st_working$est[PE.model3.st_working$op == "r2"] - PE.model2.st_working$est[PE.model2.st_working$op == "r2"])
print(r2diff3.st_working)    #difference model2 vs 3, incremental explained variance by highest qualification
## [1] 0.07368505
##employment status: studying/apprenticeship vs. unemployed
model1.st_studying <- 'st_studying ~ sex1 + SESscore'
model1.st_studyingfit <- sem(model1.st_studying, data = df_dummy, ordered = c("st_studying"), missing = "listwise")
summary(model1.st_studyingfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 7 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         3
## 
##                                                   Used       Total
##   Number of observations                          3698        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_studying ~                                                         
##     sex1              0.103    0.044    2.352    0.019    0.017    0.188
##     SESscore          0.290    0.023   12.542    0.000    0.245    0.336
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_studying       0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_studying|t1    0.365    0.027   13.373    0.000    0.311    0.418
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_studying       1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_studying       1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_studying       0.072
standardizedsolution(model1.st_studyingfit)
##            lhs  op         rhs est.std    se      z pvalue ci.lower ci.upper
## 1  st_studying   ~        sex1   0.048 0.020  2.358  0.018    0.008    0.088
## 2  st_studying   ~    SESscore   0.261 0.019 13.462  0.000    0.223    0.299
## 3  st_studying   |          t1   0.351 0.026 13.544  0.000    0.300    0.402
## 4  st_studying  ~~ st_studying   0.928 0.010 89.275  0.000    0.908    0.948
## 5         sex1  ~~        sex1   1.000 0.000     NA     NA    1.000    1.000
## 6         sex1  ~~    SESscore   0.052 0.000     NA     NA    0.052    0.052
## 7     SESscore  ~~    SESscore   1.000 0.000     NA     NA    1.000    1.000
## 8  st_studying ~*~ st_studying   1.000 0.000     NA     NA    1.000    1.000
## 9  st_studying  ~1               0.000 0.000     NA     NA    0.000    0.000
## 10        sex1  ~1               0.789 0.000     NA     NA    0.789    0.789
## 11    SESscore  ~1               0.059 0.000     NA     NA    0.059    0.059
model2.st_studying <- 'st_studying ~ sex1 + SESscore + Zgcse'
model2.st_studyingfit <- sem(model2.st_studying, data = df_dummy, ordered = c("st_studying"), missing = "listwise")
summary(model2.st_studyingfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 10 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         4
## 
##                                                   Used       Total
##   Number of observations                          3698        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_studying ~                                                         
##     sex1              0.111    0.044    2.530    0.011    0.025    0.198
##     SESscore          0.156    0.026    6.073    0.000    0.106    0.206
##     Zgcse             0.304    0.026   11.866    0.000    0.254    0.354
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_studying       0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_studying|t1    0.434    0.028   15.255    0.000    0.379    0.490
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_studying       1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_studying       1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_studying       0.128
standardizedsolution(model2.st_studyingfit)
##            lhs  op         rhs est.std    se      z pvalue ci.lower ci.upper
## 1  st_studying   ~        sex1   0.051 0.020  2.537  0.011    0.012    0.090
## 2  st_studying   ~    SESscore   0.136 0.022  6.166  0.000    0.093    0.180
## 3  st_studying   ~       Zgcse   0.268 0.021 12.577  0.000    0.226    0.309
## 4  st_studying   |          t1   0.406 0.026 15.704  0.000    0.355    0.456
## 5  st_studying  ~~ st_studying   0.872 0.013 68.011  0.000    0.847    0.897
## 6         sex1  ~~        sex1   1.000 0.000     NA     NA    1.000    1.000
## 7         sex1  ~~    SESscore   0.052 0.000     NA     NA    0.052    0.052
## 8         sex1  ~~       Zgcse   0.014 0.000     NA     NA    0.014    0.014
## 9     SESscore  ~~    SESscore   1.000 0.000     NA     NA    1.000    1.000
## 10    SESscore  ~~       Zgcse   0.467 0.000     NA     NA    0.467    0.467
## 11       Zgcse  ~~       Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 12 st_studying ~*~ st_studying   1.000 0.000     NA     NA    1.000    1.000
## 13 st_studying  ~1               0.000 0.000     NA     NA    0.000    0.000
## 14        sex1  ~1               0.789 0.000     NA     NA    0.789    0.789
## 15    SESscore  ~1               0.059 0.000     NA     NA    0.059    0.059
## 16       Zgcse  ~1               0.216 0.000     NA     NA    0.216    0.216
model3.st_studying <- 'st_studying ~ sex1 + SESscore + Zgcse + Zhqual'
model3.st_studyingfit <- sem(model3.st_studying, data = df_dummy, ordered = c("st_studying"), missing = "listwise")
summary(model3.st_studyingfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 13 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         5
## 
##                                                   Used       Total
##   Number of observations                          3635        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_studying ~                                                         
##     sex1              0.137    0.046    2.983    0.003    0.047    0.227
##     SESscore          0.111    0.027    4.177    0.000    0.059    0.163
##     Zgcse             0.101    0.030    3.416    0.001    0.043    0.159
##     Zhqual            0.528    0.028   18.883    0.000    0.473    0.582
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_studying       0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_studying|t1    0.454    0.030   15.102    0.000    0.395    0.513
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_studying       1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_studying       1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_studying       0.286
standardizedsolution(model3.st_studyingfit)
##            lhs  op         rhs est.std    se      z pvalue ci.lower ci.upper
## 1  st_studying   ~        sex1   0.056 0.019  3.000  0.003    0.020    0.093
## 2  st_studying   ~    SESscore   0.087 0.021  4.207  0.000    0.047    0.128
## 3  st_studying   ~       Zgcse   0.079 0.023  3.421  0.001    0.034    0.125
## 4  st_studying   ~      Zhqual   0.445 0.020 21.901  0.000    0.405    0.485
## 5  st_studying   |          t1   0.384 0.025 15.518  0.000    0.336    0.433
## 6  st_studying  ~~ st_studying   0.714 0.015 46.792  0.000    0.684    0.744
## 7         sex1  ~~        sex1   1.000 0.000     NA     NA    1.000    1.000
## 8         sex1  ~~    SESscore   0.051 0.000     NA     NA    0.051    0.051
## 9         sex1  ~~       Zgcse   0.011 0.000     NA     NA    0.011    0.011
## 10        sex1  ~~      Zhqual  -0.006 0.000     NA     NA   -0.006   -0.006
## 11    SESscore  ~~    SESscore   1.000 0.000     NA     NA    1.000    1.000
## 12    SESscore  ~~       Zgcse   0.459 0.000     NA     NA    0.459    0.459
## 13    SESscore  ~~      Zhqual   0.340 0.000     NA     NA    0.340    0.340
## 14       Zgcse  ~~       Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 15       Zgcse  ~~      Zhqual   0.528 0.000     NA     NA    0.528    0.528
## 16      Zhqual  ~~      Zhqual   1.000 0.000     NA     NA    1.000    1.000
## 17 st_studying ~*~ st_studying   1.000 0.000     NA     NA    1.000    1.000
## 18 st_studying  ~1               0.000 0.000     NA     NA    0.000    0.000
## 19        sex1  ~1               0.792 0.000     NA     NA    0.792    0.792
## 20    SESscore  ~1               0.066 0.000     NA     NA    0.066    0.066
## 21       Zgcse  ~1               0.233 0.000     NA     NA    0.233    0.233
## 22      Zhqual  ~1               0.005 0.000     NA     NA    0.005    0.005
#get change in R2 for model1 vs. model2 vs. model3
(PE.model3.st_studying <- parameterEstimates(model3.st_studyingfit, rsquare = TRUE)) 
##            lhs  op         rhs    est    se      z pvalue ci.lower ci.upper
## 1  st_studying   ~        sex1  0.137 0.046  2.983  0.003    0.047    0.227
## 2  st_studying   ~    SESscore  0.111 0.027  4.177  0.000    0.059    0.163
## 3  st_studying   ~       Zgcse  0.101 0.030  3.416  0.001    0.043    0.159
## 4  st_studying   ~      Zhqual  0.528 0.028 18.883  0.000    0.473    0.582
## 5  st_studying   |          t1  0.454 0.030 15.102  0.000    0.395    0.513
## 6  st_studying  ~~ st_studying  1.000 0.000     NA     NA    1.000    1.000
## 7         sex1  ~~        sex1  0.237 0.000     NA     NA    0.237    0.237
## 8         sex1  ~~    SESscore  0.023 0.000     NA     NA    0.023    0.023
## 9         sex1  ~~       Zgcse  0.005 0.000     NA     NA    0.005    0.005
## 10        sex1  ~~      Zhqual -0.003 0.000     NA     NA   -0.003   -0.003
## 11    SESscore  ~~    SESscore  0.868 0.000     NA     NA    0.868    0.868
## 12    SESscore  ~~       Zgcse  0.398 0.000     NA     NA    0.398    0.398
## 13    SESscore  ~~      Zhqual  0.316 0.000     NA     NA    0.316    0.316
## 14       Zgcse  ~~       Zgcse  0.865 0.000     NA     NA    0.865    0.865
## 15       Zgcse  ~~      Zhqual  0.490 0.000     NA     NA    0.490    0.490
## 16      Zhqual  ~~      Zhqual  0.997 0.000     NA     NA    0.997    0.997
## 17 st_studying ~*~ st_studying  1.000 0.000     NA     NA    1.000    1.000
## 18 st_studying  ~1              0.000 0.000     NA     NA    0.000    0.000
## 19        sex1  ~1              0.385 0.000     NA     NA    0.385    0.385
## 20    SESscore  ~1              0.062 0.000     NA     NA    0.062    0.062
## 21       Zgcse  ~1              0.217 0.000     NA     NA    0.217    0.217
## 22      Zhqual  ~1              0.005 0.000     NA     NA    0.005    0.005
## 23 st_studying  r2 st_studying  0.286    NA     NA     NA       NA       NA
PE.model3.st_studying$est[PE.model3.st_studying$op == "r2"]
## [1] 0.2856984
(PE.model2.st_studying <- parameterEstimates(model2.st_studyingfit, rsquare = TRUE)) 
##            lhs  op         rhs   est    se      z pvalue ci.lower ci.upper
## 1  st_studying   ~        sex1 0.111 0.044  2.530  0.011    0.025    0.198
## 2  st_studying   ~    SESscore 0.156 0.026  6.073  0.000    0.106    0.206
## 3  st_studying   ~       Zgcse 0.304 0.026 11.866  0.000    0.254    0.354
## 4  st_studying   |          t1 0.434 0.028 15.255  0.000    0.379    0.490
## 5  st_studying  ~~ st_studying 1.000 0.000     NA     NA    1.000    1.000
## 6         sex1  ~~        sex1 0.237 0.000     NA     NA    0.237    0.237
## 7         sex1  ~~    SESscore 0.024 0.000     NA     NA    0.024    0.024
## 8         sex1  ~~       Zgcse 0.007 0.000     NA     NA    0.007    0.007
## 9     SESscore  ~~    SESscore 0.874 0.000     NA     NA    0.874    0.874
## 10    SESscore  ~~       Zgcse 0.411 0.000     NA     NA    0.411    0.411
## 11       Zgcse  ~~       Zgcse 0.888 0.000     NA     NA    0.888    0.888
## 12 st_studying ~*~ st_studying 1.000 0.000     NA     NA    1.000    1.000
## 13 st_studying  ~1             0.000 0.000     NA     NA    0.000    0.000
## 14        sex1  ~1             0.384 0.000     NA     NA    0.384    0.384
## 15    SESscore  ~1             0.055 0.000     NA     NA    0.055    0.055
## 16       Zgcse  ~1             0.203 0.000     NA     NA    0.203    0.203
## 17 st_studying  r2 st_studying 0.128    NA     NA     NA       NA       NA
PE.model2.st_studying$est[PE.model2.st_studying$op == "r2"]
## [1] 0.1278711
(PE.model1.st_studying <- parameterEstimates(model1.st_studyingfit, rsquare = TRUE)) 
##            lhs  op         rhs   est    se      z pvalue ci.lower ci.upper
## 1  st_studying   ~        sex1 0.103 0.044  2.352  0.019    0.017    0.188
## 2  st_studying   ~    SESscore 0.290 0.023 12.542  0.000    0.245    0.336
## 3  st_studying   |          t1 0.365 0.027 13.373  0.000    0.311    0.418
## 4  st_studying  ~~ st_studying 1.000 0.000     NA     NA    1.000    1.000
## 5         sex1  ~~        sex1 0.237 0.000     NA     NA    0.237    0.237
## 6         sex1  ~~    SESscore 0.024 0.000     NA     NA    0.024    0.024
## 7     SESscore  ~~    SESscore 0.874 0.000     NA     NA    0.874    0.874
## 8  st_studying ~*~ st_studying 1.000 0.000     NA     NA    1.000    1.000
## 9  st_studying  ~1             0.000 0.000     NA     NA    0.000    0.000
## 10        sex1  ~1             0.384 0.000     NA     NA    0.384    0.384
## 11    SESscore  ~1             0.055 0.000     NA     NA    0.055    0.055
## 12 st_studying  r2 st_studying 0.072    NA     NA     NA       NA       NA
PE.model1.st_studying$est[PE.model1.st_studying$op == "r2"]
## [1] 0.07191247
r2diff2.st_studying <- (PE.model2.st_studying$est[PE.model2.st_studying$op == "r2"] - PE.model1.st_studying$est[PE.model1.st_studying$op == "r2"])
print(r2diff2.st_studying)    #difference model1 vs 2, incremental explained variance by GCSE
## [1] 0.05595861
r2diff3.st_studying <- (PE.model3.st_studying$est[PE.model3.st_studying$op == "r2"] - PE.model2.st_studying$est[PE.model2.st_studying$op == "r2"])
print(r2diff3.st_studying)    #difference model2 vs 3, incremental explained variance by highest qualification
## [1] 0.1578273
##employment status: full-time parent vs. unemployed
model1.st_parent <- 'st_parent ~ sex1 + SESscore'
model1.st_parentfit <- sem(model1.st_parent, data = df_dummy, ordered = c("st_parent"), missing = "listwise")
summary(model1.st_parentfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 10 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         3
## 
##                                                   Used       Total
##   Number of observations                          3698        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_parent ~                                                           
##     sex1             -0.507    0.222   -2.278    0.023   -0.943   -0.071
##     SESscore         -0.493    0.100   -4.916    0.000   -0.690   -0.296
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_parent         0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_parent|t1      2.601    0.117   22.308    0.000    2.373    2.830
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_parent         1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_parent         1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_parent         0.222
standardizedsolution(model1.st_parentfit)
##          lhs  op       rhs est.std    se      z pvalue ci.lower ci.upper
## 1  st_parent   ~      sex1  -0.217 0.090 -2.422  0.015   -0.393   -0.041
## 2  st_parent   ~  SESscore  -0.407 0.068 -5.980  0.000   -0.540   -0.273
## 3  st_parent   |        t1   2.295 0.111 20.661  0.000    2.077    2.513
## 4  st_parent  ~~ st_parent   0.778 0.068 11.375  0.000    0.644    0.912
## 5       sex1  ~~      sex1   1.000 0.000     NA     NA    1.000    1.000
## 6       sex1  ~~  SESscore   0.052 0.000     NA     NA    0.052    0.052
## 7   SESscore  ~~  SESscore   1.000 0.000     NA     NA    1.000    1.000
## 8  st_parent ~*~ st_parent   1.000 0.000     NA     NA    1.000    1.000
## 9  st_parent  ~1             0.000 0.000     NA     NA    0.000    0.000
## 10      sex1  ~1             0.789 0.000     NA     NA    0.789    0.789
## 11  SESscore  ~1             0.059 0.000     NA     NA    0.059    0.059
model2.st_parent <- 'st_parent ~ sex1 + SESscore + Zgcse'
model2.st_parentfit <- sem(model2.st_parent, data = df_dummy, ordered = c("st_parent"), missing = "listwise")
summary(model2.st_parentfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 17 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         4
## 
##                                                   Used       Total
##   Number of observations                          3698        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_parent ~                                                           
##     sex1             -0.542    0.233   -2.332    0.020   -0.998   -0.087
##     SESscore         -0.352    0.112   -3.155    0.002   -0.571   -0.133
##     Zgcse            -0.315    0.089   -3.545    0.000   -0.489   -0.141
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_parent         0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_parent|t1      2.632    0.121   21.673    0.000    2.394    2.870
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_parent         1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_parent         1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_parent         0.269
standardizedsolution(model2.st_parentfit)
##          lhs  op       rhs est.std    se      z pvalue ci.lower ci.upper
## 1  st_parent   ~      sex1  -0.226 0.090 -2.498  0.012   -0.402   -0.049
## 2  st_parent   ~  SESscore  -0.281 0.082 -3.444  0.001   -0.441   -0.121
## 3  st_parent   ~     Zgcse  -0.254 0.068 -3.723  0.000   -0.387   -0.120
## 4  st_parent   |        t1   2.250 0.113 19.944  0.000    2.029    2.471
## 5  st_parent  ~~ st_parent   0.731 0.069 10.537  0.000    0.595    0.867
## 6       sex1  ~~      sex1   1.000 0.000     NA     NA    1.000    1.000
## 7       sex1  ~~  SESscore   0.052 0.000     NA     NA    0.052    0.052
## 8       sex1  ~~     Zgcse   0.014 0.000     NA     NA    0.014    0.014
## 9   SESscore  ~~  SESscore   1.000 0.000     NA     NA    1.000    1.000
## 10  SESscore  ~~     Zgcse   0.467 0.000     NA     NA    0.467    0.467
## 11     Zgcse  ~~     Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 12 st_parent ~*~ st_parent   1.000 0.000     NA     NA    1.000    1.000
## 13 st_parent  ~1             0.000 0.000     NA     NA    0.000    0.000
## 14      sex1  ~1             0.789 0.000     NA     NA    0.789    0.789
## 15  SESscore  ~1             0.059 0.000     NA     NA    0.059    0.059
## 16     Zgcse  ~1             0.216 0.000     NA     NA    0.216    0.216
model3.st_parent <- 'st_parent ~ sex1 + SESscore + Zgcse + Zhqual'
model3.st_parentfit <- sem(model3.st_parent, data = df_dummy, ordered = c("st_parent"), missing = "listwise")
summary(model3.st_parentfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 23 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         5
## 
##                                                   Used       Total
##   Number of observations                          3635        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_parent ~                                                           
##     sex1             -0.553    0.302   -1.831    0.067   -1.146    0.039
##     SESscore         -0.312    0.125   -2.494    0.013   -0.556   -0.067
##     Zgcse            -0.080    0.109   -0.728    0.466   -0.294    0.135
##     Zhqual           -0.390    0.132   -2.960    0.003   -0.649   -0.132
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_parent         0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_parent|t1      2.850    0.230   12.403    0.000    2.400    3.300
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_parent         1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_parent         1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_parent         0.310
standardizedsolution(model3.st_parentfit)
##          lhs  op       rhs est.std    se      z pvalue ci.lower ci.upper
## 1  st_parent   ~      sex1  -0.224 0.118 -1.891  0.059   -0.456    0.008
## 2  st_parent   ~  SESscore  -0.241 0.091 -2.645  0.008   -0.420   -0.062
## 3  st_parent   ~     Zgcse  -0.062 0.084 -0.737  0.461   -0.225    0.102
## 4  st_parent   ~    Zhqual  -0.324 0.108 -2.999  0.003   -0.535   -0.112
## 5  st_parent   |        t1   2.368 0.184 12.858  0.000    2.007    2.729
## 6  st_parent  ~~ st_parent   0.690 0.067 10.352  0.000    0.560    0.821
## 7       sex1  ~~      sex1   1.000 0.000     NA     NA    1.000    1.000
## 8       sex1  ~~  SESscore   0.051 0.000     NA     NA    0.051    0.051
## 9       sex1  ~~     Zgcse   0.011 0.000     NA     NA    0.011    0.011
## 10      sex1  ~~    Zhqual  -0.006 0.000     NA     NA   -0.006   -0.006
## 11  SESscore  ~~  SESscore   1.000 0.000     NA     NA    1.000    1.000
## 12  SESscore  ~~     Zgcse   0.459 0.000     NA     NA    0.459    0.459
## 13  SESscore  ~~    Zhqual   0.340 0.000     NA     NA    0.340    0.340
## 14     Zgcse  ~~     Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 15     Zgcse  ~~    Zhqual   0.528 0.000     NA     NA    0.528    0.528
## 16    Zhqual  ~~    Zhqual   1.000 0.000     NA     NA    1.000    1.000
## 17 st_parent ~*~ st_parent   1.000 0.000     NA     NA    1.000    1.000
## 18 st_parent  ~1             0.000 0.000     NA     NA    0.000    0.000
## 19      sex1  ~1             0.792 0.000     NA     NA    0.792    0.792
## 20  SESscore  ~1             0.066 0.000     NA     NA    0.066    0.066
## 21     Zgcse  ~1             0.233 0.000     NA     NA    0.233    0.233
## 22    Zhqual  ~1             0.005 0.000     NA     NA    0.005    0.005
#get change in R2 for model1 vs. model2 vs. model3
(PE.model3.st_parent <- parameterEstimates(model3.st_parentfit, rsquare = TRUE)) 
##          lhs  op       rhs    est    se      z pvalue ci.lower ci.upper
## 1  st_parent   ~      sex1 -0.553 0.302 -1.831  0.067   -1.146    0.039
## 2  st_parent   ~  SESscore -0.312 0.125 -2.494  0.013   -0.556   -0.067
## 3  st_parent   ~     Zgcse -0.080 0.109 -0.728  0.466   -0.294    0.135
## 4  st_parent   ~    Zhqual -0.390 0.132 -2.960  0.003   -0.649   -0.132
## 5  st_parent   |        t1  2.850 0.230 12.403  0.000    2.400    3.300
## 6  st_parent  ~~ st_parent  1.000 0.000     NA     NA    1.000    1.000
## 7       sex1  ~~      sex1  0.237 0.000     NA     NA    0.237    0.237
## 8       sex1  ~~  SESscore  0.023 0.000     NA     NA    0.023    0.023
## 9       sex1  ~~     Zgcse  0.005 0.000     NA     NA    0.005    0.005
## 10      sex1  ~~    Zhqual -0.003 0.000     NA     NA   -0.003   -0.003
## 11  SESscore  ~~  SESscore  0.868 0.000     NA     NA    0.868    0.868
## 12  SESscore  ~~     Zgcse  0.398 0.000     NA     NA    0.398    0.398
## 13  SESscore  ~~    Zhqual  0.316 0.000     NA     NA    0.316    0.316
## 14     Zgcse  ~~     Zgcse  0.865 0.000     NA     NA    0.865    0.865
## 15     Zgcse  ~~    Zhqual  0.490 0.000     NA     NA    0.490    0.490
## 16    Zhqual  ~~    Zhqual  0.997 0.000     NA     NA    0.997    0.997
## 17 st_parent ~*~ st_parent  1.000 0.000     NA     NA    1.000    1.000
## 18 st_parent  ~1            0.000 0.000     NA     NA    0.000    0.000
## 19      sex1  ~1            0.385 0.000     NA     NA    0.385    0.385
## 20  SESscore  ~1            0.062 0.000     NA     NA    0.062    0.062
## 21     Zgcse  ~1            0.217 0.000     NA     NA    0.217    0.217
## 22    Zhqual  ~1            0.005 0.000     NA     NA    0.005    0.005
## 23 st_parent  r2 st_parent  0.310    NA     NA     NA       NA       NA
PE.model3.st_parent$est[PE.model3.st_parent$op == "r2"]
## [1] 0.3096148
(PE.model2.st_parent <- parameterEstimates(model2.st_parentfit, rsquare = TRUE)) 
##          lhs  op       rhs    est    se      z pvalue ci.lower ci.upper
## 1  st_parent   ~      sex1 -0.542 0.233 -2.332  0.020   -0.998   -0.087
## 2  st_parent   ~  SESscore -0.352 0.112 -3.155  0.002   -0.571   -0.133
## 3  st_parent   ~     Zgcse -0.315 0.089 -3.545  0.000   -0.489   -0.141
## 4  st_parent   |        t1  2.632 0.121 21.673  0.000    2.394    2.870
## 5  st_parent  ~~ st_parent  1.000 0.000     NA     NA    1.000    1.000
## 6       sex1  ~~      sex1  0.237 0.000     NA     NA    0.237    0.237
## 7       sex1  ~~  SESscore  0.024 0.000     NA     NA    0.024    0.024
## 8       sex1  ~~     Zgcse  0.007 0.000     NA     NA    0.007    0.007
## 9   SESscore  ~~  SESscore  0.874 0.000     NA     NA    0.874    0.874
## 10  SESscore  ~~     Zgcse  0.411 0.000     NA     NA    0.411    0.411
## 11     Zgcse  ~~     Zgcse  0.888 0.000     NA     NA    0.888    0.888
## 12 st_parent ~*~ st_parent  1.000 0.000     NA     NA    1.000    1.000
## 13 st_parent  ~1            0.000 0.000     NA     NA    0.000    0.000
## 14      sex1  ~1            0.384 0.000     NA     NA    0.384    0.384
## 15  SESscore  ~1            0.055 0.000     NA     NA    0.055    0.055
## 16     Zgcse  ~1            0.203 0.000     NA     NA    0.203    0.203
## 17 st_parent  r2 st_parent  0.269    NA     NA     NA       NA       NA
PE.model2.st_parent$est[PE.model2.st_parent$op == "r2"]
## [1] 0.2692434
(PE.model1.st_parent <- parameterEstimates(model1.st_parentfit, rsquare = TRUE)) 
##          lhs  op       rhs    est    se      z pvalue ci.lower ci.upper
## 1  st_parent   ~      sex1 -0.507 0.222 -2.278  0.023   -0.943   -0.071
## 2  st_parent   ~  SESscore -0.493 0.100 -4.916  0.000   -0.690   -0.296
## 3  st_parent   |        t1  2.601 0.117 22.308  0.000    2.373    2.830
## 4  st_parent  ~~ st_parent  1.000 0.000     NA     NA    1.000    1.000
## 5       sex1  ~~      sex1  0.237 0.000     NA     NA    0.237    0.237
## 6       sex1  ~~  SESscore  0.024 0.000     NA     NA    0.024    0.024
## 7   SESscore  ~~  SESscore  0.874 0.000     NA     NA    0.874    0.874
## 8  st_parent ~*~ st_parent  1.000 0.000     NA     NA    1.000    1.000
## 9  st_parent  ~1            0.000 0.000     NA     NA    0.000    0.000
## 10      sex1  ~1            0.384 0.000     NA     NA    0.384    0.384
## 11  SESscore  ~1            0.055 0.000     NA     NA    0.055    0.055
## 12 st_parent  r2 st_parent  0.222    NA     NA     NA       NA       NA
PE.model1.st_parent$est[PE.model1.st_parent$op == "r2"]
## [1] 0.2218161
r2diff2.st_parent <- (PE.model2.st_parent$est[PE.model2.st_parent$op == "r2"] - PE.model1.st_parent$est[PE.model1.st_parent$op == "r2"])
print(r2diff2.st_parent)    #difference model1 vs 2, incremental explained variance by GCSE
## [1] 0.04742732
r2diff3.st_parent <- (PE.model3.st_parent$est[PE.model3.st_parent$op == "r2"] - PE.model2.st_parent$est[PE.model2.st_parent$op == "r2"])
print(r2diff3.st_parent)    #difference model2 vs 3, incremental explained variance by highest qualification
## [1] 0.04037144
#employment status: gap year/travelling vs. unemployed
model1.st_gapyear <- 'st_gapyear ~ sex1 + SESscore'
model1.st_gapyearfit <- sem(model1.st_gapyear, data = df_dummy, ordered = c("st_gapyear"), missing = "listwise")
summary(model1.st_gapyearfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 9 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         3
## 
##                                                   Used       Total
##   Number of observations                          3698        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_gapyear ~                                                          
##     sex1             -0.103    0.082   -1.250    0.211   -0.264    0.058
##     SESscore          0.165    0.043    3.857    0.000    0.081    0.249
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_gapyear        0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_gapyear|t1     1.802    0.050   35.689    0.000    1.703    1.901
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_gapyear        1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_gapyear        1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_gapyear        0.025
standardizedsolution(model1.st_gapyearfit)
##           lhs  op        rhs est.std    se      z pvalue ci.lower ci.upper
## 1  st_gapyear   ~       sex1  -0.049 0.039 -1.252  0.211   -0.127    0.028
## 2  st_gapyear   ~   SESscore   0.152 0.039  3.947  0.000    0.077    0.228
## 3  st_gapyear   |         t1   1.780 0.050 35.365  0.000    1.681    1.878
## 4  st_gapyear  ~~ st_gapyear   0.975 0.012 81.707  0.000    0.952    0.998
## 5        sex1  ~~       sex1   1.000 0.000     NA     NA    1.000    1.000
## 6        sex1  ~~   SESscore   0.052 0.000     NA     NA    0.052    0.052
## 7    SESscore  ~~   SESscore   1.000 0.000     NA     NA    1.000    1.000
## 8  st_gapyear ~*~ st_gapyear   1.000 0.000     NA     NA    1.000    1.000
## 9  st_gapyear  ~1              0.000 0.000     NA     NA    0.000    0.000
## 10       sex1  ~1              0.789 0.000     NA     NA    0.789    0.789
## 11   SESscore  ~1              0.059 0.000     NA     NA    0.059    0.059
model2.st_gapyear <- 'st_gapyear ~ sex1 + SESscore + Zgcse'
model2.st_gapyearfit <- sem(model2.st_gapyear, data = df_dummy, ordered = c("st_gapyear"), missing = "listwise")
summary(model2.st_gapyearfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 10 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         4
## 
##                                                   Used       Total
##   Number of observations                          3698        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_gapyear ~                                                          
##     sex1             -0.101    0.083   -1.213    0.225   -0.263    0.062
##     SESscore          0.142    0.049    2.892    0.004    0.046    0.238
##     Zgcse             0.050    0.051    0.993    0.321   -0.049    0.149
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_gapyear        0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_gapyear|t1     1.814    0.053   34.342    0.000    1.710    1.917
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_gapyear        1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_gapyear        1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_gapyear        0.027
standardizedsolution(model2.st_gapyearfit)
##           lhs  op        rhs est.std    se      z pvalue ci.lower ci.upper
## 1  st_gapyear   ~       sex1  -0.048 0.040 -1.215  0.224   -0.126    0.030
## 2  st_gapyear   ~   SESscore   0.131 0.045  2.929  0.003    0.043    0.218
## 3  st_gapyear   ~      Zgcse   0.047 0.047  0.995  0.320   -0.045    0.139
## 4  st_gapyear   |         t1   1.789 0.052 34.543  0.000    1.688    1.891
## 5  st_gapyear  ~~ st_gapyear   0.973 0.012 79.238  0.000    0.949    0.998
## 6        sex1  ~~       sex1   1.000 0.000     NA     NA    1.000    1.000
## 7        sex1  ~~   SESscore   0.052 0.000     NA     NA    0.052    0.052
## 8        sex1  ~~      Zgcse   0.014 0.000     NA     NA    0.014    0.014
## 9    SESscore  ~~   SESscore   1.000 0.000     NA     NA    1.000    1.000
## 10   SESscore  ~~      Zgcse   0.467 0.000     NA     NA    0.467    0.467
## 11      Zgcse  ~~      Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 12 st_gapyear ~*~ st_gapyear   1.000 0.000     NA     NA    1.000    1.000
## 13 st_gapyear  ~1              0.000 0.000     NA     NA    0.000    0.000
## 14       sex1  ~1              0.789 0.000     NA     NA    0.789    0.789
## 15   SESscore  ~1              0.059 0.000     NA     NA    0.059    0.059
## 16      Zgcse  ~1              0.216 0.000     NA     NA    0.216    0.216
model3.st_gapyear <- 'st_gapyear ~ sex1 + SESscore + Zgcse + Zhqual'
model3.st_gapyearfit <- sem(model3.st_gapyear, data = df_dummy, ordered = c("st_gapyear"), missing = "listwise")
summary(model3.st_gapyearfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 15 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         5
## 
##                                                   Used       Total
##   Number of observations                          3635        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_gapyear ~                                                          
##     sex1             -0.113    0.083   -1.357    0.175   -0.276    0.050
##     SESscore          0.137    0.050    2.741    0.006    0.039    0.235
##     Zgcse             0.056    0.056    1.003    0.316   -0.054    0.167
##     Zhqual           -0.015    0.055   -0.268    0.789   -0.123    0.093
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_gapyear        0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_gapyear|t1     1.805    0.053   33.897    0.000    1.701    1.910
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_gapyear        1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_gapyear        1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_gapyear        0.025
standardizedsolution(model3.st_gapyearfit)
##           lhs  op        rhs est.std    se      z pvalue ci.lower ci.upper
## 1  st_gapyear   ~       sex1  -0.054 0.040 -1.359  0.174   -0.133    0.024
## 2  st_gapyear   ~   SESscore   0.126 0.045  2.772  0.006    0.037    0.215
## 3  st_gapyear   ~      Zgcse   0.052 0.052  1.004  0.315   -0.049    0.153
## 4  st_gapyear   ~     Zhqual  -0.015 0.054 -0.268  0.789   -0.121    0.092
## 5  st_gapyear   |         t1   1.783 0.053 33.869  0.000    1.680    1.886
## 6  st_gapyear  ~~ st_gapyear   0.975 0.012 82.481  0.000    0.952    0.998
## 7        sex1  ~~       sex1   1.000 0.000     NA     NA    1.000    1.000
## 8        sex1  ~~   SESscore   0.051 0.000     NA     NA    0.051    0.051
## 9        sex1  ~~      Zgcse   0.011 0.000     NA     NA    0.011    0.011
## 10       sex1  ~~     Zhqual  -0.006 0.000     NA     NA   -0.006   -0.006
## 11   SESscore  ~~   SESscore   1.000 0.000     NA     NA    1.000    1.000
## 12   SESscore  ~~      Zgcse   0.459 0.000     NA     NA    0.459    0.459
## 13   SESscore  ~~     Zhqual   0.340 0.000     NA     NA    0.340    0.340
## 14      Zgcse  ~~      Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 15      Zgcse  ~~     Zhqual   0.528 0.000     NA     NA    0.528    0.528
## 16     Zhqual  ~~     Zhqual   1.000 0.000     NA     NA    1.000    1.000
## 17 st_gapyear ~*~ st_gapyear   1.000 0.000     NA     NA    1.000    1.000
## 18 st_gapyear  ~1              0.000 0.000     NA     NA    0.000    0.000
## 19       sex1  ~1              0.792 0.000     NA     NA    0.792    0.792
## 20   SESscore  ~1              0.066 0.000     NA     NA    0.066    0.066
## 21      Zgcse  ~1              0.233 0.000     NA     NA    0.233    0.233
## 22     Zhqual  ~1              0.005 0.000     NA     NA    0.005    0.005
#get change in R2 for model1 vs. model2 vs. model3
(PE.model3.st_gapyear <- parameterEstimates(model3.st_gapyearfit, rsquare = TRUE)) 
##           lhs  op        rhs    est    se      z pvalue ci.lower ci.upper
## 1  st_gapyear   ~       sex1 -0.113 0.083 -1.357  0.175   -0.276    0.050
## 2  st_gapyear   ~   SESscore  0.137 0.050  2.741  0.006    0.039    0.235
## 3  st_gapyear   ~      Zgcse  0.056 0.056  1.003  0.316   -0.054    0.167
## 4  st_gapyear   ~     Zhqual -0.015 0.055 -0.268  0.789   -0.123    0.093
## 5  st_gapyear   |         t1  1.805 0.053 33.897  0.000    1.701    1.910
## 6  st_gapyear  ~~ st_gapyear  1.000 0.000     NA     NA    1.000    1.000
## 7        sex1  ~~       sex1  0.237 0.000     NA     NA    0.237    0.237
## 8        sex1  ~~   SESscore  0.023 0.000     NA     NA    0.023    0.023
## 9        sex1  ~~      Zgcse  0.005 0.000     NA     NA    0.005    0.005
## 10       sex1  ~~     Zhqual -0.003 0.000     NA     NA   -0.003   -0.003
## 11   SESscore  ~~   SESscore  0.868 0.000     NA     NA    0.868    0.868
## 12   SESscore  ~~      Zgcse  0.398 0.000     NA     NA    0.398    0.398
## 13   SESscore  ~~     Zhqual  0.316 0.000     NA     NA    0.316    0.316
## 14      Zgcse  ~~      Zgcse  0.865 0.000     NA     NA    0.865    0.865
## 15      Zgcse  ~~     Zhqual  0.490 0.000     NA     NA    0.490    0.490
## 16     Zhqual  ~~     Zhqual  0.997 0.000     NA     NA    0.997    0.997
## 17 st_gapyear ~*~ st_gapyear  1.000 0.000     NA     NA    1.000    1.000
## 18 st_gapyear  ~1             0.000 0.000     NA     NA    0.000    0.000
## 19       sex1  ~1             0.385 0.000     NA     NA    0.385    0.385
## 20   SESscore  ~1             0.062 0.000     NA     NA    0.062    0.062
## 21      Zgcse  ~1             0.217 0.000     NA     NA    0.217    0.217
## 22     Zhqual  ~1             0.005 0.000     NA     NA    0.005    0.005
## 23 st_gapyear  r2 st_gapyear  0.025    NA     NA     NA       NA       NA
PE.model3.st_gapyear$est[PE.model3.st_gapyear$op == "r2"]
## [1] 0.02491703
(PE.model2.st_gapyear <- parameterEstimates(model2.st_gapyearfit, rsquare = TRUE)) 
##           lhs  op        rhs    est    se      z pvalue ci.lower ci.upper
## 1  st_gapyear   ~       sex1 -0.101 0.083 -1.213  0.225   -0.263    0.062
## 2  st_gapyear   ~   SESscore  0.142 0.049  2.892  0.004    0.046    0.238
## 3  st_gapyear   ~      Zgcse  0.050 0.051  0.993  0.321   -0.049    0.149
## 4  st_gapyear   |         t1  1.814 0.053 34.342  0.000    1.710    1.917
## 5  st_gapyear  ~~ st_gapyear  1.000 0.000     NA     NA    1.000    1.000
## 6        sex1  ~~       sex1  0.237 0.000     NA     NA    0.237    0.237
## 7        sex1  ~~   SESscore  0.024 0.000     NA     NA    0.024    0.024
## 8        sex1  ~~      Zgcse  0.007 0.000     NA     NA    0.007    0.007
## 9    SESscore  ~~   SESscore  0.874 0.000     NA     NA    0.874    0.874
## 10   SESscore  ~~      Zgcse  0.411 0.000     NA     NA    0.411    0.411
## 11      Zgcse  ~~      Zgcse  0.888 0.000     NA     NA    0.888    0.888
## 12 st_gapyear ~*~ st_gapyear  1.000 0.000     NA     NA    1.000    1.000
## 13 st_gapyear  ~1             0.000 0.000     NA     NA    0.000    0.000
## 14       sex1  ~1             0.384 0.000     NA     NA    0.384    0.384
## 15   SESscore  ~1             0.055 0.000     NA     NA    0.055    0.055
## 16      Zgcse  ~1             0.203 0.000     NA     NA    0.203    0.203
## 17 st_gapyear  r2 st_gapyear  0.027    NA     NA     NA       NA       NA
PE.model2.st_gapyear$est[PE.model2.st_gapyear$op == "r2"]
## [1] 0.02655772
(PE.model1.st_gapyear <- parameterEstimates(model1.st_gapyearfit, rsquare = TRUE)) 
##           lhs  op        rhs    est    se      z pvalue ci.lower ci.upper
## 1  st_gapyear   ~       sex1 -0.103 0.082 -1.250  0.211   -0.264    0.058
## 2  st_gapyear   ~   SESscore  0.165 0.043  3.857  0.000    0.081    0.249
## 3  st_gapyear   |         t1  1.802 0.050 35.689  0.000    1.703    1.901
## 4  st_gapyear  ~~ st_gapyear  1.000 0.000     NA     NA    1.000    1.000
## 5        sex1  ~~       sex1  0.237 0.000     NA     NA    0.237    0.237
## 6        sex1  ~~   SESscore  0.024 0.000     NA     NA    0.024    0.024
## 7    SESscore  ~~   SESscore  0.874 0.000     NA     NA    0.874    0.874
## 8  st_gapyear ~*~ st_gapyear  1.000 0.000     NA     NA    1.000    1.000
## 9  st_gapyear  ~1             0.000 0.000     NA     NA    0.000    0.000
## 10       sex1  ~1             0.384 0.000     NA     NA    0.384    0.384
## 11   SESscore  ~1             0.055 0.000     NA     NA    0.055    0.055
## 12 st_gapyear  r2 st_gapyear  0.025    NA     NA     NA       NA       NA
PE.model1.st_gapyear$est[PE.model1.st_gapyear$op == "r2"]
## [1] 0.02490141
r2diff2.st_gapyear <- (PE.model2.st_gapyear$est[PE.model2.st_gapyear$op == "r2"] - PE.model1.st_gapyear$est[PE.model1.st_gapyear$op == "r2"])
print(r2diff2.st_gapyear)    #difference model1 vs 2, incremental explained variance by GCSE
## [1] 0.001656313
r2diff3.st_gapyear <- (PE.model3.st_gapyear$est[PE.model3.st_gapyear$op == "r2"] - PE.model2.st_gapyear$est[PE.model2.st_gapyear$op == "r2"])
print(r2diff3.st_gapyear)    #difference model2 vs 3, incremental explained variance by highest qualification
## [1] -0.001640693

#Step 4: #Regression models with moderation for sex and SES

again series of linear/logistic/multi-nominal regressions for all DVs now with moderation by SES or sex (separately)

Model a1: DV ~ sex1 + Zgcse Model a2: DV ~ sex1 + Zgcse + sex*Zgcse

Model b1: DV ~ SESscore + Zgcse Model b2: DV ~ SESscore + Zgcse + SES*Zgcse

df$sex.gcse <- df$sex1*df$Zgcse
df$SES.gcse <- df$SESscore*df$Zgcse
modela1.hqual <- 'Zhqual ~ sex1 + Zgcse'
modela1.hqualfit <- sem(modela1.hqual, data = df, missing = "fiml", fixed.x = FALSE)
summary(modela1.hqualfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 12 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                          6488
##   Number of missing patterns                         2
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                              1209.253
##   Degrees of freedom                                 2
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -18526.245
##   Loglikelihood unrestricted model (H1)     -18526.245
##                                                       
##   Akaike (AIC)                               37070.489
##   Bayesian (BIC)                             37131.489
##   Sample-size adjusted Bayesian (SABIC)      37102.889
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zhqual ~                                                              
##     sex1             -0.026    0.029   -0.899    0.369   -0.082    0.030
##     Zgcse             0.565    0.015   37.825    0.000    0.536    0.595
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zhqual           -0.108    0.018   -5.973    0.000   -0.143   -0.073
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zhqual            0.720    0.017   42.948    0.000    0.687    0.753
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zhqual            0.308
standardizedsolution(modela1.hqualfit)
##      lhs op    rhs est.std    se      z pvalue ci.lower ci.upper
## 1 Zhqual  ~   sex1  -0.013 0.014 -0.900  0.368   -0.040    0.015
## 2 Zhqual  ~  Zgcse   0.554 0.012 47.820  0.000    0.531    0.577
## 3 Zhqual ~~ Zhqual   0.692 0.013 53.719  0.000    0.667    0.717
## 4   sex1 ~~   sex1   1.000 0.000     NA     NA    1.000    1.000
## 5   sex1 ~~  Zgcse  -0.053 0.012 -4.250  0.000   -0.077   -0.028
## 6  Zgcse ~~  Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 7 Zhqual ~1         -0.106 0.018 -5.993  0.000   -0.140   -0.071
## 8   sex1 ~1          0.950 0.015 63.509  0.000    0.920    0.979
## 9  Zgcse ~1          0.000 0.012  0.000  1.000   -0.024    0.024
modela2.hqual <- 'Zhqual ~ sex1 + Zgcse + sex.gcse'
modela2.hqualfit <- sem(modela2.hqual, data = df, missing = "fiml", fixed.x = FALSE)
summary(modela2.hqualfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 18 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        14
## 
##   Number of observations                          6488
##   Number of missing patterns                         2
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                              1213.586
##   Degrees of freedom                                 3
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -23222.754
##   Loglikelihood unrestricted model (H1)     -23222.754
##                                                       
##   Akaike (AIC)                               46473.508
##   Bayesian (BIC)                             46568.396
##   Sample-size adjusted Bayesian (SABIC)      46523.908
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zhqual ~                                                              
##     sex1             -0.039    0.029   -1.336    0.182   -0.097    0.018
##     Zgcse             0.540    0.019   27.951    0.000    0.502    0.578
##     sex.gcse          0.063    0.030    2.082    0.037    0.004    0.123
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     sex.gcse         -0.014    0.004   -3.174    0.002   -0.022   -0.005
##   Zgcse ~~                                                              
##     sex.gcse          0.492    0.011   46.289    0.000    0.471    0.513
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zhqual           -0.103    0.018   -5.640    0.000   -0.139   -0.067
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
##     sex.gcse         -0.026    0.009   -3.018    0.003   -0.043   -0.009
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zhqual            0.719    0.017   42.948    0.000    0.687    0.752
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     sex.gcse          0.492    0.009   56.957    0.000    0.475    0.509
## 
## R-Square:
##                    Estimate
##     Zhqual            0.314
standardizedsolution(modela2.hqualfit)
##         lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1    Zhqual  ~     sex1  -0.019 0.014  -1.338  0.181   -0.047    0.009
## 2    Zhqual  ~    Zgcse   0.527 0.017  30.199  0.000    0.493    0.561
## 3    Zhqual  ~ sex.gcse   0.043 0.021   2.090  0.037    0.003    0.084
## 4    Zhqual ~~   Zhqual   0.686 0.013  52.010  0.000    0.661    0.712
## 5      sex1 ~~     sex1   1.000 0.000      NA     NA    1.000    1.000
## 6      sex1 ~~    Zgcse  -0.053 0.012  -4.249  0.000   -0.077   -0.028
## 7      sex1 ~~ sex.gcse  -0.039 0.012  -3.182  0.001   -0.064   -0.015
## 8     Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 9     Zgcse ~~ sex.gcse   0.702 0.006 111.584  0.000    0.690    0.715
## 10 sex.gcse ~~ sex.gcse   1.000 0.000      NA     NA    1.000    1.000
## 11   Zhqual ~1           -0.100 0.018  -5.648  0.000   -0.135   -0.066
## 12     sex1 ~1            0.950 0.015  63.510  0.000    0.920    0.979
## 13    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
## 14 sex.gcse ~1           -0.037 0.012  -3.017  0.003   -0.062   -0.013
modelb1.hqual <- 'Zhqual ~ SESscore + Zgcse'
modelb1.hqualfit <- sem(modelb1.hqual, data = df, missing = "fiml", fixed.x = FALSE)
summary(modelb1.hqualfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 9 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                              1269.436
##   Degrees of freedom                                 2
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -21575.873
##   Loglikelihood unrestricted model (H1)     -21575.873
##                                                       
##   Akaike (AIC)                               43169.745
##   Bayesian (BIC)                             43230.745
##   Sample-size adjusted Bayesian (SABIC)      43202.145
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zhqual ~                                                              
##     SESscore          0.132    0.017    7.845    0.000    0.099    0.165
##     Zgcse             0.505    0.017   30.193    0.000    0.472    0.537
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.421    0.000    0.422    0.472
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zhqual           -0.113    0.014   -7.957    0.000   -0.141   -0.085
##     SESscore         -0.034    0.012   -2.914    0.004   -0.057   -0.011
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zhqual            0.708    0.017   42.936    0.000    0.676    0.741
##     SESscore          0.874    0.016   56.326    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zhqual            0.318
standardizedsolution(modelb1.hqualfit)
##        lhs op      rhs est.std    se      z pvalue ci.lower ci.upper
## 1   Zhqual  ~ SESscore   0.122 0.015  7.880  0.000    0.091    0.152
## 2   Zhqual  ~    Zgcse   0.495 0.014 34.663  0.000    0.467    0.523
## 3   Zhqual ~~   Zhqual   0.682 0.013 53.266  0.000    0.657    0.708
## 4 SESscore ~~ SESscore   1.000 0.000     NA     NA    1.000    1.000
## 5 SESscore ~~    Zgcse   0.478 0.010 49.293  0.000    0.459    0.497
## 6    Zgcse ~~    Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 7   Zhqual ~1           -0.111 0.014 -8.030  0.000   -0.138   -0.084
## 8 SESscore ~1           -0.036 0.013 -2.914  0.004   -0.061   -0.012
## 9    Zgcse ~1            0.000 0.012  0.000  1.000   -0.024    0.024
modelb2.hqual <- 'Zhqual ~ SESscore + Zgcse + SES.gcse'
modelb2.hqualfit <- sem(modelb2.hqual, data = df, missing = "fiml", fixed.x = FALSE)
summary(modelb2.hqualfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 10 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        14
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                              1360.864
##   Degrees of freedom                                 3
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -30248.349
##   Loglikelihood unrestricted model (H1)     -30248.349
##                                                       
##   Akaike (AIC)                               60524.699
##   Bayesian (BIC)                             60619.587
##   Sample-size adjusted Bayesian (SABIC)      60575.098
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zhqual ~                                                              
##     SESscore          0.164    0.017    9.654    0.000    0.131    0.197
##     Zgcse             0.501    0.017   30.341    0.000    0.469    0.533
##     SES.gcse         -0.153    0.016   -9.628    0.000   -0.184   -0.122
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.418    0.000    0.422    0.472
##     SES.gcse         -0.013    0.011   -1.111    0.267   -0.035    0.010
##   Zgcse ~~                                                              
##     SES.gcse         -0.118    0.012   -9.648    0.000   -0.142   -0.094
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zhqual           -0.051    0.015   -3.329    0.001   -0.082   -0.021
##     SESscore         -0.034    0.012   -2.913    0.004   -0.057   -0.011
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
##     SES.gcse          0.444    0.012   36.804    0.000    0.420    0.467
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zhqual            0.691    0.016   42.913    0.000    0.659    0.722
##     SESscore          0.874    0.016   56.329    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     SES.gcse          0.925    0.016   56.380    0.000    0.893    0.957
## 
## R-Square:
##                    Estimate
##     Zhqual            0.360
standardizedsolution(modelb2.hqualfit)
##         lhs op      rhs est.std    se      z pvalue ci.lower ci.upper
## 1    Zhqual  ~ SESscore   0.148 0.015  9.771  0.000    0.118    0.177
## 2    Zhqual  ~    Zgcse   0.482 0.014 34.458  0.000    0.455    0.510
## 3    Zhqual  ~ SES.gcse  -0.142 0.014 -9.898  0.000   -0.170   -0.114
## 4    Zhqual ~~   Zhqual   0.640 0.013 47.733  0.000    0.614    0.667
## 5  SESscore ~~ SESscore   1.000 0.000     NA     NA    1.000    1.000
## 6  SESscore ~~    Zgcse   0.478 0.010 49.285  0.000    0.459    0.497
## 7  SESscore ~~ SES.gcse  -0.014 0.013 -1.111  0.266   -0.039    0.011
## 8     Zgcse ~~    Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 9     Zgcse ~~ SES.gcse  -0.122 0.012 -9.864  0.000   -0.147   -0.098
## 10 SES.gcse ~~ SES.gcse   1.000 0.000     NA     NA    1.000    1.000
## 11   Zhqual ~1           -0.049 0.015 -3.326  0.001   -0.079   -0.020
## 12 SESscore ~1           -0.036 0.013 -2.912  0.004   -0.061   -0.012
## 13    Zgcse ~1            0.000 0.012  0.000  1.000   -0.024    0.024
## 14 SES.gcse ~1            0.461 0.013 35.005  0.000    0.436    0.487
#get change in R2 for models with vs. w/0 moderation (modela1 vs. a2 and b1 vs b2) 
(PE.modela1.hqual <- parameterEstimates(modela1.hqualfit, rsquare = TRUE)) 
##       lhs op    rhs    est    se      z pvalue ci.lower ci.upper
## 1  Zhqual  ~   sex1 -0.026 0.029 -0.899  0.369   -0.082    0.030
## 2  Zhqual  ~  Zgcse  0.565 0.015 37.825  0.000    0.536    0.595
## 3  Zhqual ~~ Zhqual  0.720 0.017 42.948  0.000    0.687    0.753
## 4    sex1 ~~   sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 5    sex1 ~~  Zgcse -0.026 0.006 -4.232  0.000   -0.038   -0.014
## 6   Zgcse ~~  Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 7  Zhqual ~1        -0.108 0.018 -5.973  0.000   -0.143   -0.073
## 8    sex1 ~1         0.474 0.006 76.503  0.000    0.462    0.486
## 9   Zgcse ~1         0.000 0.012  0.000  1.000   -0.024    0.024
## 10 Zhqual r2 Zhqual  0.308    NA     NA     NA       NA       NA
PE.modela1.hqual$est[PE.modela1.hqual$op == "r2"]
## [1] 0.30791
(PE.modela2.hqual <- parameterEstimates(modela2.hqualfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1    Zhqual  ~     sex1 -0.039 0.029 -1.336  0.182   -0.097    0.018
## 2    Zhqual  ~    Zgcse  0.540 0.019 27.951  0.000    0.502    0.578
## 3    Zhqual  ~ sex.gcse  0.063 0.030  2.082  0.037    0.004    0.123
## 4    Zhqual ~~   Zhqual  0.719 0.017 42.948  0.000    0.687    0.752
## 5      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 6      sex1 ~~    Zgcse -0.026 0.006 -4.232  0.000   -0.038   -0.014
## 7      sex1 ~~ sex.gcse -0.014 0.004 -3.174  0.002   -0.022   -0.005
## 8     Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 9     Zgcse ~~ sex.gcse  0.492 0.011 46.289  0.000    0.471    0.513
## 10 sex.gcse ~~ sex.gcse  0.492 0.009 56.957  0.000    0.475    0.509
## 11   Zhqual ~1          -0.103 0.018 -5.640  0.000   -0.139   -0.067
## 12     sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 13    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 14 sex.gcse ~1          -0.026 0.009 -3.018  0.003   -0.043   -0.009
## 15   Zhqual r2   Zhqual  0.314    NA     NA     NA       NA       NA
PE.modela2.hqual$est[PE.modela2.hqual$op == "r2"]
## [1] 0.3135517
(PE.modelb1.hqual <- parameterEstimates(modelb1.hqualfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1    Zhqual  ~ SESscore  0.132 0.017  7.845  0.000    0.099    0.165
## 2    Zhqual  ~    Zgcse  0.505 0.017 30.193  0.000    0.472    0.537
## 3    Zhqual ~~   Zhqual  0.708 0.017 42.936  0.000    0.676    0.741
## 4  SESscore ~~ SESscore  0.874 0.016 56.326  0.000    0.844    0.905
## 5  SESscore ~~    Zgcse  0.447 0.013 34.421  0.000    0.422    0.472
## 6     Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 7    Zhqual ~1          -0.113 0.014 -7.957  0.000   -0.141   -0.085
## 8  SESscore ~1          -0.034 0.012 -2.914  0.004   -0.057   -0.011
## 9     Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 10   Zhqual r2   Zhqual  0.318    NA     NA     NA       NA       NA
PE.modelb1.hqual$est[PE.modelb1.hqual$op == "r2"]
## [1] 0.3175504
(PE.modelb2.hqual <- parameterEstimates(modelb2.hqualfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1    Zhqual  ~ SESscore  0.164 0.017  9.654  0.000    0.131    0.197
## 2    Zhqual  ~    Zgcse  0.501 0.017 30.341  0.000    0.469    0.533
## 3    Zhqual  ~ SES.gcse -0.153 0.016 -9.628  0.000   -0.184   -0.122
## 4    Zhqual ~~   Zhqual  0.691 0.016 42.913  0.000    0.659    0.722
## 5  SESscore ~~ SESscore  0.874 0.016 56.329  0.000    0.844    0.905
## 6  SESscore ~~    Zgcse  0.447 0.013 34.418  0.000    0.422    0.472
## 7  SESscore ~~ SES.gcse -0.013 0.011 -1.111  0.267   -0.035    0.010
## 8     Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 9     Zgcse ~~ SES.gcse -0.118 0.012 -9.648  0.000   -0.142   -0.094
## 10 SES.gcse ~~ SES.gcse  0.925 0.016 56.380  0.000    0.893    0.957
## 11   Zhqual ~1          -0.051 0.015 -3.329  0.001   -0.082   -0.021
## 12 SESscore ~1          -0.034 0.012 -2.913  0.004   -0.057   -0.011
## 13    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 14 SES.gcse ~1           0.444 0.012 36.804  0.000    0.420    0.467
## 15   Zhqual r2   Zhqual  0.360    NA     NA     NA       NA       NA
PE.modelb2.hqual$est[PE.modelb2.hqual$op == "r2"]
## [1] 0.3596876
r2diffa.hqual <- (PE.modela2.hqual$est[PE.modela2.hqual$op == "r2"] - PE.modela1.hqual$est[PE.modela1.hqual$op == "r2"])
print(r2diffa.hqual)    #difference modela1 vs a2, incremental explained variance by sexxGCSE
## [1] 0.00564173
r2diffb.hqual <- (PE.modelb2.hqual$est[PE.modelb2.hqual$op == "r2"] - PE.modelb1.hqual$est[PE.modelb1.hqual$op == "r2"])
print(r2diffb.hqual)    #difference modelb1 vs b2, incremental explained variance by SESxGCSE
## [1] 0.04213726
modela1.degree <- 'Zdegree ~ sex1 + Zgcse'
modela1.degreefit <- sem(modela1.degree, data = df, missing = "fiml", fixed.x = FALSE)
summary(modela1.degreefit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 18 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                          6488
##   Number of missing patterns                         2
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                               151.823
##   Degrees of freedom                                 2
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -16339.111
##   Loglikelihood unrestricted model (H1)     -16339.111
##                                                       
##   Akaike (AIC)                               32696.222
##   Bayesian (BIC)                             32757.221
##   Sample-size adjusted Bayesian (SABIC)      32728.621
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zdegree ~                                                             
##     sex1             -0.079    0.048   -1.652    0.099   -0.172    0.015
##     Zgcse             0.381    0.030   12.562    0.000    0.322    0.441
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zdegree          -0.170    0.032   -5.325    0.000   -0.233   -0.107
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zdegree           0.917    0.031   29.791    0.000    0.857    0.978
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zdegree           0.139
standardizedsolution(modela1.degreefit)
##       lhs op     rhs est.std    se      z pvalue ci.lower ci.upper
## 1 Zdegree  ~    sex1  -0.038 0.023 -1.656  0.098   -0.083    0.007
## 2 Zdegree  ~   Zgcse   0.369 0.026 14.177  0.000    0.318    0.420
## 3 Zdegree ~~ Zdegree   0.861 0.020 43.924  0.000    0.822    0.899
## 4    sex1 ~~    sex1   1.000 0.000     NA     NA    1.000    1.000
## 5    sex1 ~~   Zgcse  -0.053 0.012 -4.249  0.000   -0.077   -0.028
## 6   Zgcse ~~   Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 7 Zdegree ~1          -0.165 0.030 -5.426  0.000   -0.224   -0.105
## 8    sex1 ~1           0.950 0.015 63.510  0.000    0.920    0.979
## 9   Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
modela2.degree <- 'Zdegree ~ sex1 + Zgcse + sex.gcse'
modela2.degreefit <- sem(modela2.degree, data = df, missing = "fiml", fixed.x = FALSE)
summary(modela2.degreefit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 26 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        14
## 
##   Number of observations                          6488
##   Number of missing patterns                         2
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                               156.027
##   Degrees of freedom                                 3
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -21035.685
##   Loglikelihood unrestricted model (H1)     -21035.685
##                                                       
##   Akaike (AIC)                               42099.370
##   Bayesian (BIC)                             42194.258
##   Sample-size adjusted Bayesian (SABIC)      42149.770
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zdegree ~                                                             
##     sex1             -0.006    0.059   -0.107    0.915   -0.122    0.109
##     Zgcse             0.426    0.037   11.392    0.000    0.353    0.500
##     sex.gcse         -0.131    0.064   -2.052    0.040   -0.256   -0.006
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     sex.gcse         -0.014    0.004   -3.174    0.002   -0.022   -0.005
##   Zgcse ~~                                                              
##     sex.gcse          0.492    0.011   46.290    0.000    0.471    0.513
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zdegree          -0.192    0.034   -5.708    0.000   -0.258   -0.126
##     sex1              0.474    0.006   76.502    0.000    0.462    0.486
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
##     sex.gcse         -0.026    0.009   -3.017    0.003   -0.043   -0.009
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zdegree           0.915    0.031   29.792    0.000    0.855    0.976
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     Zgcse             1.000    0.018   56.957    0.000    0.965    1.034
##     sex.gcse          0.492    0.009   56.957    0.000    0.475    0.509
## 
## R-Square:
##                    Estimate
##     Zdegree           0.129
standardizedsolution(modela2.degreefit)
##         lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1   Zdegree  ~     sex1  -0.003 0.029  -0.107  0.915   -0.059    0.053
## 2   Zdegree  ~    Zgcse   0.416 0.034  12.152  0.000    0.349    0.483
## 3   Zdegree  ~ sex.gcse  -0.090 0.044  -2.044  0.041   -0.176   -0.004
## 4   Zdegree ~~  Zdegree   0.871 0.019  45.920  0.000    0.834    0.908
## 5      sex1 ~~     sex1   1.000 0.000      NA     NA    1.000    1.000
## 6      sex1 ~~    Zgcse  -0.053 0.012  -4.250  0.000   -0.077   -0.028
## 7      sex1 ~~ sex.gcse  -0.039 0.012  -3.182  0.001   -0.064   -0.015
## 8     Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 9     Zgcse ~~ sex.gcse   0.702 0.006 111.585  0.000    0.690    0.715
## 10 sex.gcse ~~ sex.gcse   1.000 0.000      NA     NA    1.000    1.000
## 11  Zdegree ~1           -0.187 0.032  -5.804  0.000   -0.250   -0.124
## 12     sex1 ~1            0.950 0.015  63.509  0.000    0.920    0.979
## 13    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
## 14 sex.gcse ~1           -0.037 0.012  -3.016  0.003   -0.062   -0.013
modelb1.degree <- 'Zdegree ~ SESscore + Zgcse'
modelb1.degreefit <- sem(modelb1.degree, data = df, missing = "fiml", fixed.x = FALSE)
summary(modelb1.degreefit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 13 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                               149.284
##   Degrees of freedom                                 2
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -19420.100
##   Loglikelihood unrestricted model (H1)     -19420.100
##                                                       
##   Akaike (AIC)                               38858.201
##   Bayesian (BIC)                             38919.200
##   Sample-size adjusted Bayesian (SABIC)      38890.600
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zdegree ~                                                             
##     SESscore          0.012    0.028    0.431    0.666   -0.043    0.068
##     Zgcse             0.372    0.033   11.297    0.000    0.308    0.437
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.425    0.000    0.422    0.473
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zdegree          -0.196    0.028   -7.094    0.000   -0.251   -0.142
##     SESscore         -0.034    0.012   -2.915    0.004   -0.057   -0.011
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zdegree           0.919    0.031   29.792    0.000    0.858    0.979
##     SESscore          0.874    0.016   56.320    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zdegree           0.135
standardizedsolution(modelb1.degreefit)
##        lhs op      rhs est.std    se      z pvalue ci.lower ci.upper
## 1  Zdegree  ~ SESscore   0.011 0.026  0.431  0.666   -0.039    0.062
## 2  Zdegree  ~    Zgcse   0.361 0.029 12.428  0.000    0.304    0.418
## 3  Zdegree ~~  Zdegree   0.865 0.019 45.123  0.000    0.828    0.903
## 4 SESscore ~~ SESscore   1.000 0.000     NA     NA    1.000    1.000
## 5 SESscore ~~    Zgcse   0.478 0.010 49.311  0.000    0.459    0.497
## 6    Zgcse ~~    Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 7  Zdegree ~1           -0.191 0.026 -7.358  0.000   -0.241   -0.140
## 8 SESscore ~1           -0.036 0.013 -2.914  0.004   -0.061   -0.012
## 9    Zgcse ~1            0.000 0.012  0.000  1.000   -0.024    0.024
modelb2.degree <- 'Zdegree ~ SESscore + Zgcse + SES.gcse'
modelb2.degreefit <- sem(modelb2.degree, data = df, missing = "fiml", fixed.x = FALSE)
summary(modelb2.degreefit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 15 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        14
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                               152.430
##   Degrees of freedom                                 3
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -28136.718
##   Loglikelihood unrestricted model (H1)     -28136.718
##                                                       
##   Akaike (AIC)                               56301.435
##   Bayesian (BIC)                             56396.323
##   Sample-size adjusted Bayesian (SABIC)      56351.835
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zdegree ~                                                             
##     SESscore          0.041    0.033    1.248    0.212   -0.023    0.105
##     Zgcse             0.385    0.034   11.428    0.000    0.319    0.451
##     SES.gcse         -0.061    0.034   -1.776    0.076   -0.128    0.006
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.426    0.000    0.422    0.473
##     SES.gcse         -0.013    0.011   -1.120    0.263   -0.035    0.009
##   Zgcse ~~                                                              
##     SES.gcse         -0.118    0.012   -9.669    0.000   -0.142   -0.094
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zdegree          -0.186    0.028   -6.599    0.000   -0.242   -0.131
##     SESscore         -0.034    0.012   -2.913    0.004   -0.057   -0.011
##     Zgcse            -0.000    0.012   -0.001    0.999   -0.024    0.024
##     SES.gcse          0.444    0.012   36.803    0.000    0.420    0.467
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zdegree           0.917    0.031   29.792    0.000    0.857    0.977
##     SESscore          0.874    0.016   56.319    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     SES.gcse          0.925    0.016   56.378    0.000    0.893    0.957
## 
## R-Square:
##                    Estimate
##     Zdegree           0.158
standardizedsolution(modelb2.degreefit)
##         lhs op      rhs est.std    se      z pvalue ci.lower ci.upper
## 1   Zdegree  ~ SESscore   0.036 0.029  1.255  0.209   -0.020    0.093
## 2   Zdegree  ~    Zgcse   0.369 0.029 12.864  0.000    0.312    0.425
## 3   Zdegree  ~ SES.gcse  -0.056 0.031 -1.803  0.071   -0.117    0.005
## 4   Zdegree ~~  Zdegree   0.842 0.025 33.842  0.000    0.793    0.890
## 5  SESscore ~~ SESscore   1.000 0.000     NA     NA    1.000    1.000
## 6  SESscore ~~    Zgcse   0.478 0.010 49.314  0.000    0.459    0.497
## 7  SESscore ~~ SES.gcse  -0.014 0.013 -1.120  0.263   -0.039    0.011
## 8     Zgcse ~~    Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 9     Zgcse ~~ SES.gcse  -0.123 0.012 -9.887  0.000   -0.147   -0.098
## 10 SES.gcse ~~ SES.gcse   1.000 0.000     NA     NA    1.000    1.000
## 11  Zdegree ~1           -0.178 0.026 -6.743  0.000   -0.230   -0.127
## 12 SESscore ~1           -0.036 0.013 -2.913  0.004   -0.061   -0.012
## 13    Zgcse ~1            0.000 0.012 -0.001  0.999   -0.024    0.024
## 14 SES.gcse ~1            0.461 0.013 35.005  0.000    0.436    0.487
#get change in R2 for models with vs. w/0 moderation (modela1 vs. a2 and b1 vs b2) 
(PE.modela1.degree <- parameterEstimates(modela1.degreefit, rsquare = TRUE)) 
##        lhs op     rhs    est    se      z pvalue ci.lower ci.upper
## 1  Zdegree  ~    sex1 -0.079 0.048 -1.652  0.099   -0.172    0.015
## 2  Zdegree  ~   Zgcse  0.381 0.030 12.562  0.000    0.322    0.441
## 3  Zdegree ~~ Zdegree  0.917 0.031 29.791  0.000    0.857    0.978
## 4     sex1 ~~    sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 5     sex1 ~~   Zgcse -0.026 0.006 -4.232  0.000   -0.038   -0.014
## 6    Zgcse ~~   Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 7  Zdegree ~1         -0.170 0.032 -5.325  0.000   -0.233   -0.107
## 8     sex1 ~1          0.474 0.006 76.503  0.000    0.462    0.486
## 9    Zgcse ~1          0.000 0.012  0.000  1.000   -0.024    0.024
## 10 Zdegree r2 Zdegree  0.139    NA     NA     NA       NA       NA
PE.modela1.degree$est[PE.modela1.degree$op == "r2"]
## [1] 0.139219
(PE.modela2.degree <- parameterEstimates(modela2.degreefit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1   Zdegree  ~     sex1 -0.006 0.059 -0.107  0.915   -0.122    0.109
## 2   Zdegree  ~    Zgcse  0.426 0.037 11.392  0.000    0.353    0.500
## 3   Zdegree  ~ sex.gcse -0.131 0.064 -2.052  0.040   -0.256   -0.006
## 4   Zdegree ~~  Zdegree  0.915 0.031 29.792  0.000    0.855    0.976
## 5      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 6      sex1 ~~    Zgcse -0.026 0.006 -4.232  0.000   -0.038   -0.014
## 7      sex1 ~~ sex.gcse -0.014 0.004 -3.174  0.002   -0.022   -0.005
## 8     Zgcse ~~    Zgcse  1.000 0.018 56.957  0.000    0.965    1.034
## 9     Zgcse ~~ sex.gcse  0.492 0.011 46.290  0.000    0.471    0.513
## 10 sex.gcse ~~ sex.gcse  0.492 0.009 56.957  0.000    0.475    0.509
## 11  Zdegree ~1          -0.192 0.034 -5.708  0.000   -0.258   -0.126
## 12     sex1 ~1           0.474 0.006 76.502  0.000    0.462    0.486
## 13    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 14 sex.gcse ~1          -0.026 0.009 -3.017  0.003   -0.043   -0.009
## 15  Zdegree r2  Zdegree  0.129    NA     NA     NA       NA       NA
PE.modela2.degree$est[PE.modela2.degree$op == "r2"]
## [1] 0.1287065
(PE.modelb1.degree <- parameterEstimates(modelb1.degreefit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1   Zdegree  ~ SESscore  0.012 0.028  0.431  0.666   -0.043    0.068
## 2   Zdegree  ~    Zgcse  0.372 0.033 11.297  0.000    0.308    0.437
## 3   Zdegree ~~  Zdegree  0.919 0.031 29.792  0.000    0.858    0.979
## 4  SESscore ~~ SESscore  0.874 0.016 56.320  0.000    0.844    0.905
## 5  SESscore ~~    Zgcse  0.447 0.013 34.425  0.000    0.422    0.473
## 6     Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 7   Zdegree ~1          -0.196 0.028 -7.094  0.000   -0.251   -0.142
## 8  SESscore ~1          -0.034 0.012 -2.915  0.004   -0.057   -0.011
## 9     Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 10  Zdegree r2  Zdegree  0.135    NA     NA     NA       NA       NA
PE.modelb1.degree$est[PE.modelb1.degree$op == "r2"]
## [1] 0.1345458
(PE.modelb2.degree <- parameterEstimates(modelb2.degreefit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1   Zdegree  ~ SESscore  0.041 0.033  1.248  0.212   -0.023    0.105
## 2   Zdegree  ~    Zgcse  0.385 0.034 11.428  0.000    0.319    0.451
## 3   Zdegree  ~ SES.gcse -0.061 0.034 -1.776  0.076   -0.128    0.006
## 4   Zdegree ~~  Zdegree  0.917 0.031 29.792  0.000    0.857    0.977
## 5  SESscore ~~ SESscore  0.874 0.016 56.319  0.000    0.844    0.905
## 6  SESscore ~~    Zgcse  0.447 0.013 34.426  0.000    0.422    0.473
## 7  SESscore ~~ SES.gcse -0.013 0.011 -1.120  0.263   -0.035    0.009
## 8     Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 9     Zgcse ~~ SES.gcse -0.118 0.012 -9.669  0.000   -0.142   -0.094
## 10 SES.gcse ~~ SES.gcse  0.925 0.016 56.378  0.000    0.893    0.957
## 11  Zdegree ~1          -0.186 0.028 -6.599  0.000   -0.242   -0.131
## 12 SESscore ~1          -0.034 0.012 -2.913  0.004   -0.057   -0.011
## 13    Zgcse ~1           0.000 0.012 -0.001  0.999   -0.024    0.024
## 14 SES.gcse ~1           0.444 0.012 36.803  0.000    0.420    0.467
## 15  Zdegree r2  Zdegree  0.158    NA     NA     NA       NA       NA
PE.modelb2.degree$est[PE.modelb2.degree$op == "r2"]
## [1] 0.1582521
r2diffa.degree <- (PE.modela2.degree$est[PE.modela2.degree$op == "r2"] - PE.modela1.degree$est[PE.modela1.degree$op == "r2"])
print(r2diffa.degree)    #difference modela1 vs a2, incremental explained variance by sexxGCSE
## [1] -0.0105125
r2diffb.degree <- (PE.modelb2.degree$est[PE.modelb2.degree$op == "r2"] - PE.modelb1.degree$est[PE.modelb1.degree$op == "r2"])
print(r2diffb.degree)    #difference modelb1 vs b2, incremental explained variance by SESxGCSE
## [1] 0.02370632
modela1.ocprestige <- 'Zsoc ~ sex1 + Zgcse'
modela1.ocprestigefit <- sem(modela1.ocprestige, data = df, missing = "fiml", fixed.x = FALSE)
summary(modela1.ocprestigefit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 16 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                          6488
##   Number of missing patterns                         2
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                               159.936
##   Degrees of freedom                                 2
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -16208.769
##   Loglikelihood unrestricted model (H1)     -16208.769
##                                                       
##   Akaike (AIC)                               32435.538
##   Bayesian (BIC)                             32496.538
##   Sample-size adjusted Bayesian (SABIC)      32467.938
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zsoc ~                                                                
##     sex1              0.168    0.048    3.469    0.001    0.073    0.262
##     Zgcse             0.316    0.025   12.485    0.000    0.267    0.366
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsoc             -0.054    0.029   -1.845    0.065   -0.111    0.003
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsoc              0.909    0.031   29.034    0.000    0.848    0.970
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zsoc              0.103
standardizedsolution(modela1.ocprestigefit)
##     lhs op   rhs est.std    se      z pvalue ci.lower ci.upper
## 1  Zsoc  ~  sex1   0.083 0.024  3.480  0.001    0.036    0.130
## 2  Zsoc  ~ Zgcse   0.314 0.023 13.447  0.000    0.269    0.360
## 3  Zsoc ~~  Zsoc   0.897 0.015 60.870  0.000    0.868    0.926
## 4  sex1 ~~  sex1   1.000 0.000     NA     NA    1.000    1.000
## 5  sex1 ~~ Zgcse  -0.053 0.012 -4.250  0.000   -0.077   -0.028
## 6 Zgcse ~~ Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 7  Zsoc ~1        -0.053 0.029 -1.847  0.065   -0.110    0.003
## 8  sex1 ~1         0.950 0.015 63.509  0.000    0.920    0.979
## 9 Zgcse ~1         0.000 0.012  0.000  1.000   -0.024    0.024
modela2.ocprestige <- 'Zsoc ~ sex1 + Zgcse + sex.gcse'
modela2.ocprestigefit <- sem(modela2.ocprestige, data = df, missing = "fiml", fixed.x = FALSE)
summary(modela2.ocprestigefit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 26 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        14
## 
##   Number of observations                          6488
##   Number of missing patterns                         2
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                               162.480
##   Degrees of freedom                                 3
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -20906.173
##   Loglikelihood unrestricted model (H1)     -20906.173
##                                                       
##   Akaike (AIC)                               41840.346
##   Bayesian (BIC)                             41935.234
##   Sample-size adjusted Bayesian (SABIC)      41890.746
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zsoc ~                                                                
##     sex1              0.170    0.048    3.509    0.000    0.075    0.264
##     Zgcse             0.283    0.033    8.628    0.000    0.219    0.347
##     sex.gcse          0.082    0.052    1.596    0.110   -0.019    0.184
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     sex.gcse         -0.014    0.004   -3.174    0.002   -0.022   -0.005
##   Zgcse ~~                                                              
##     sex.gcse          0.492    0.011   46.289    0.000    0.471    0.513
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsoc             -0.054    0.029   -1.870    0.061   -0.111    0.003
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
##     sex.gcse         -0.026    0.009   -3.018    0.003   -0.043   -0.009
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsoc              0.908    0.031   29.034    0.000    0.846    0.969
##     sex1              0.249    0.004   56.957    0.000    0.241    0.258
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     sex.gcse          0.492    0.009   56.956    0.000    0.475    0.509
## 
## R-Square:
##                    Estimate
##     Zsoc              0.109
standardizedsolution(modela2.ocprestigefit)
##         lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1      Zsoc  ~     sex1   0.084 0.024   3.521  0.000    0.037    0.131
## 2      Zsoc  ~    Zgcse   0.281 0.032   8.856  0.000    0.218    0.343
## 3      Zsoc  ~ sex.gcse   0.057 0.036   1.602  0.109   -0.013    0.127
## 4      Zsoc ~~     Zsoc   0.891 0.016  57.242  0.000    0.861    0.922
## 5      sex1 ~~     sex1   1.000 0.000      NA     NA    1.000    1.000
## 6      sex1 ~~    Zgcse  -0.053 0.012  -4.249  0.000   -0.077   -0.028
## 7      sex1 ~~ sex.gcse  -0.039 0.012  -3.182  0.001   -0.064   -0.015
## 8     Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 9     Zgcse ~~ sex.gcse   0.702 0.006 111.585  0.000    0.690    0.715
## 10 sex.gcse ~~ sex.gcse   1.000 0.000      NA     NA    1.000    1.000
## 11     Zsoc ~1           -0.054 0.029  -1.872  0.061   -0.110    0.003
## 12     sex1 ~1            0.950 0.015  63.510  0.000    0.920    0.979
## 13    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
## 14 sex.gcse ~1           -0.037 0.012  -3.017  0.003   -0.062   -0.013
modelb1.ocprestige <- 'Zsoc ~ SESscore + Zgcse'
modelb1.ocprestigefit <- sem(modelb1.ocprestige, data = df, missing = "fiml", fixed.x = FALSE)
summary(modelb1.ocprestigefit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 14 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                               154.298
##   Degrees of freedom                                 2
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -19291.308
##   Loglikelihood unrestricted model (H1)     -19291.308
##                                                       
##   Akaike (AIC)                               38600.615
##   Bayesian (BIC)                             38661.615
##   Sample-size adjusted Bayesian (SABIC)      38633.015
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zsoc ~                                                                
##     SESscore          0.073    0.029    2.523    0.012    0.016    0.130
##     Zgcse             0.285    0.028   10.059    0.000    0.229    0.340
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.426    0.000    0.422    0.473
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsoc              0.018    0.024    0.749    0.454   -0.029    0.064
##     SESscore         -0.034    0.012   -2.918    0.004   -0.057   -0.011
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsoc              0.912    0.031   29.033    0.000    0.850    0.974
##     SESscore          0.874    0.016   56.320    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zsoc              0.103
standardizedsolution(modelb1.ocprestigefit)
##        lhs op      rhs est.std    se      z pvalue ci.lower ci.upper
## 1     Zsoc  ~ SESscore   0.068 0.027  2.529  0.011    0.015    0.120
## 2     Zsoc  ~    Zgcse   0.282 0.027 10.559  0.000    0.230    0.335
## 3     Zsoc ~~     Zsoc   0.897 0.015 60.119  0.000    0.868    0.927
## 4 SESscore ~~ SESscore   1.000 0.000     NA     NA    1.000    1.000
## 5 SESscore ~~    Zgcse   0.478 0.010 49.313  0.000    0.459    0.497
## 6    Zgcse ~~    Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 7     Zsoc ~1            0.018 0.023  0.749  0.454   -0.028    0.064
## 8 SESscore ~1           -0.037 0.013 -2.917  0.004   -0.061   -0.012
## 9    Zgcse ~1            0.000 0.012  0.000  1.000   -0.024    0.024
modelb2.ocprestige <- 'Zsoc ~ SESscore + Zgcse + SES.gcse'
modelb2.ocprestigefit <- sem(modelb2.ocprestige, data = df, missing = "fiml", fixed.x = FALSE)
summary(modelb2.ocprestigefit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 15 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        14
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                               160.578
##   Degrees of freedom                                 3
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -28006.358
##   Loglikelihood unrestricted model (H1)     -28006.358
##                                                       
##   Akaike (AIC)                               56040.717
##   Bayesian (BIC)                             56135.605
##   Sample-size adjusted Bayesian (SABIC)      56091.116
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zsoc ~                                                                
##     SESscore          0.077    0.029    2.674    0.007    0.021    0.134
##     Zgcse             0.273    0.029    9.511    0.000    0.216    0.329
##     SES.gcse         -0.068    0.027   -2.508    0.012   -0.122   -0.015
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.426    0.000    0.422    0.473
##     SES.gcse         -0.013    0.011   -1.118    0.263   -0.035    0.010
##   Zgcse ~~                                                              
##     SES.gcse         -0.118    0.012   -9.666    0.000   -0.142   -0.094
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsoc              0.043    0.026    1.677    0.094   -0.007    0.093
##     SESscore         -0.034    0.012   -2.918    0.004   -0.057   -0.011
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
##     SES.gcse          0.444    0.012   36.807    0.000    0.420    0.467
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsoc              0.909    0.031   29.032    0.000    0.847    0.970
##     SESscore          0.874    0.016   56.320    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     SES.gcse          0.925    0.016   56.379    0.000    0.893    0.957
## 
## R-Square:
##                    Estimate
##     Zsoc              0.106
standardizedsolution(modelb2.ocprestigefit)
##         lhs op      rhs est.std    se      z pvalue ci.lower ci.upper
## 1      Zsoc  ~ SESscore   0.072 0.027  2.682  0.007    0.019    0.124
## 2      Zsoc  ~    Zgcse   0.271 0.027  9.927  0.000    0.217    0.324
## 3      Zsoc  ~ SES.gcse  -0.065 0.026 -2.514  0.012   -0.116   -0.014
## 4      Zsoc ~~     Zsoc   0.894 0.015 59.594  0.000    0.865    0.924
## 5  SESscore ~~ SESscore   1.000 0.000     NA     NA    1.000    1.000
## 6  SESscore ~~    Zgcse   0.478 0.010 49.313  0.000    0.459    0.497
## 7  SESscore ~~ SES.gcse  -0.014 0.013 -1.119  0.263   -0.039    0.011
## 8     Zgcse ~~    Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 9     Zgcse ~~ SES.gcse  -0.123 0.012 -9.884  0.000   -0.147   -0.098
## 10 SES.gcse ~~ SES.gcse   1.000 0.000     NA     NA    1.000    1.000
## 11     Zsoc ~1            0.043 0.025  1.679  0.093   -0.007    0.093
## 12 SESscore ~1           -0.037 0.013 -2.917  0.004   -0.061   -0.012
## 13    Zgcse ~1            0.000 0.012  0.000  1.000   -0.024    0.024
## 14 SES.gcse ~1            0.462 0.013 35.009  0.000    0.436    0.487
#get change in R2 for models with vs. w/0 moderation (modela1 vs. a2 and b1 vs b2) 
(PE.modela1.ocprestige <- parameterEstimates(modela1.ocprestigefit, rsquare = TRUE)) 
##      lhs op   rhs    est    se      z pvalue ci.lower ci.upper
## 1   Zsoc  ~  sex1  0.168 0.048  3.469  0.001    0.073    0.262
## 2   Zsoc  ~ Zgcse  0.316 0.025 12.485  0.000    0.267    0.366
## 3   Zsoc ~~  Zsoc  0.909 0.031 29.034  0.000    0.848    0.970
## 4   sex1 ~~  sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 5   sex1 ~~ Zgcse -0.026 0.006 -4.232  0.000   -0.038   -0.014
## 6  Zgcse ~~ Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 7   Zsoc ~1       -0.054 0.029 -1.845  0.065   -0.111    0.003
## 8   sex1 ~1        0.474 0.006 76.503  0.000    0.462    0.486
## 9  Zgcse ~1        0.000 0.012  0.000  1.000   -0.024    0.024
## 10  Zsoc r2  Zsoc  0.103    NA     NA     NA       NA       NA
PE.modela1.ocprestige$est[PE.modela1.ocprestige$op == "r2"]
## [1] 0.102987
(PE.modela2.ocprestige <- parameterEstimates(modela2.ocprestigefit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1      Zsoc  ~     sex1  0.170 0.048  3.509  0.000    0.075    0.264
## 2      Zsoc  ~    Zgcse  0.283 0.033  8.628  0.000    0.219    0.347
## 3      Zsoc  ~ sex.gcse  0.082 0.052  1.596  0.110   -0.019    0.184
## 4      Zsoc ~~     Zsoc  0.908 0.031 29.034  0.000    0.846    0.969
## 5      sex1 ~~     sex1  0.249 0.004 56.957  0.000    0.241    0.258
## 6      sex1 ~~    Zgcse -0.026 0.006 -4.232  0.000   -0.038   -0.014
## 7      sex1 ~~ sex.gcse -0.014 0.004 -3.174  0.002   -0.022   -0.005
## 8     Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 9     Zgcse ~~ sex.gcse  0.492 0.011 46.289  0.000    0.471    0.513
## 10 sex.gcse ~~ sex.gcse  0.492 0.009 56.956  0.000    0.475    0.509
## 11     Zsoc ~1          -0.054 0.029 -1.870  0.061   -0.111    0.003
## 12     sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 13    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 14 sex.gcse ~1          -0.026 0.009 -3.018  0.003   -0.043   -0.009
## 15     Zsoc r2     Zsoc  0.109    NA     NA     NA       NA       NA
PE.modela2.ocprestige$est[PE.modela2.ocprestige$op == "r2"]
## [1] 0.1087385
(PE.modelb1.ocprestige <- parameterEstimates(modelb1.ocprestigefit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1      Zsoc  ~ SESscore  0.073 0.029  2.523  0.012    0.016    0.130
## 2      Zsoc  ~    Zgcse  0.285 0.028 10.059  0.000    0.229    0.340
## 3      Zsoc ~~     Zsoc  0.912 0.031 29.033  0.000    0.850    0.974
## 4  SESscore ~~ SESscore  0.874 0.016 56.320  0.000    0.844    0.905
## 5  SESscore ~~    Zgcse  0.447 0.013 34.426  0.000    0.422    0.473
## 6     Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 7      Zsoc ~1           0.018 0.024  0.749  0.454   -0.029    0.064
## 8  SESscore ~1          -0.034 0.012 -2.918  0.004   -0.057   -0.011
## 9     Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 10     Zsoc r2     Zsoc  0.103    NA     NA     NA       NA       NA
PE.modelb1.ocprestige$est[PE.modelb1.ocprestige$op == "r2"]
## [1] 0.1026571
(PE.modelb2.ocprestige <- parameterEstimates(modelb2.ocprestigefit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1      Zsoc  ~ SESscore  0.077 0.029  2.674  0.007    0.021    0.134
## 2      Zsoc  ~    Zgcse  0.273 0.029  9.511  0.000    0.216    0.329
## 3      Zsoc  ~ SES.gcse -0.068 0.027 -2.508  0.012   -0.122   -0.015
## 4      Zsoc ~~     Zsoc  0.909 0.031 29.032  0.000    0.847    0.970
## 5  SESscore ~~ SESscore  0.874 0.016 56.320  0.000    0.844    0.905
## 6  SESscore ~~    Zgcse  0.447 0.013 34.426  0.000    0.422    0.473
## 7  SESscore ~~ SES.gcse -0.013 0.011 -1.118  0.263   -0.035    0.010
## 8     Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 9     Zgcse ~~ SES.gcse -0.118 0.012 -9.666  0.000   -0.142   -0.094
## 10 SES.gcse ~~ SES.gcse  0.925 0.016 56.379  0.000    0.893    0.957
## 11     Zsoc ~1           0.043 0.026  1.677  0.094   -0.007    0.093
## 12 SESscore ~1          -0.034 0.012 -2.918  0.004   -0.057   -0.011
## 13    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 14 SES.gcse ~1           0.444 0.012 36.807  0.000    0.420    0.467
## 15     Zsoc r2     Zsoc  0.106    NA     NA     NA       NA       NA
PE.modelb2.ocprestige$est[PE.modelb2.ocprestige$op == "r2"]
## [1] 0.1055931
r2diffa.ocprestige <- (PE.modela2.ocprestige$est[PE.modela2.ocprestige$op == "r2"] - PE.modela1.ocprestige$est[PE.modela1.ocprestige$op == "r2"])
print(r2diffa.ocprestige)    #difference modela1 vs a2, incremental explained variance by sexxGCSE
## [1] 0.005751535
r2diffb.ocprestige <- (PE.modelb2.ocprestige$est[PE.modelb2.ocprestige$op == "r2"] - PE.modelb1.ocprestige$est[PE.modelb1.ocprestige$op == "r2"])
print(r2diffb.ocprestige)    #difference modelb1 vs b2, incremental explained variance by SESxGCSE
## [1] 0.002936041
modela1.inc <- 'Zinc ~ sex1 + Zgcse'
modela1.incfit <- sem(modela1.inc, data = df, missing = "fiml", fixed.x = FALSE)
summary(modela1.incfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 16 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                          6488
##   Number of missing patterns                         2
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                               130.920
##   Degrees of freedom                                 2
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -16499.970
##   Loglikelihood unrestricted model (H1)     -16499.970
##                                                       
##   Akaike (AIC)                               33017.940
##   Bayesian (BIC)                             33078.940
##   Sample-size adjusted Bayesian (SABIC)      33050.340
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zinc ~                                                                
##     sex1              0.388    0.046    8.359    0.000    0.297    0.479
##     Zgcse             0.192    0.024    8.035    0.000    0.145    0.239
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zinc             -0.132    0.028   -4.751    0.000   -0.187   -0.078
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zinc              0.932    0.030   30.668    0.000    0.873    0.992
##     sex1              0.249    0.004   56.957    0.000    0.241    0.258
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zinc              0.070
standardizedsolution(modela1.incfit)
##     lhs op   rhs est.std    se      z pvalue ci.lower ci.upper
## 1  Zinc  ~  sex1   0.194 0.023  8.561      0    0.149    0.238
## 2  Zinc  ~ Zgcse   0.192 0.023  8.232      0    0.146    0.237
## 3  Zinc ~~  Zinc   0.930 0.011 80.927      0    0.907    0.952
## 4  sex1 ~~  sex1   1.000 0.000     NA     NA    1.000    1.000
## 5  sex1 ~~ Zgcse  -0.053 0.012 -4.250      0   -0.077   -0.028
## 6 Zgcse ~~ Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 7  Zinc ~1        -0.132 0.028 -4.791      0   -0.186   -0.078
## 8  sex1 ~1         0.950 0.015 63.510      0    0.920    0.979
## 9 Zgcse ~1         0.000 0.012  0.000      1   -0.024    0.024
modela2.inc <- 'Zinc ~ sex1 + Zgcse + sex.gcse'
modela2.incfit <- sem(modela2.inc, data = df, missing = "fiml", fixed.x = FALSE)
summary(modela2.incfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 26 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        14
## 
##   Number of observations                          6488
##   Number of missing patterns                         2
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                               131.905
##   Degrees of freedom                                 3
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -21198.154
##   Loglikelihood unrestricted model (H1)     -21198.154
##                                                       
##   Akaike (AIC)                               42424.308
##   Bayesian (BIC)                             42519.195
##   Sample-size adjusted Bayesian (SABIC)      42474.707
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zinc ~                                                                
##     sex1              0.387    0.046    8.322    0.000    0.295    0.478
##     Zgcse             0.211    0.031    6.883    0.000    0.151    0.271
##     sex.gcse         -0.049    0.049   -0.993    0.321   -0.144    0.047
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     sex.gcse         -0.014    0.004   -3.175    0.001   -0.022   -0.005
##   Zgcse ~~                                                              
##     sex.gcse          0.492    0.011   46.289    0.000    0.471    0.513
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zinc             -0.131    0.028   -4.721    0.000   -0.186   -0.077
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
##     sex.gcse         -0.026    0.009   -3.018    0.003   -0.043   -0.009
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zinc              0.932    0.030   30.668    0.000    0.872    0.991
##     sex1              0.249    0.004   56.955    0.000    0.241    0.258
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     sex.gcse          0.492    0.009   56.956    0.000    0.475    0.509
## 
## R-Square:
##                    Estimate
##     Zinc              0.069
standardizedsolution(modela2.incfit)
##         lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1      Zinc  ~     sex1   0.193 0.023   8.524  0.000    0.149    0.237
## 2      Zinc  ~    Zgcse   0.211 0.030   6.972  0.000    0.152    0.270
## 3      Zinc  ~ sex.gcse  -0.034 0.034  -0.992  0.321   -0.101    0.033
## 4      Zinc ~~     Zinc   0.931 0.011  81.833  0.000    0.909    0.953
## 5      sex1 ~~     sex1   1.000 0.000      NA     NA    1.000    1.000
## 6      sex1 ~~    Zgcse  -0.053 0.012  -4.249  0.000   -0.077   -0.028
## 7      sex1 ~~ sex.gcse  -0.039 0.012  -3.182  0.001   -0.064   -0.015
## 8     Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 9     Zgcse ~~ sex.gcse   0.702 0.006 111.586  0.000    0.690    0.715
## 10 sex.gcse ~~ sex.gcse   1.000 0.000      NA     NA    1.000    1.000
## 11     Zinc ~1           -0.131 0.028  -4.760  0.000   -0.185   -0.077
## 12     sex1 ~1            0.950 0.015  63.509  0.000    0.920    0.979
## 13    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
## 14 sex.gcse ~1           -0.037 0.012  -3.017  0.003   -0.062   -0.013
modelb1.inc <- 'Zinc ~ SESscore + Zgcse'
modelb1.incfit <- sem(modelb1.inc, data = df, missing = "fiml", fixed.x = FALSE)
summary(modelb1.incfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 11 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                65.546
##   Degrees of freedom                                 2
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -19612.377
##   Loglikelihood unrestricted model (H1)     -19612.377
##                                                       
##   Akaike (AIC)                               39242.754
##   Bayesian (BIC)                             39303.754
##   Sample-size adjusted Bayesian (SABIC)      39275.154
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zinc ~                                                                
##     SESscore          0.051    0.028    1.799    0.072   -0.005    0.106
##     Zgcse             0.172    0.027    6.346    0.000    0.119    0.225
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.425    0.000    0.422    0.473
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zinc              0.014    0.023    0.589    0.556   -0.031    0.059
##     SESscore         -0.034    0.012   -2.916    0.004   -0.057   -0.011
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zinc              0.965    0.031   30.668    0.000    0.904    1.027
##     SESscore          0.874    0.016   56.321    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zinc              0.039
standardizedsolution(modelb1.incfit)
##        lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1     Zinc  ~ SESscore   0.047 0.026   1.802  0.072   -0.004    0.099
## 2     Zinc  ~    Zgcse   0.172 0.027   6.457  0.000    0.120    0.224
## 3     Zinc ~~     Zinc   0.961 0.009 102.310  0.000    0.942    0.979
## 4 SESscore ~~ SESscore   1.000 0.000      NA     NA    1.000    1.000
## 5 SESscore ~~    Zgcse   0.478 0.010  49.310  0.000    0.459    0.497
## 6    Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 7     Zinc ~1            0.013 0.023   0.589  0.556   -0.031    0.058
## 8 SESscore ~1           -0.036 0.013  -2.916  0.004   -0.061   -0.012
## 9    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
modelb2.inc <- 'Zinc ~ SESscore + Zgcse + SES.gcse'
modelb2.incfit <- sem(modelb2.inc, data = df, missing = "fiml", fixed.x = FALSE)
summary(modelb2.incfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 13 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        14
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                66.287
##   Degrees of freedom                                 3
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -28330.197
##   Loglikelihood unrestricted model (H1)     -28330.197
##                                                       
##   Akaike (AIC)                               56688.394
##   Bayesian (BIC)                             56783.282
##   Sample-size adjusted Bayesian (SABIC)      56738.793
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zinc ~                                                                
##     SESscore          0.050    0.028    1.760    0.078   -0.006    0.105
##     Zgcse             0.176    0.027    6.402    0.000    0.122    0.230
##     SES.gcse          0.022    0.026    0.861    0.389   -0.028    0.073
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.425    0.000    0.422    0.473
##     SES.gcse         -0.013    0.011   -1.118    0.264   -0.035    0.010
##   Zgcse ~~                                                              
##     SES.gcse         -0.118    0.012   -9.664    0.000   -0.142   -0.094
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zinc              0.005    0.025    0.208    0.835   -0.044    0.054
##     SESscore         -0.034    0.012   -2.916    0.004   -0.057   -0.011
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
##     SES.gcse          0.444    0.012   36.802    0.000    0.420    0.467
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zinc              0.965    0.031   30.667    0.000    0.903    1.026
##     SESscore          0.874    0.016   56.321    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     SES.gcse          0.925    0.016   56.379    0.000    0.893    0.957
## 
## R-Square:
##                    Estimate
##     Zinc              0.040
standardizedsolution(modelb2.incfit)
##         lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1      Zinc  ~ SESscore   0.046 0.026   1.762  0.078   -0.005    0.098
## 2      Zinc  ~    Zgcse   0.176 0.027   6.518  0.000    0.123    0.228
## 3      Zinc  ~ SES.gcse   0.021 0.025   0.861  0.389   -0.027    0.070
## 4      Zinc ~~     Zinc   0.960 0.010 100.756  0.000    0.941    0.978
## 5  SESscore ~~ SESscore   1.000 0.000      NA     NA    1.000    1.000
## 6  SESscore ~~    Zgcse   0.478 0.010  49.310  0.000    0.459    0.497
## 7  SESscore ~~ SES.gcse  -0.014 0.013  -1.118  0.264   -0.039    0.011
## 8     Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 9     Zgcse ~~ SES.gcse  -0.123 0.012  -9.882  0.000   -0.147   -0.098
## 10 SES.gcse ~~ SES.gcse   1.000 0.000      NA     NA    1.000    1.000
## 11     Zinc ~1            0.005 0.025   0.208  0.835   -0.044    0.054
## 12 SESscore ~1           -0.036 0.013  -2.915  0.004   -0.061   -0.012
## 13    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
## 14 SES.gcse ~1            0.461 0.013  35.004  0.000    0.436    0.487
#get change in R2 for models with vs. w/0 moderation (modela1 vs. a2 and b1 vs b2) 
(PE.modela1.inc <- parameterEstimates(modela1.incfit, rsquare = TRUE)) 
##      lhs op   rhs    est    se      z pvalue ci.lower ci.upper
## 1   Zinc  ~  sex1  0.388 0.046  8.359      0    0.297    0.479
## 2   Zinc  ~ Zgcse  0.192 0.024  8.035      0    0.145    0.239
## 3   Zinc ~~  Zinc  0.932 0.030 30.668      0    0.873    0.992
## 4   sex1 ~~  sex1  0.249 0.004 56.957      0    0.241    0.258
## 5   sex1 ~~ Zgcse -0.026 0.006 -4.232      0   -0.038   -0.014
## 6  Zgcse ~~ Zgcse  1.000 0.018 56.956      0    0.965    1.034
## 7   Zinc ~1       -0.132 0.028 -4.751      0   -0.187   -0.078
## 8   sex1 ~1        0.474 0.006 76.503      0    0.462    0.486
## 9  Zgcse ~1        0.000 0.012  0.000      1   -0.024    0.024
## 10  Zinc r2  Zinc  0.070    NA     NA     NA       NA       NA
PE.modela1.inc$est[PE.modela1.inc$op == "r2"]
## [1] 0.07029591
(PE.modela2.inc <- parameterEstimates(modela2.incfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1      Zinc  ~     sex1  0.387 0.046  8.322  0.000    0.295    0.478
## 2      Zinc  ~    Zgcse  0.211 0.031  6.883  0.000    0.151    0.271
## 3      Zinc  ~ sex.gcse -0.049 0.049 -0.993  0.321   -0.144    0.047
## 4      Zinc ~~     Zinc  0.932 0.030 30.668  0.000    0.872    0.991
## 5      sex1 ~~     sex1  0.249 0.004 56.955  0.000    0.241    0.258
## 6      sex1 ~~    Zgcse -0.026 0.006 -4.232  0.000   -0.038   -0.014
## 7      sex1 ~~ sex.gcse -0.014 0.004 -3.175  0.001   -0.022   -0.005
## 8     Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 9     Zgcse ~~ sex.gcse  0.492 0.011 46.289  0.000    0.471    0.513
## 10 sex.gcse ~~ sex.gcse  0.492 0.009 56.956  0.000    0.475    0.509
## 11     Zinc ~1          -0.131 0.028 -4.721  0.000   -0.186   -0.077
## 12     sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 13    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 14 sex.gcse ~1          -0.026 0.009 -3.018  0.003   -0.043   -0.009
## 15     Zinc r2     Zinc  0.069    NA     NA     NA       NA       NA
PE.modela2.inc$est[PE.modela2.inc$op == "r2"]
## [1] 0.0690365
(PE.modelb1.inc <- parameterEstimates(modelb1.incfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1      Zinc  ~ SESscore  0.051 0.028  1.799  0.072   -0.005    0.106
## 2      Zinc  ~    Zgcse  0.172 0.027  6.346  0.000    0.119    0.225
## 3      Zinc ~~     Zinc  0.965 0.031 30.668  0.000    0.904    1.027
## 4  SESscore ~~ SESscore  0.874 0.016 56.321  0.000    0.844    0.905
## 5  SESscore ~~    Zgcse  0.447 0.013 34.425  0.000    0.422    0.473
## 6     Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 7      Zinc ~1           0.014 0.023  0.589  0.556   -0.031    0.059
## 8  SESscore ~1          -0.034 0.012 -2.916  0.004   -0.057   -0.011
## 9     Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 10     Zinc r2     Zinc  0.039    NA     NA     NA       NA       NA
PE.modelb1.inc$est[PE.modelb1.inc$op == "r2"]
## [1] 0.0394635
(PE.modelb2.inc <- parameterEstimates(modelb2.incfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1      Zinc  ~ SESscore  0.050 0.028  1.760  0.078   -0.006    0.105
## 2      Zinc  ~    Zgcse  0.176 0.027  6.402  0.000    0.122    0.230
## 3      Zinc  ~ SES.gcse  0.022 0.026  0.861  0.389   -0.028    0.073
## 4      Zinc ~~     Zinc  0.965 0.031 30.667  0.000    0.903    1.026
## 5  SESscore ~~ SESscore  0.874 0.016 56.321  0.000    0.844    0.905
## 6  SESscore ~~    Zgcse  0.447 0.013 34.425  0.000    0.422    0.473
## 7  SESscore ~~ SES.gcse -0.013 0.011 -1.118  0.264   -0.035    0.010
## 8     Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 9     Zgcse ~~ SES.gcse -0.118 0.012 -9.664  0.000   -0.142   -0.094
## 10 SES.gcse ~~ SES.gcse  0.925 0.016 56.379  0.000    0.893    0.957
## 11     Zinc ~1           0.005 0.025  0.208  0.835   -0.044    0.054
## 12 SESscore ~1          -0.034 0.012 -2.916  0.004   -0.057   -0.011
## 13    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 14 SES.gcse ~1           0.444 0.012 36.802  0.000    0.420    0.467
## 15     Zinc r2     Zinc  0.040    NA     NA     NA       NA       NA
PE.modelb2.inc$est[PE.modelb2.inc$op == "r2"]
## [1] 0.04025784
r2diffa.inc <- (PE.modela2.inc$est[PE.modela2.inc$op == "r2"] - PE.modela1.inc$est[PE.modela1.inc$op == "r2"])
print(r2diffa.inc)    #difference modela1 vs a2, incremental explained variance by sexxGCSE
## [1] -0.001259405
r2diffb.inc <- (PE.modelb2.inc$est[PE.modelb2.inc$op == "r2"] - PE.modelb1.inc$est[PE.modelb1.inc$op == "r2"])
print(r2diffb.inc)    #difference modelb1 vs b2, incremental explained variance by SESxGCSE
## [1] 0.0007943386
model1.mon <- 'Zmon ~ sex1 + SESscore'
model1.monfit <- sem(model1.mon, data = df, missing = "fiml", fixed.x = FALSE)
summary(model1.monfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 16 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                56.036
##   Degrees of freedom                                 2
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -18452.108
##   Loglikelihood unrestricted model (H1)     -18452.108
##                                                       
##   Akaike (AIC)                               36922.215
##   Bayesian (BIC)                             36983.215
##   Sample-size adjusted Bayesian (SABIC)      36954.615
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zmon ~                                                                
##     sex1             -0.232    0.034   -6.887    0.000   -0.298   -0.166
##     SESscore         -0.047    0.018   -2.652    0.008   -0.082   -0.012
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.013    0.006    2.288    0.022    0.002    0.025
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zmon              0.093    0.021    4.422    0.000    0.052    0.134
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.029    0.012   -2.514    0.012   -0.052   -0.006
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zmon              0.985    0.023   42.777    0.000    0.939    1.030
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.873    0.015   56.387    0.000    0.842    0.903
## 
## R-Square:
##                    Estimate
##     Zmon              0.016
standardizedsolution(model1.monfit)
##        lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1     Zmon  ~     sex1  -0.116 0.017  -6.945  0.000   -0.149   -0.083
## 2     Zmon  ~ SESscore  -0.044 0.017  -2.654  0.008   -0.077   -0.012
## 3     Zmon ~~     Zmon   0.984 0.004 237.936  0.000    0.976    0.992
## 4     sex1 ~~     sex1   1.000 0.000      NA     NA    1.000    1.000
## 5     sex1 ~~ SESscore   0.029 0.013   2.290  0.022    0.004    0.053
## 6 SESscore ~~ SESscore   1.000 0.000      NA     NA    1.000    1.000
## 7     Zmon ~1            0.093 0.021   4.441  0.000    0.052    0.133
## 8     sex1 ~1            0.950 0.015  63.510  0.000    0.920    0.979
## 9 SESscore ~1           -0.032 0.013  -2.514  0.012   -0.056   -0.007
modela1.mon <- 'Zmon ~ sex1 + Zgcse'
modela1.monfit <- sem(modela1.mon, data = df, missing = "fiml", fixed.x = FALSE)
summary(modela1.monfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 14 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                          6488
##   Number of missing patterns                         2
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                58.653
##   Degrees of freedom                                 2
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -19060.395
##   Loglikelihood unrestricted model (H1)     -19060.395
##                                                       
##   Akaike (AIC)                               38138.791
##   Bayesian (BIC)                             38199.790
##   Sample-size adjusted Bayesian (SABIC)      38171.190
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zmon ~                                                                
##     sex1             -0.238    0.034   -7.070    0.000   -0.304   -0.172
##     Zgcse             0.054    0.017    3.107    0.002    0.020    0.088
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zmon              0.081    0.021    3.813    0.000    0.039    0.122
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zmon              0.984    0.023   42.779    0.000    0.939    1.029
##     sex1              0.249    0.004   56.957    0.000    0.241    0.258
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zmon              0.018
standardizedsolution(modela1.monfit)
##     lhs op   rhs est.std    se       z pvalue ci.lower ci.upper
## 1  Zmon  ~  sex1  -0.119 0.017  -7.136  0.000   -0.151   -0.086
## 2  Zmon  ~ Zgcse   0.054 0.017   3.114  0.002    0.020    0.088
## 3  Zmon ~~  Zmon   0.982 0.005 215.636  0.000    0.973    0.991
## 4  sex1 ~~  sex1   1.000 0.000      NA     NA    1.000    1.000
## 5  sex1 ~~ Zgcse  -0.053 0.012  -4.250  0.000   -0.077   -0.028
## 6 Zgcse ~~ Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 7  Zmon ~1         0.081 0.021   3.824  0.000    0.039    0.122
## 8  sex1 ~1         0.950 0.015  63.510  0.000    0.920    0.979
## 9 Zgcse ~1         0.000 0.012   0.000  1.000   -0.024    0.024
modela2.mon <- 'Zmon ~ sex1 + Zgcse + sex.gcse'
modela2.monfit <- sem(modela2.mon, data = df, missing = "fiml", fixed.x = FALSE)
summary(modela2.monfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 20 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        14
## 
##   Number of observations                          6488
##   Number of missing patterns                         2
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                60.556
##   Degrees of freedom                                 3
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -23758.120
##   Loglikelihood unrestricted model (H1)     -23758.120
##                                                       
##   Akaike (AIC)                               47544.240
##   Bayesian (BIC)                             47639.128
##   Sample-size adjusted Bayesian (SABIC)      47594.640
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zmon ~                                                                
##     sex1             -0.228    0.034   -6.602    0.000   -0.295   -0.160
##     Zgcse             0.073    0.022    3.283    0.001    0.030    0.117
##     sex.gcse         -0.049    0.035   -1.379    0.168   -0.118    0.021
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     sex.gcse         -0.014    0.004   -3.175    0.002   -0.022   -0.005
##   Zgcse ~~                                                              
##     sex.gcse          0.492    0.011   46.289    0.000    0.471    0.513
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zmon              0.077    0.021    3.601    0.000    0.035    0.119
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
##     sex.gcse         -0.026    0.009   -3.018    0.003   -0.043   -0.009
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zmon              0.983    0.023   42.778    0.000    0.938    1.028
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     sex.gcse          0.492    0.009   56.956    0.000    0.475    0.509
## 
## R-Square:
##                    Estimate
##     Zmon              0.017
standardizedsolution(modela2.monfit)
##         lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1      Zmon  ~     sex1  -0.114 0.017  -6.658  0.000   -0.147   -0.080
## 2      Zmon  ~    Zgcse   0.073 0.022   3.286  0.001    0.030    0.117
## 3      Zmon  ~ sex.gcse  -0.034 0.025  -1.378  0.168   -0.083    0.014
## 4      Zmon ~~     Zmon   0.983 0.004 226.516  0.000    0.975    0.992
## 5      sex1 ~~     sex1   1.000 0.000      NA     NA    1.000    1.000
## 6      sex1 ~~    Zgcse  -0.053 0.012  -4.249  0.000   -0.077   -0.028
## 7      sex1 ~~ sex.gcse  -0.039 0.012  -3.182  0.001   -0.064   -0.015
## 8     Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 9     Zgcse ~~ sex.gcse   0.702 0.006 111.584  0.000    0.690    0.715
## 10 sex.gcse ~~ sex.gcse   1.000 0.000      NA     NA    1.000    1.000
## 11     Zmon ~1            0.077 0.021   3.612  0.000    0.035    0.119
## 12     sex1 ~1            0.950 0.015  63.509  0.000    0.920    0.979
## 13    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
## 14 sex.gcse ~1           -0.037 0.012  -3.017  0.003   -0.062   -0.013
modelb1.mon <- 'Zmon ~ SESscore + Zgcse'
modelb1.monfit <- sem(modelb1.mon, data = df, missing = "fiml", fixed.x = FALSE)
summary(modelb1.monfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 10 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                32.000
##   Degrees of freedom                                 2
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -22153.442
##   Loglikelihood unrestricted model (H1)     -22153.442
##                                                       
##   Akaike (AIC)                               44324.883
##   Bayesian (BIC)                             44385.883
##   Sample-size adjusted Bayesian (SABIC)      44357.283
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zmon ~                                                                
##     SESscore         -0.097    0.020   -4.803    0.000   -0.137   -0.057
##     Zgcse             0.097    0.020    4.930    0.000    0.059    0.136
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.415    0.000    0.421    0.472
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zmon             -0.014    0.017   -0.852    0.394   -0.047    0.019
##     SESscore         -0.034    0.012   -2.911    0.004   -0.057   -0.011
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zmon              0.991    0.023   42.773    0.000    0.946    1.036
##     SESscore          0.874    0.016   56.330    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zmon              0.009
standardizedsolution(modelb1.monfit)
##        lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1     Zmon  ~ SESscore  -0.091 0.019  -4.822  0.000   -0.128   -0.054
## 2     Zmon  ~    Zgcse   0.097 0.020   4.953  0.000    0.059    0.136
## 3     Zmon ~~     Zmon   0.991 0.003 304.307  0.000    0.984    0.997
## 4 SESscore ~~ SESscore   1.000 0.000      NA     NA    1.000    1.000
## 5 SESscore ~~    Zgcse   0.478 0.010  49.276  0.000    0.459    0.497
## 6    Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 7     Zmon ~1           -0.014 0.017  -0.852  0.394   -0.047    0.019
## 8 SESscore ~1           -0.036 0.013  -2.910  0.004   -0.061   -0.012
## 9    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
modelb2.mon <- 'Zmon ~ SESscore + Zgcse + SES.gcse'
modelb2.monfit <- sem(modelb2.mon, data = df, missing = "fiml", fixed.x = FALSE)
summary(modelb2.monfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 10 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        14
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                41.592
##   Degrees of freedom                                 3
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -30866.836
##   Loglikelihood unrestricted model (H1)     -30866.836
##                                                       
##   Akaike (AIC)                               61761.672
##   Bayesian (BIC)                             61856.560
##   Sample-size adjusted Bayesian (SABIC)      61812.072
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zmon ~                                                                
##     SESscore         -0.085    0.021   -4.147    0.000   -0.125   -0.045
##     Zgcse             0.094    0.020    4.772    0.000    0.056    0.133
##     SES.gcse         -0.058    0.019   -3.099    0.002   -0.094   -0.021
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.416    0.000    0.421    0.472
##     SES.gcse         -0.013    0.011   -1.122    0.262   -0.035    0.009
##   Zgcse ~~                                                              
##     SES.gcse         -0.118    0.012   -9.678    0.000   -0.142   -0.094
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zmon              0.010    0.019    0.543    0.587   -0.026    0.047
##     SESscore         -0.034    0.012   -2.911    0.004   -0.057   -0.011
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
##     SES.gcse          0.444    0.012   36.806    0.000    0.420    0.467
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zmon              0.988    0.023   42.772    0.000    0.943    1.034
##     SESscore          0.874    0.016   56.329    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     SES.gcse          0.925    0.016   56.376    0.000    0.893    0.957
## 
## R-Square:
##                    Estimate
##     Zmon              0.012
standardizedsolution(modelb2.monfit)
##         lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1      Zmon  ~ SESscore  -0.080 0.019  -4.157  0.000   -0.117   -0.042
## 2      Zmon  ~    Zgcse   0.094 0.020   4.794  0.000    0.056    0.133
## 3      Zmon  ~ SES.gcse  -0.055 0.018  -3.106  0.002   -0.090   -0.020
## 4      Zmon ~~     Zmon   0.988 0.004 259.151  0.000    0.980    0.995
## 5  SESscore ~~ SESscore   1.000 0.000      NA     NA    1.000    1.000
## 6  SESscore ~~    Zgcse   0.478 0.010  49.280  0.000    0.459    0.497
## 7  SESscore ~~ SES.gcse  -0.014 0.013  -1.122  0.262   -0.039    0.011
## 8     Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 9     Zgcse ~~ SES.gcse  -0.123 0.012  -9.897  0.000   -0.147   -0.098
## 10 SES.gcse ~~ SES.gcse   1.000 0.000      NA     NA    1.000    1.000
## 11     Zmon ~1            0.010 0.019   0.543  0.587   -0.026    0.047
## 12 SESscore ~1           -0.036 0.013  -2.911  0.004   -0.061   -0.012
## 13    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
## 14 SES.gcse ~1            0.462 0.013  35.008  0.000    0.436    0.487
#get change in R2 for models with vs. w/0 moderation (modela1 vs. a2 and b1 vs b2) 
(PE.modela1.mon <- parameterEstimates(modela1.monfit, rsquare = TRUE)) 
##      lhs op   rhs    est    se      z pvalue ci.lower ci.upper
## 1   Zmon  ~  sex1 -0.238 0.034 -7.070  0.000   -0.304   -0.172
## 2   Zmon  ~ Zgcse  0.054 0.017  3.107  0.002    0.020    0.088
## 3   Zmon ~~  Zmon  0.984 0.023 42.779  0.000    0.939    1.029
## 4   sex1 ~~  sex1  0.249 0.004 56.957  0.000    0.241    0.258
## 5   sex1 ~~ Zgcse -0.026 0.006 -4.232  0.000   -0.038   -0.014
## 6  Zgcse ~~ Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 7   Zmon ~1        0.081 0.021  3.813  0.000    0.039    0.122
## 8   sex1 ~1        0.474 0.006 76.503  0.000    0.462    0.486
## 9  Zgcse ~1        0.000 0.012  0.000  1.000   -0.024    0.024
## 10  Zmon r2  Zmon  0.018    NA     NA     NA       NA       NA
PE.modela1.mon$est[PE.modela1.mon$op == "r2"]
## [1] 0.01768206
(PE.modela2.mon <- parameterEstimates(modela2.monfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1      Zmon  ~     sex1 -0.228 0.034 -6.602  0.000   -0.295   -0.160
## 2      Zmon  ~    Zgcse  0.073 0.022  3.283  0.001    0.030    0.117
## 3      Zmon  ~ sex.gcse -0.049 0.035 -1.379  0.168   -0.118    0.021
## 4      Zmon ~~     Zmon  0.983 0.023 42.778  0.000    0.938    1.028
## 5      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 6      sex1 ~~    Zgcse -0.026 0.006 -4.232  0.000   -0.038   -0.014
## 7      sex1 ~~ sex.gcse -0.014 0.004 -3.175  0.002   -0.022   -0.005
## 8     Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 9     Zgcse ~~ sex.gcse  0.492 0.011 46.289  0.000    0.471    0.513
## 10 sex.gcse ~~ sex.gcse  0.492 0.009 56.956  0.000    0.475    0.509
## 11     Zmon ~1           0.077 0.021  3.601  0.000    0.035    0.119
## 12     sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 13    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 14 sex.gcse ~1          -0.026 0.009 -3.018  0.003   -0.043   -0.009
## 15     Zmon r2     Zmon  0.017    NA     NA     NA       NA       NA
PE.modela2.mon$est[PE.modela2.mon$op == "r2"]
## [1] 0.01651096
(PE.modelb1.mon <- parameterEstimates(modelb1.monfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1      Zmon  ~ SESscore -0.097 0.020 -4.803  0.000   -0.137   -0.057
## 2      Zmon  ~    Zgcse  0.097 0.020  4.930  0.000    0.059    0.136
## 3      Zmon ~~     Zmon  0.991 0.023 42.773  0.000    0.946    1.036
## 4  SESscore ~~ SESscore  0.874 0.016 56.330  0.000    0.844    0.905
## 5  SESscore ~~    Zgcse  0.447 0.013 34.415  0.000    0.421    0.472
## 6     Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 7      Zmon ~1          -0.014 0.017 -0.852  0.394   -0.047    0.019
## 8  SESscore ~1          -0.034 0.012 -2.911  0.004   -0.057   -0.011
## 9     Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 10     Zmon r2     Zmon  0.009    NA     NA     NA       NA       NA
PE.modelb1.mon$est[PE.modelb1.mon$op == "r2"]
## [1] 0.009271553
(PE.modelb2.mon <- parameterEstimates(modelb2.monfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1      Zmon  ~ SESscore -0.085 0.021 -4.147  0.000   -0.125   -0.045
## 2      Zmon  ~    Zgcse  0.094 0.020  4.772  0.000    0.056    0.133
## 3      Zmon  ~ SES.gcse -0.058 0.019 -3.099  0.002   -0.094   -0.021
## 4      Zmon ~~     Zmon  0.988 0.023 42.772  0.000    0.943    1.034
## 5  SESscore ~~ SESscore  0.874 0.016 56.329  0.000    0.844    0.905
## 6  SESscore ~~    Zgcse  0.447 0.013 34.416  0.000    0.421    0.472
## 7  SESscore ~~ SES.gcse -0.013 0.011 -1.122  0.262   -0.035    0.009
## 8     Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 9     Zgcse ~~ SES.gcse -0.118 0.012 -9.678  0.000   -0.142   -0.094
## 10 SES.gcse ~~ SES.gcse  0.925 0.016 56.376  0.000    0.893    0.957
## 11     Zmon ~1           0.010 0.019  0.543  0.587   -0.026    0.047
## 12 SESscore ~1          -0.034 0.012 -2.911  0.004   -0.057   -0.011
## 13    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 14 SES.gcse ~1           0.444 0.012 36.806  0.000    0.420    0.467
## 15     Zmon r2     Zmon  0.012    NA     NA     NA       NA       NA
PE.modelb2.mon$est[PE.modelb2.mon$op == "r2"]
## [1] 0.01228161
r2diffa.mon <- (PE.modela2.mon$est[PE.modela2.mon$op == "r2"] - PE.modela1.mon$est[PE.modela1.mon$op == "r2"])
print(r2diffa.mon)    #difference modela1 vs a2, incremental explained variance by sexxGCSE
## [1] -0.001171099
r2diffb.mon <- (PE.modelb2.mon$est[PE.modelb2.mon$op == "r2"] - PE.modelb1.mon$est[PE.modelb1.mon$op == "r2"])
print(r2diffb.mon)    #difference modelb1 vs b2, incremental explained variance by SESxGCSE
## [1] 0.003010057
modela1.fina <- 'Zfina ~ sex1 + Zgcse'
modela1.finafit <- sem(modela1.fina, data = df, missing = "fiml", fixed.x = FALSE)
summary(modela1.finafit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 13 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                          6488
##   Number of missing patterns                         2
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 3.181
##   Degrees of freedom                                 2
##   P-value                                        0.204
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -19090.969
##   Loglikelihood unrestricted model (H1)     -19090.969
##                                                       
##   Akaike (AIC)                               38199.938
##   Bayesian (BIC)                             38260.938
##   Sample-size adjusted Bayesian (SABIC)      38232.338
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zfina ~                                                               
##     sex1              0.059    0.034    1.732    0.083   -0.008    0.125
##     Zgcse             0.007    0.017    0.406    0.685   -0.027    0.041
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zfina            -0.024    0.021   -1.130    0.258   -0.066    0.018
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zfina             0.999    0.023   42.790    0.000    0.953    1.045
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zfina             0.001
standardizedsolution(modela1.finafit)
##     lhs op   rhs est.std    se        z pvalue ci.lower ci.upper
## 1 Zfina  ~  sex1   0.029 0.017    1.733  0.083   -0.004    0.063
## 2 Zfina  ~ Zgcse   0.007 0.017    0.406  0.685   -0.027    0.041
## 3 Zfina ~~ Zfina   0.999 0.001 1001.293  0.000    0.997    1.001
## 4  sex1 ~~  sex1   1.000 0.000       NA     NA    1.000    1.000
## 5  sex1 ~~ Zgcse  -0.053 0.012   -4.250  0.000   -0.077   -0.028
## 6 Zgcse ~~ Zgcse   1.000 0.000       NA     NA    1.000    1.000
## 7 Zfina ~1        -0.024 0.021   -1.131  0.258   -0.066    0.018
## 8  sex1 ~1         0.950 0.015   63.509  0.000    0.920    0.979
## 9 Zgcse ~1         0.000 0.012    0.000  1.000   -0.024    0.024
modela2.fina <- 'Zfina ~ sex1 + Zgcse + sex.gcse'
modela2.finafit <- sem(modela2.fina, data = df, missing = "fiml", fixed.x = FALSE)
summary(modela2.finafit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 20 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        14
## 
##   Number of observations                          6488
##   Number of missing patterns                         2
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 3.655
##   Degrees of freedom                                 3
##   P-value                                        0.301
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -23789.408
##   Loglikelihood unrestricted model (H1)     -23789.408
##                                                       
##   Akaike (AIC)                               47606.817
##   Bayesian (BIC)                             47701.705
##   Sample-size adjusted Bayesian (SABIC)      47657.216
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zfina ~                                                               
##     sex1              0.064    0.035    1.841    0.066   -0.004    0.132
##     Zgcse             0.017    0.022    0.749    0.454   -0.027    0.061
##     sex.gcse         -0.025    0.036   -0.689    0.491   -0.095    0.045
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     sex.gcse         -0.014    0.004   -3.175    0.001   -0.022   -0.005
##   Zgcse ~~                                                              
##     sex.gcse          0.492    0.011   46.289    0.000    0.471    0.513
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zfina            -0.026    0.022   -1.210    0.226   -0.068    0.016
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
##     sex.gcse         -0.026    0.009   -3.018    0.003   -0.043   -0.009
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zfina             0.999    0.023   42.790    0.000    0.953    1.044
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     sex.gcse          0.492    0.009   56.956    0.000    0.475    0.509
## 
## R-Square:
##                    Estimate
##     Zfina             0.001
standardizedsolution(modela2.finafit)
##         lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1     Zfina  ~     sex1   0.032 0.017   1.842  0.065   -0.002    0.066
## 2     Zfina  ~    Zgcse   0.017 0.022   0.749  0.454   -0.027    0.061
## 3     Zfina  ~ sex.gcse  -0.017 0.025  -0.689  0.491   -0.066    0.032
## 4     Zfina ~~    Zfina   0.999 0.001 790.092  0.000    0.996    1.001
## 5      sex1 ~~     sex1   1.000 0.000      NA     NA    1.000    1.000
## 6      sex1 ~~    Zgcse  -0.053 0.012  -4.250  0.000   -0.077   -0.028
## 7      sex1 ~~ sex.gcse  -0.039 0.012  -3.182  0.001   -0.064   -0.015
## 8     Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 9     Zgcse ~~ sex.gcse   0.702 0.006 111.585  0.000    0.690    0.715
## 10 sex.gcse ~~ sex.gcse   1.000 0.000      NA     NA    1.000    1.000
## 11    Zfina ~1           -0.026 0.022  -1.211  0.226   -0.068    0.016
## 12     sex1 ~1            0.950 0.015  63.509  0.000    0.920    0.979
## 13    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
## 14 sex.gcse ~1           -0.037 0.012  -3.017  0.003   -0.062   -0.013
modelb1.fina <- 'Zfina ~ SESscore + Zgcse'
modelb1.finafit <- sem(modelb1.fina, data = df, missing = "fiml", fixed.x = FALSE)
summary(modelb1.finafit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 10 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                14.594
##   Degrees of freedom                                 2
##   P-value                                        0.001
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -22164.982
##   Loglikelihood unrestricted model (H1)     -22164.982
##                                                       
##   Akaike (AIC)                               44347.965
##   Bayesian (BIC)                             44408.964
##   Sample-size adjusted Bayesian (SABIC)      44380.364
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zfina ~                                                               
##     SESscore         -0.077    0.020   -3.800    0.000   -0.117   -0.037
##     Zgcse             0.043    0.020    2.179    0.029    0.004    0.082
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.419    0.000    0.422    0.472
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zfina            -0.004    0.017   -0.258    0.796   -0.037    0.029
##     SESscore         -0.034    0.012   -2.903    0.004   -0.057   -0.011
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zfina             0.996    0.023   42.787    0.000    0.950    1.041
##     SESscore          0.874    0.016   56.325    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zfina             0.004
standardizedsolution(modelb1.finafit)
##        lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1    Zfina  ~ SESscore  -0.072 0.019  -3.810  0.000   -0.109   -0.035
## 2    Zfina  ~    Zgcse   0.043 0.020   2.180  0.029    0.004    0.082
## 3    Zfina ~~    Zfina   0.996 0.002 468.693  0.000    0.992    1.000
## 4 SESscore ~~ SESscore   1.000 0.000      NA     NA    1.000    1.000
## 5 SESscore ~~    Zgcse   0.478 0.010  49.292  0.000    0.459    0.497
## 6    Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 7    Zfina ~1           -0.004 0.017  -0.258  0.796   -0.037    0.029
## 8 SESscore ~1           -0.036 0.013  -2.902  0.004   -0.061   -0.012
## 9    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
modelb2.fina <- 'Zfina ~ SESscore + Zgcse + SES.gcse'
modelb2.finafit <- sem(modelb2.fina, data = df, missing = "fiml", fixed.x = FALSE)
summary(modelb2.finafit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 12 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        14
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                14.617
##   Degrees of freedom                                 3
##   P-value                                        0.002
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -30883.161
##   Loglikelihood unrestricted model (H1)     -30883.161
##                                                       
##   Akaike (AIC)                               61794.323
##   Bayesian (BIC)                             61889.211
##   Sample-size adjusted Bayesian (SABIC)      61844.722
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zfina ~                                                               
##     SESscore         -0.078    0.021   -3.762    0.000   -0.118   -0.037
##     Zgcse             0.043    0.020    2.183    0.029    0.004    0.082
##     SES.gcse          0.003    0.019    0.151    0.880   -0.034    0.039
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.419    0.000    0.422    0.472
##     SES.gcse         -0.013    0.011   -1.116    0.264   -0.035    0.010
##   Zgcse ~~                                                              
##     SES.gcse         -0.118    0.012   -9.664    0.000   -0.142   -0.094
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zfina            -0.006    0.019   -0.298    0.766   -0.042    0.031
##     SESscore         -0.034    0.012   -2.903    0.004   -0.057   -0.011
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
##     SES.gcse          0.444    0.012   36.803    0.000    0.420    0.467
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zfina             0.996    0.023   42.787    0.000    0.950    1.041
##     SESscore          0.874    0.016   56.326    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     SES.gcse          0.925    0.016   56.379    0.000    0.893    0.957
## 
## R-Square:
##                    Estimate
##     Zfina             0.004
standardizedsolution(modelb2.finafit)
##         lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1     Zfina  ~ SESscore  -0.072 0.019  -3.771  0.000   -0.110   -0.035
## 2     Zfina  ~    Zgcse   0.043 0.020   2.185  0.029    0.004    0.082
## 3     Zfina  ~ SES.gcse   0.003 0.018   0.151  0.880   -0.032    0.038
## 4     Zfina ~~    Zfina   0.996 0.002 461.309  0.000    0.992    1.000
## 5  SESscore ~~ SESscore   1.000 0.000      NA     NA    1.000    1.000
## 6  SESscore ~~    Zgcse   0.478 0.010  49.291  0.000    0.459    0.497
## 7  SESscore ~~ SES.gcse  -0.014 0.013  -1.117  0.264   -0.039    0.011
## 8     Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 9     Zgcse ~~ SES.gcse  -0.123 0.012  -9.882  0.000   -0.147   -0.098
## 10 SES.gcse ~~ SES.gcse   1.000 0.000      NA     NA    1.000    1.000
## 11    Zfina ~1           -0.006 0.019  -0.298  0.766   -0.042    0.031
## 12 SESscore ~1           -0.036 0.013  -2.902  0.004   -0.061   -0.012
## 13    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
## 14 SES.gcse ~1            0.461 0.013  35.005  0.000    0.436    0.487
#get change in R2 for models with vs. w/0 moderation (modela1 vs. a2 and b1 vs b2) 
(PE.modela1.fina <- parameterEstimates(modela1.finafit, rsquare = TRUE)) 
##      lhs op   rhs    est    se      z pvalue ci.lower ci.upper
## 1  Zfina  ~  sex1  0.059 0.034  1.732  0.083   -0.008    0.125
## 2  Zfina  ~ Zgcse  0.007 0.017  0.406  0.685   -0.027    0.041
## 3  Zfina ~~ Zfina  0.999 0.023 42.790  0.000    0.953    1.045
## 4   sex1 ~~  sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 5   sex1 ~~ Zgcse -0.026 0.006 -4.232  0.000   -0.038   -0.014
## 6  Zgcse ~~ Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 7  Zfina ~1       -0.024 0.021 -1.130  0.258   -0.066    0.018
## 8   sex1 ~1        0.474 0.006 76.503  0.000    0.462    0.486
## 9  Zgcse ~1        0.000 0.012  0.000  1.000   -0.024    0.024
## 10 Zfina r2 Zfina  0.001    NA     NA     NA       NA       NA
PE.modela1.fina$est[PE.modela1.fina$op == "r2"]
## [1] 0.0008895165
(PE.modela2.fina <- parameterEstimates(modela2.finafit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1     Zfina  ~     sex1  0.064 0.035  1.841  0.066   -0.004    0.132
## 2     Zfina  ~    Zgcse  0.017 0.022  0.749  0.454   -0.027    0.061
## 3     Zfina  ~ sex.gcse -0.025 0.036 -0.689  0.491   -0.095    0.045
## 4     Zfina ~~    Zfina  0.999 0.023 42.790  0.000    0.953    1.044
## 5      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 6      sex1 ~~    Zgcse -0.026 0.006 -4.232  0.000   -0.038   -0.014
## 7      sex1 ~~ sex.gcse -0.014 0.004 -3.175  0.001   -0.022   -0.005
## 8     Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 9     Zgcse ~~ sex.gcse  0.492 0.011 46.289  0.000    0.471    0.513
## 10 sex.gcse ~~ sex.gcse  0.492 0.009 56.956  0.000    0.475    0.509
## 11    Zfina ~1          -0.026 0.022 -1.210  0.226   -0.068    0.016
## 12     sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 13    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 14 sex.gcse ~1          -0.026 0.009 -3.018  0.003   -0.043   -0.009
## 15    Zfina r2    Zfina  0.001    NA     NA     NA       NA       NA
PE.modela2.fina$est[PE.modela2.fina$op == "r2"]
## [1] 0.001180469
(PE.modelb1.fina <- parameterEstimates(modelb1.finafit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1     Zfina  ~ SESscore -0.077 0.020 -3.800  0.000   -0.117   -0.037
## 2     Zfina  ~    Zgcse  0.043 0.020  2.179  0.029    0.004    0.082
## 3     Zfina ~~    Zfina  0.996 0.023 42.787  0.000    0.950    1.041
## 4  SESscore ~~ SESscore  0.874 0.016 56.325  0.000    0.844    0.905
## 5  SESscore ~~    Zgcse  0.447 0.013 34.419  0.000    0.422    0.472
## 6     Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 7     Zfina ~1          -0.004 0.017 -0.258  0.796   -0.037    0.029
## 8  SESscore ~1          -0.034 0.012 -2.903  0.004   -0.057   -0.011
## 9     Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 10    Zfina r2    Zfina  0.004    NA     NA     NA       NA       NA
PE.modelb1.fina$est[PE.modelb1.fina$op == "r2"]
## [1] 0.00407102
(PE.modelb2.fina <- parameterEstimates(modelb2.finafit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1     Zfina  ~ SESscore -0.078 0.021 -3.762  0.000   -0.118   -0.037
## 2     Zfina  ~    Zgcse  0.043 0.020  2.183  0.029    0.004    0.082
## 3     Zfina  ~ SES.gcse  0.003 0.019  0.151  0.880   -0.034    0.039
## 4     Zfina ~~    Zfina  0.996 0.023 42.787  0.000    0.950    1.041
## 5  SESscore ~~ SESscore  0.874 0.016 56.326  0.000    0.844    0.905
## 6  SESscore ~~    Zgcse  0.447 0.013 34.419  0.000    0.422    0.472
## 7  SESscore ~~ SES.gcse -0.013 0.011 -1.116  0.264   -0.035    0.010
## 8     Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 9     Zgcse ~~ SES.gcse -0.118 0.012 -9.664  0.000   -0.142   -0.094
## 10 SES.gcse ~~ SES.gcse  0.925 0.016 56.379  0.000    0.893    0.957
## 11    Zfina ~1          -0.006 0.019 -0.298  0.766   -0.042    0.031
## 12 SESscore ~1          -0.034 0.012 -2.903  0.004   -0.057   -0.011
## 13    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 14 SES.gcse ~1           0.444 0.012 36.803  0.000    0.420    0.467
## 15    Zfina r2    Zfina  0.004    NA     NA     NA       NA       NA
PE.modelb2.fina$est[PE.modelb2.fina$op == "r2"]
## [1] 0.004113188
r2diffa.fina <- (PE.modela2.fina$est[PE.modela2.fina$op == "r2"] - PE.modela1.fina$est[PE.modela1.fina$op == "r2"])
print(r2diffa.fina)    #difference modela1 vs a2, incremental explained variance by sexxGCSE
## [1] 0.0002909522
r2diffb.fina <- (PE.modelb2.fina$est[PE.modelb2.fina$op == "r2"] - PE.modelb1.fina$est[PE.modelb1.fina$op == "r2"])
print(r2diffb.fina)    #difference modelb1 vs b2, incremental explained variance by SESxGCSE
## [1] 4.216797e-05
modela1.wellb <- 'Zwellb ~ sex1 + Zgcse'
modela1.wellbfit <- sem(modela1.wellb, data = df, missing = "fiml", fixed.x = FALSE)
summary(modela1.wellbfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 14 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                          6488
##   Number of missing patterns                         2
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                               109.405
##   Degrees of freedom                                 2
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -19168.400
##   Loglikelihood unrestricted model (H1)     -19168.400
##                                                       
##   Akaike (AIC)                               38354.799
##   Bayesian (BIC)                             38415.798
##   Sample-size adjusted Bayesian (SABIC)      38387.199
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zwellb ~                                                              
##     sex1              0.265    0.033    8.005    0.000    0.200    0.330
##     Zgcse             0.115    0.017    6.768    0.000    0.082    0.149
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zwellb           -0.124    0.021   -6.002    0.000   -0.165   -0.084
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zwellb            0.971    0.022   43.324    0.000    0.927    1.015
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zwellb            0.029
standardizedsolution(modela1.wellbfit)
##      lhs op    rhs est.std    se       z pvalue ci.lower ci.upper
## 1 Zwellb  ~   sex1   0.132 0.016   8.085      0    0.100    0.164
## 2 Zwellb  ~  Zgcse   0.115 0.017   6.819      0    0.082    0.148
## 3 Zwellb ~~ Zwellb   0.971 0.005 178.603      0    0.960    0.982
## 4   sex1 ~~   sex1   1.000 0.000      NA     NA    1.000    1.000
## 5   sex1 ~~  Zgcse  -0.053 0.012  -4.250      0   -0.077   -0.028
## 6  Zgcse ~~  Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 7 Zwellb ~1         -0.124 0.021  -6.044      0   -0.165   -0.084
## 8   sex1 ~1          0.950 0.015  63.510      0    0.920    0.979
## 9  Zgcse ~1          0.000 0.012   0.000      1   -0.024    0.024
modela2.wellb <- 'Zwellb ~ sex1 + Zgcse + sex.gcse'
modela2.wellbfit <- sem(modela2.wellb, data = df, missing = "fiml", fixed.x = FALSE)
summary(modela2.wellbfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 21 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        14
## 
##   Number of observations                          6488
##   Number of missing patterns                         2
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                               111.789
##   Degrees of freedom                                 3
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -23865.884
##   Loglikelihood unrestricted model (H1)     -23865.884
##                                                       
##   Akaike (AIC)                               47759.768
##   Bayesian (BIC)                             47854.656
##   Sample-size adjusted Bayesian (SABIC)      47810.167
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zwellb ~                                                              
##     sex1              0.276    0.034    8.154    0.000    0.210    0.342
##     Zgcse             0.137    0.022    6.226    0.000    0.094    0.180
##     sex.gcse         -0.054    0.035   -1.545    0.122   -0.122    0.014
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     sex.gcse         -0.014    0.004   -3.175    0.001   -0.022   -0.005
##   Zgcse ~~                                                              
##     sex.gcse          0.492    0.011   46.289    0.000    0.471    0.513
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zwellb           -0.129    0.021   -6.151    0.000   -0.170   -0.088
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
##     sex.gcse         -0.026    0.009   -3.018    0.003   -0.043   -0.009
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zwellb            0.970    0.022   43.324    0.000    0.927    1.014
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     sex.gcse          0.492    0.009   56.956    0.000    0.475    0.509
## 
## R-Square:
##                    Estimate
##     Zwellb            0.030
standardizedsolution(modela2.wellbfit)
##         lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1    Zwellb  ~     sex1   0.138 0.017   8.248  0.000    0.105    0.170
## 2    Zwellb  ~    Zgcse   0.137 0.022   6.268  0.000    0.094    0.179
## 3    Zwellb  ~ sex.gcse  -0.038 0.024  -1.546  0.122   -0.085    0.010
## 4    Zwellb ~~   Zwellb   0.970 0.006 173.675  0.000    0.959    0.981
## 5      sex1 ~~     sex1   1.000 0.000      NA     NA    1.000    1.000
## 6      sex1 ~~    Zgcse  -0.053 0.012  -4.250  0.000   -0.077   -0.028
## 7      sex1 ~~ sex.gcse  -0.039 0.012  -3.182  0.001   -0.064   -0.015
## 8     Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 9     Zgcse ~~ sex.gcse   0.702 0.006 111.585  0.000    0.690    0.715
## 10 sex.gcse ~~ sex.gcse   1.000 0.000      NA     NA    1.000    1.000
## 11   Zwellb ~1           -0.129 0.021  -6.200  0.000   -0.169   -0.088
## 12     sex1 ~1            0.950 0.015  63.510  0.000    0.920    0.979
## 13    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
## 14 sex.gcse ~1           -0.037 0.012  -3.017  0.003   -0.062   -0.013
modelb1.wellb <- 'Zwellb ~ SESscore + Zgcse'
modelb1.wellbfit <- sem(modelb1.wellb, data = df, missing = "fiml", fixed.x = FALSE)
summary(modelb1.wellbfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 8 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                46.942
##   Degrees of freedom                                 2
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -22279.351
##   Loglikelihood unrestricted model (H1)     -22279.351
##                                                       
##   Akaike (AIC)                               44576.701
##   Bayesian (BIC)                             44637.701
##   Sample-size adjusted Bayesian (SABIC)      44609.101
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zwellb ~                                                              
##     SESscore          0.021    0.020    1.038    0.299   -0.018    0.059
##     Zgcse             0.107    0.019    5.492    0.000    0.069    0.145
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.426    0.000    0.422    0.473
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zwellb           -0.023    0.017   -1.357    0.175   -0.055    0.010
##     SESscore         -0.034    0.012   -2.916    0.004   -0.057   -0.011
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zwellb            0.987    0.023   43.325    0.000    0.943    1.032
##     SESscore          0.874    0.016   56.320    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zwellb            0.014
standardizedsolution(modelb1.wellbfit)
##        lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1   Zwellb  ~ SESscore   0.019 0.019   1.038  0.299   -0.017    0.056
## 2   Zwellb  ~    Zgcse   0.107 0.019   5.525  0.000    0.069    0.145
## 3   Zwellb ~~   Zwellb   0.986 0.004 247.977  0.000    0.978    0.994
## 4 SESscore ~~ SESscore   1.000 0.000      NA     NA    1.000    1.000
## 5 SESscore ~~    Zgcse   0.478 0.010  49.312  0.000    0.459    0.497
## 6    Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 7   Zwellb ~1           -0.023 0.017  -1.358  0.174   -0.055    0.010
## 8 SESscore ~1           -0.036 0.013  -2.915  0.004   -0.061   -0.012
## 9    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
modelb2.wellb <- 'Zwellb ~ SESscore + Zgcse + SES.gcse'
modelb2.wellbfit <- sem(modelb2.wellb, data = df, missing = "fiml", fixed.x = FALSE)
summary(modelb2.wellbfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 10 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        14
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                48.553
##   Degrees of freedom                                 3
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -30996.736
##   Loglikelihood unrestricted model (H1)     -30996.736
##                                                       
##   Akaike (AIC)                               62021.472
##   Bayesian (BIC)                             62116.360
##   Sample-size adjusted Bayesian (SABIC)      62071.871
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zwellb ~                                                              
##     SESscore          0.016    0.020    0.794    0.427   -0.024    0.056
##     Zgcse             0.108    0.020    5.541    0.000    0.070    0.146
##     SES.gcse          0.023    0.018    1.269    0.204   -0.013    0.059
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.426    0.000    0.422    0.473
##     SES.gcse         -0.013    0.011   -1.117    0.264   -0.035    0.010
##   Zgcse ~~                                                              
##     SES.gcse         -0.118    0.012   -9.661    0.000   -0.142   -0.094
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zwellb           -0.032    0.018   -1.767    0.077   -0.068    0.004
##     SESscore         -0.034    0.012   -2.915    0.004   -0.057   -0.011
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
##     SES.gcse          0.444    0.012   36.801    0.000    0.420    0.467
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zwellb            0.987    0.023   43.324    0.000    0.942    1.032
##     SESscore          0.874    0.016   56.320    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     SES.gcse          0.925    0.016   56.380    0.000    0.893    0.957
## 
## R-Square:
##                    Estimate
##     Zwellb            0.013
standardizedsolution(modelb2.wellbfit)
##         lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1    Zwellb  ~ SESscore   0.015 0.019   0.794  0.427   -0.022    0.052
## 2    Zwellb  ~    Zgcse   0.108 0.019   5.573  0.000    0.070    0.146
## 3    Zwellb  ~ SES.gcse   0.022 0.018   1.269  0.204   -0.012    0.057
## 4    Zwellb ~~   Zwellb   0.987 0.004 256.587  0.000    0.979    0.994
## 5  SESscore ~~ SESscore   1.000 0.000      NA     NA    1.000    1.000
## 6  SESscore ~~    Zgcse   0.478 0.010  49.313  0.000    0.459    0.497
## 7  SESscore ~~ SES.gcse  -0.014 0.013  -1.117  0.264   -0.039    0.011
## 8     Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 9     Zgcse ~~ SES.gcse  -0.123 0.012  -9.879  0.000   -0.147   -0.098
## 10 SES.gcse ~~ SES.gcse   1.000 0.000      NA     NA    1.000    1.000
## 11   Zwellb ~1           -0.032 0.018  -1.768  0.077   -0.068    0.004
## 12 SESscore ~1           -0.036 0.013  -2.915  0.004   -0.061   -0.012
## 13    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
## 14 SES.gcse ~1            0.461 0.013  35.003  0.000    0.436    0.487
#get change in R2 for models with vs. w/0 moderation (modela1 vs. a2 and b1 vs b2) 
(PE.modela1.wellb <- parameterEstimates(modela1.wellbfit, rsquare = TRUE)) 
##       lhs op    rhs    est    se      z pvalue ci.lower ci.upper
## 1  Zwellb  ~   sex1  0.265 0.033  8.005      0    0.200    0.330
## 2  Zwellb  ~  Zgcse  0.115 0.017  6.768      0    0.082    0.149
## 3  Zwellb ~~ Zwellb  0.971 0.022 43.324      0    0.927    1.015
## 4    sex1 ~~   sex1  0.249 0.004 56.956      0    0.241    0.258
## 5    sex1 ~~  Zgcse -0.026 0.006 -4.232      0   -0.038   -0.014
## 6   Zgcse ~~  Zgcse  1.000 0.018 56.956      0    0.965    1.034
## 7  Zwellb ~1        -0.124 0.021 -6.002      0   -0.165   -0.084
## 8    sex1 ~1         0.474 0.006 76.503      0    0.462    0.486
## 9   Zgcse ~1         0.000 0.012  0.000      1   -0.024    0.024
## 10 Zwellb r2 Zwellb  0.029    NA     NA     NA       NA       NA
PE.modela1.wellb$est[PE.modela1.wellb$op == "r2"]
## [1] 0.02915231
(PE.modela2.wellb <- parameterEstimates(modela2.wellbfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1    Zwellb  ~     sex1  0.276 0.034  8.154  0.000    0.210    0.342
## 2    Zwellb  ~    Zgcse  0.137 0.022  6.226  0.000    0.094    0.180
## 3    Zwellb  ~ sex.gcse -0.054 0.035 -1.545  0.122   -0.122    0.014
## 4    Zwellb ~~   Zwellb  0.970 0.022 43.324  0.000    0.927    1.014
## 5      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 6      sex1 ~~    Zgcse -0.026 0.006 -4.232  0.000   -0.038   -0.014
## 7      sex1 ~~ sex.gcse -0.014 0.004 -3.175  0.001   -0.022   -0.005
## 8     Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 9     Zgcse ~~ sex.gcse  0.492 0.011 46.289  0.000    0.471    0.513
## 10 sex.gcse ~~ sex.gcse  0.492 0.009 56.956  0.000    0.475    0.509
## 11   Zwellb ~1          -0.129 0.021 -6.151  0.000   -0.170   -0.088
## 12     sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 13    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 14 sex.gcse ~1          -0.026 0.009 -3.018  0.003   -0.043   -0.009
## 15   Zwellb r2   Zwellb  0.030    NA     NA     NA       NA       NA
PE.modela2.wellb$est[PE.modela2.wellb$op == "r2"]
## [1] 0.0302282
(PE.modelb1.wellb <- parameterEstimates(modelb1.wellbfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1    Zwellb  ~ SESscore  0.021 0.020  1.038  0.299   -0.018    0.059
## 2    Zwellb  ~    Zgcse  0.107 0.019  5.492  0.000    0.069    0.145
## 3    Zwellb ~~   Zwellb  0.987 0.023 43.325  0.000    0.943    1.032
## 4  SESscore ~~ SESscore  0.874 0.016 56.320  0.000    0.844    0.905
## 5  SESscore ~~    Zgcse  0.447 0.013 34.426  0.000    0.422    0.473
## 6     Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 7    Zwellb ~1          -0.023 0.017 -1.357  0.175   -0.055    0.010
## 8  SESscore ~1          -0.034 0.012 -2.916  0.004   -0.057   -0.011
## 9     Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 10   Zwellb r2   Zwellb  0.014    NA     NA     NA       NA       NA
PE.modelb1.wellb$est[PE.modelb1.wellb$op == "r2"]
## [1] 0.01378128
(PE.modelb2.wellb <- parameterEstimates(modelb2.wellbfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1    Zwellb  ~ SESscore  0.016 0.020  0.794  0.427   -0.024    0.056
## 2    Zwellb  ~    Zgcse  0.108 0.020  5.541  0.000    0.070    0.146
## 3    Zwellb  ~ SES.gcse  0.023 0.018  1.269  0.204   -0.013    0.059
## 4    Zwellb ~~   Zwellb  0.987 0.023 43.324  0.000    0.942    1.032
## 5  SESscore ~~ SESscore  0.874 0.016 56.320  0.000    0.844    0.905
## 6  SESscore ~~    Zgcse  0.447 0.013 34.426  0.000    0.422    0.473
## 7  SESscore ~~ SES.gcse -0.013 0.011 -1.117  0.264   -0.035    0.010
## 8     Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 9     Zgcse ~~ SES.gcse -0.118 0.012 -9.661  0.000   -0.142   -0.094
## 10 SES.gcse ~~ SES.gcse  0.925 0.016 56.380  0.000    0.893    0.957
## 11   Zwellb ~1          -0.032 0.018 -1.767  0.077   -0.068    0.004
## 12 SESscore ~1          -0.034 0.012 -2.915  0.004   -0.057   -0.011
## 13    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 14 SES.gcse ~1           0.444 0.012 36.801  0.000    0.420    0.467
## 15   Zwellb r2   Zwellb  0.013    NA     NA     NA       NA       NA
PE.modelb2.wellb$est[PE.modelb2.wellb$op == "r2"]
## [1] 0.01333689
r2diffa.wellb <- (PE.modela2.wellb$est[PE.modela2.wellb$op == "r2"] - PE.modela1.wellb$est[PE.modela1.wellb$op == "r2"])
print(r2diffa.wellb)    #difference modela1 vs a2, incremental explained variance by sexxGCSE
## [1] 0.001075893
r2diffb.wellb <- (PE.modelb2.wellb$est[PE.modelb2.wellb$op == "r2"] - PE.modelb1.wellb$est[PE.modelb1.wellb$op == "r2"])
print(r2diffb.wellb)    #difference modelb1 vs b2, incremental explained variance by SESxGCSE
## [1] -0.0004443923
modela1.anx <- 'Zanx ~ sex1 + Zgcse'
modela1.anxfit <- sem(modela1.anx, data = df, missing = "fiml", fixed.x = FALSE)
summary(modela1.anxfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 15 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                          6488
##   Number of missing patterns                         2
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                90.926
##   Degrees of freedom                                 2
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -18716.484
##   Loglikelihood unrestricted model (H1)     -18716.484
##                                                       
##   Akaike (AIC)                               37450.968
##   Bayesian (BIC)                             37511.967
##   Sample-size adjusted Bayesian (SABIC)      37483.368
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zanx ~                                                                
##     sex1             -0.334    0.035   -9.556    0.000   -0.402   -0.265
##     Zgcse            -0.011    0.018   -0.595    0.552   -0.045    0.024
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zanx              0.126    0.021    5.850    0.000    0.083    0.168
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zanx              0.974    0.024   41.406    0.000    0.927    1.020
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zanx              0.028
standardizedsolution(modela1.anxfit)
##     lhs op   rhs est.std    se       z pvalue ci.lower ci.upper
## 1  Zanx  ~  sex1  -0.167 0.017  -9.730  0.000   -0.200   -0.133
## 2  Zanx  ~ Zgcse  -0.011 0.018  -0.595  0.552   -0.045    0.024
## 3  Zanx ~~  Zanx   0.972 0.006 171.166  0.000    0.961    0.983
## 4  sex1 ~~  sex1   1.000 0.000      NA     NA    1.000    1.000
## 5  sex1 ~~ Zgcse  -0.053 0.012  -4.250  0.000   -0.077   -0.028
## 6 Zgcse ~~ Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 7  Zanx ~1         0.125 0.021   5.895  0.000    0.084    0.167
## 8  sex1 ~1         0.950 0.015  63.510  0.000    0.920    0.979
## 9 Zgcse ~1         0.000 0.012   0.000  1.000   -0.024    0.024
modela2.anx <- 'Zanx ~ sex1 + Zgcse + sex.gcse'
modela2.anxfit <- sem(modela2.anx, data = df, missing = "fiml", fixed.x = FALSE)
summary(modela2.anxfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 21 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        14
## 
##   Number of observations                          6488
##   Number of missing patterns                         2
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                91.438
##   Degrees of freedom                                 3
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -23414.904
##   Loglikelihood unrestricted model (H1)     -23414.904
##                                                       
##   Akaike (AIC)                               46857.809
##   Bayesian (BIC)                             46952.696
##   Sample-size adjusted Bayesian (SABIC)      46908.208
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zanx ~                                                                
##     sex1             -0.339    0.036   -9.480    0.000   -0.410   -0.269
##     Zgcse            -0.020    0.023   -0.910    0.363   -0.065    0.024
##     sex.gcse          0.026    0.037    0.715    0.475   -0.045    0.098
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     sex.gcse         -0.014    0.004   -3.175    0.001   -0.022   -0.005
##   Zgcse ~~                                                              
##     sex.gcse          0.492    0.011   46.289    0.000    0.471    0.513
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zanx              0.127    0.022    5.894    0.000    0.085    0.170
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
##     sex.gcse         -0.026    0.009   -3.018    0.003   -0.043   -0.009
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zanx              0.973    0.024   41.407    0.000    0.927    1.019
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     sex.gcse          0.492    0.009   56.956    0.000    0.475    0.509
## 
## R-Square:
##                    Estimate
##     Zanx              0.029
standardizedsolution(modela2.anxfit)
##         lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1      Zanx  ~     sex1  -0.169 0.018  -9.668  0.000   -0.204   -0.135
## 2      Zanx  ~    Zgcse  -0.020 0.022  -0.910  0.363   -0.065    0.024
## 3      Zanx  ~ sex.gcse   0.018 0.026   0.716  0.474   -0.032    0.068
## 4      Zanx ~~     Zanx   0.971 0.006 160.635  0.000    0.959    0.983
## 5      sex1 ~~     sex1   1.000 0.000      NA     NA    1.000    1.000
## 6      sex1 ~~    Zgcse  -0.053 0.012  -4.250  0.000   -0.077   -0.028
## 7      sex1 ~~ sex.gcse  -0.039 0.012  -3.182  0.001   -0.064   -0.015
## 8     Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 9     Zgcse ~~ sex.gcse   0.702 0.006 111.584  0.000    0.690    0.715
## 10 sex.gcse ~~ sex.gcse   1.000 0.000      NA     NA    1.000    1.000
## 11     Zanx ~1            0.127 0.021   5.944  0.000    0.085    0.169
## 12     sex1 ~1            0.950 0.015  63.510  0.000    0.920    0.979
## 13    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
## 14 sex.gcse ~1           -0.037 0.012  -3.017  0.003   -0.062   -0.013
modelb1.anx <- 'Zanx ~ SESscore + Zgcse'
modelb1.anxfit <- sem(modelb1.anx, data = df, missing = "fiml", fixed.x = FALSE)
summary(modelb1.anxfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 11 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 1.307
##   Degrees of freedom                                 2
##   P-value                                        0.520
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -21841.013
##   Loglikelihood unrestricted model (H1)     -21841.013
##                                                       
##   Akaike (AIC)                               43700.026
##   Bayesian (BIC)                             43761.026
##   Sample-size adjusted Bayesian (SABIC)      43732.426
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zanx ~                                                                
##     SESscore         -0.015    0.021   -0.716    0.474   -0.056    0.026
##     Zgcse            -0.009    0.020   -0.435    0.664   -0.049    0.031
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.423    0.000    0.422    0.473
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zanx              0.002    0.017    0.141    0.888   -0.032    0.037
##     SESscore         -0.034    0.012   -2.914    0.004   -0.057   -0.011
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zanx              0.999    0.024   41.407    0.000    0.952    1.047
##     SESscore          0.874    0.016   56.322    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zanx              0.000
standardizedsolution(modelb1.anxfit)
##        lhs op      rhs est.std    se        z pvalue ci.lower ci.upper
## 1     Zanx  ~ SESscore  -0.014 0.020   -0.716  0.474   -0.053    0.024
## 2     Zanx  ~    Zgcse  -0.009 0.020   -0.435  0.664   -0.049    0.031
## 3     Zanx ~~     Zanx   1.000 0.001 1432.475  0.000    0.998    1.001
## 4 SESscore ~~ SESscore   1.000 0.000       NA     NA    1.000    1.000
## 5 SESscore ~~    Zgcse   0.478 0.010   49.305  0.000    0.459    0.497
## 6    Zgcse ~~    Zgcse   1.000 0.000       NA     NA    1.000    1.000
## 7     Zanx ~1            0.002 0.017    0.141  0.888   -0.032    0.037
## 8 SESscore ~1           -0.036 0.013   -2.914  0.004   -0.061   -0.012
## 9    Zgcse ~1            0.000 0.012    0.000  1.000   -0.024    0.024
modelb2.anx <- 'Zanx ~ SESscore + Zgcse + SES.gcse'
modelb2.anxfit <- sem(modelb2.anx, data = df, missing = "fiml", fixed.x = FALSE)
summary(modelb2.anxfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 13 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        14
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 9.845
##   Degrees of freedom                                 3
##   P-value                                        0.020
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -30554.935
##   Loglikelihood unrestricted model (H1)     -30554.935
##                                                       
##   Akaike (AIC)                               61137.869
##   Bayesian (BIC)                             61232.757
##   Sample-size adjusted Bayesian (SABIC)      61188.269
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zanx ~                                                                
##     SESscore         -0.004    0.021   -0.170    0.865   -0.046    0.038
##     Zgcse            -0.012    0.021   -0.606    0.545   -0.053    0.028
##     SES.gcse         -0.056    0.019   -2.924    0.003   -0.093   -0.018
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.424    0.000    0.422    0.473
##     SES.gcse         -0.013    0.011   -1.123    0.262   -0.035    0.009
##   Zgcse ~~                                                              
##     SES.gcse         -0.118    0.012   -9.675    0.000   -0.142   -0.094
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zanx              0.027    0.019    1.384    0.166   -0.011    0.065
##     SESscore         -0.034    0.012   -2.914    0.004   -0.057   -0.011
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
##     SES.gcse          0.444    0.012   36.804    0.000    0.420    0.467
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zanx              0.997    0.024   41.405    0.000    0.950    1.044
##     SESscore          0.874    0.016   56.321    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     SES.gcse          0.925    0.016   56.377    0.000    0.893    0.957
## 
## R-Square:
##                    Estimate
##     Zanx              0.003
standardizedsolution(modelb2.anxfit)
##         lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1      Zanx  ~ SESscore  -0.003 0.020  -0.170  0.865   -0.043    0.036
## 2      Zanx  ~    Zgcse  -0.012 0.021  -0.606  0.545   -0.053    0.028
## 3      Zanx  ~ SES.gcse  -0.054 0.018  -2.929  0.003   -0.090   -0.018
## 4      Zanx ~~     Zanx   0.997 0.002 527.630  0.000    0.993    1.001
## 5  SESscore ~~ SESscore   1.000 0.000      NA     NA    1.000    1.000
## 6  SESscore ~~    Zgcse   0.478 0.010  49.307  0.000    0.459    0.497
## 7  SESscore ~~ SES.gcse  -0.014 0.013  -1.123  0.261   -0.039    0.011
## 8     Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 9     Zgcse ~~ SES.gcse  -0.123 0.012  -9.894  0.000   -0.147   -0.098
## 10 SES.gcse ~~ SES.gcse   1.000 0.000      NA     NA    1.000    1.000
## 11     Zanx ~1            0.027 0.019   1.385  0.166   -0.011    0.065
## 12 SESscore ~1           -0.036 0.013  -2.914  0.004   -0.061   -0.012
## 13    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
## 14 SES.gcse ~1            0.461 0.013  35.006  0.000    0.436    0.487
#get change in R2 for models with vs. w/0 moderation (modela1 vs. a2 and b1 vs b2) 
(PE.modela1.anx <- parameterEstimates(modela1.anxfit, rsquare = TRUE)) 
##      lhs op   rhs    est    se      z pvalue ci.lower ci.upper
## 1   Zanx  ~  sex1 -0.334 0.035 -9.556  0.000   -0.402   -0.265
## 2   Zanx  ~ Zgcse -0.011 0.018 -0.595  0.552   -0.045    0.024
## 3   Zanx ~~  Zanx  0.974 0.024 41.406  0.000    0.927    1.020
## 4   sex1 ~~  sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 5   sex1 ~~ Zgcse -0.026 0.006 -4.232  0.000   -0.038   -0.014
## 6  Zgcse ~~ Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 7   Zanx ~1        0.126 0.021  5.850  0.000    0.083    0.168
## 8   sex1 ~1        0.474 0.006 76.503  0.000    0.462    0.486
## 9  Zgcse ~1        0.000 0.012  0.000  1.000   -0.024    0.024
## 10  Zanx r2  Zanx  0.028    NA     NA     NA       NA       NA
PE.modela1.anx$est[PE.modela1.anx$op == "r2"]
## [1] 0.02766229
(PE.modela2.anx <- parameterEstimates(modela2.anxfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1      Zanx  ~     sex1 -0.339 0.036 -9.480  0.000   -0.410   -0.269
## 2      Zanx  ~    Zgcse -0.020 0.023 -0.910  0.363   -0.065    0.024
## 3      Zanx  ~ sex.gcse  0.026 0.037  0.715  0.475   -0.045    0.098
## 4      Zanx ~~     Zanx  0.973 0.024 41.407  0.000    0.927    1.019
## 5      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 6      sex1 ~~    Zgcse -0.026 0.006 -4.232  0.000   -0.038   -0.014
## 7      sex1 ~~ sex.gcse -0.014 0.004 -3.175  0.001   -0.022   -0.005
## 8     Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 9     Zgcse ~~ sex.gcse  0.492 0.011 46.289  0.000    0.471    0.513
## 10 sex.gcse ~~ sex.gcse  0.492 0.009 56.956  0.000    0.475    0.509
## 11     Zanx ~1           0.127 0.022  5.894  0.000    0.085    0.170
## 12     sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 13    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 14 sex.gcse ~1          -0.026 0.009 -3.018  0.003   -0.043   -0.009
## 15     Zanx r2     Zanx  0.029    NA     NA     NA       NA       NA
PE.modela2.anx$est[PE.modela2.anx$op == "r2"]
## [1] 0.02876186
(PE.modelb1.anx <- parameterEstimates(modelb1.anxfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1      Zanx  ~ SESscore -0.015 0.021 -0.716  0.474   -0.056    0.026
## 2      Zanx  ~    Zgcse -0.009 0.020 -0.435  0.664   -0.049    0.031
## 3      Zanx ~~     Zanx  0.999 0.024 41.407  0.000    0.952    1.047
## 4  SESscore ~~ SESscore  0.874 0.016 56.322  0.000    0.844    0.905
## 5  SESscore ~~    Zgcse  0.447 0.013 34.423  0.000    0.422    0.473
## 6     Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 7      Zanx ~1           0.002 0.017  0.141  0.888   -0.032    0.037
## 8  SESscore ~1          -0.034 0.012 -2.914  0.004   -0.057   -0.011
## 9     Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 10     Zanx r2     Zanx  0.000    NA     NA     NA       NA       NA
PE.modelb1.anx$est[PE.modelb1.anx$op == "r2"]
## [1] 0.0003987046
(PE.modelb2.anx <- parameterEstimates(modelb2.anxfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1      Zanx  ~ SESscore -0.004 0.021 -0.170  0.865   -0.046    0.038
## 2      Zanx  ~    Zgcse -0.012 0.021 -0.606  0.545   -0.053    0.028
## 3      Zanx  ~ SES.gcse -0.056 0.019 -2.924  0.003   -0.093   -0.018
## 4      Zanx ~~     Zanx  0.997 0.024 41.405  0.000    0.950    1.044
## 5  SESscore ~~ SESscore  0.874 0.016 56.321  0.000    0.844    0.905
## 6  SESscore ~~    Zgcse  0.447 0.013 34.424  0.000    0.422    0.473
## 7  SESscore ~~ SES.gcse -0.013 0.011 -1.123  0.262   -0.035    0.009
## 8     Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 9     Zgcse ~~ SES.gcse -0.118 0.012 -9.675  0.000   -0.142   -0.094
## 10 SES.gcse ~~ SES.gcse  0.925 0.016 56.377  0.000    0.893    0.957
## 11     Zanx ~1           0.027 0.019  1.384  0.166   -0.011    0.065
## 12 SESscore ~1          -0.034 0.012 -2.914  0.004   -0.057   -0.011
## 13    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 14 SES.gcse ~1           0.444 0.012 36.804  0.000    0.420    0.467
## 15     Zanx r2     Zanx  0.003    NA     NA     NA       NA       NA
PE.modelb2.anx$est[PE.modelb2.anx$op == "r2"]
## [1] 0.002912923
r2diffa.anx <- (PE.modela2.anx$est[PE.modela2.anx$op == "r2"] - PE.modela1.anx$est[PE.modela1.anx$op == "r2"])
print(r2diffa.anx)    #difference modela1 vs a2, incremental explained variance by sexxGCSE
## [1] 0.001099575
r2diffb.anx <- (PE.modelb2.anx$est[PE.modelb2.anx$op == "r2"] - PE.modelb1.anx$est[PE.modelb1.anx$op == "r2"])
print(r2diffb.anx)    #difference modelb1 vs b2, incremental explained variance by SESxGCSE
## [1] 0.002514218
modela1.sdq <- 'Zsdq ~ sex1 + Zgcse'
modela1.sdqfit <- sem(modela1.sdq, data = df, missing = "fiml", fixed.x = FALSE)
summary(modela1.sdqfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 14 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                          6488
##   Number of missing patterns                         2
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                               213.888
##   Degrees of freedom                                 2
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -19117.577
##   Loglikelihood unrestricted model (H1)     -19117.577
##                                                       
##   Akaike (AIC)                               38253.154
##   Bayesian (BIC)                             38314.153
##   Sample-size adjusted Bayesian (SABIC)      38285.554
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zsdq ~                                                                
##     sex1             -0.194    0.033   -5.942    0.000   -0.258   -0.130
##     Zgcse            -0.227    0.017  -13.533    0.000   -0.260   -0.194
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsdq              0.120    0.020    5.851    0.000    0.080    0.160
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsdq              0.944    0.022   43.330    0.000    0.902    0.987
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zsdq              0.058
standardizedsolution(modela1.sdqfit)
##     lhs op   rhs est.std    se       z pvalue ci.lower ci.upper
## 1  Zsdq  ~  sex1  -0.097 0.016  -5.967      0   -0.128   -0.065
## 2  Zsdq  ~ Zgcse  -0.227 0.016 -13.980      0   -0.259   -0.195
## 3  Zsdq ~~  Zsdq   0.942 0.008 123.790      0    0.927    0.956
## 4  sex1 ~~  sex1   1.000 0.000      NA     NA    1.000    1.000
## 5  sex1 ~~ Zgcse  -0.053 0.012  -4.250      0   -0.077   -0.028
## 6 Zgcse ~~ Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 7  Zsdq ~1         0.119 0.020   5.887      0    0.080    0.159
## 8  sex1 ~1         0.950 0.015  63.510      0    0.920    0.979
## 9 Zgcse ~1         0.000 0.012   0.000      1   -0.024    0.024
modela2.sdq <- 'Zsdq ~ sex1 + Zgcse + sex.gcse'
modela2.sdqfit <- sem(modela2.sdq, data = df, missing = "fiml", fixed.x = FALSE)
summary(modela2.sdqfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 20 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        14
## 
##   Number of observations                          6488
##   Number of missing patterns                         2
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                               220.208
##   Degrees of freedom                                 3
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -23813.093
##   Loglikelihood unrestricted model (H1)     -23813.093
##                                                       
##   Akaike (AIC)                               47654.187
##   Bayesian (BIC)                             47749.075
##   Sample-size adjusted Bayesian (SABIC)      47704.586
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zsdq ~                                                                
##     sex1             -0.211    0.033   -6.342    0.000   -0.277   -0.146
##     Zgcse            -0.261    0.022  -12.091    0.000   -0.304   -0.219
##     sex.gcse          0.086    0.034    2.515    0.012    0.019    0.153
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     sex.gcse         -0.014    0.004   -3.175    0.001   -0.022   -0.005
##   Zgcse ~~                                                              
##     sex.gcse          0.492    0.011   46.289    0.000    0.471    0.513
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsdq              0.126    0.021    6.129    0.000    0.086    0.167
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
##     sex.gcse         -0.026    0.009   -3.018    0.003   -0.043   -0.009
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsdq              0.943    0.022   43.330    0.000    0.900    0.985
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     sex.gcse          0.492    0.009   56.956    0.000    0.475    0.509
## 
## R-Square:
##                    Estimate
##     Zsdq              0.058
standardizedsolution(modela2.sdqfit)
##         lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1      Zsdq  ~     sex1  -0.105 0.017  -6.378  0.000   -0.138   -0.073
## 2      Zsdq  ~    Zgcse  -0.261 0.021 -12.359  0.000   -0.303   -0.220
## 3      Zsdq  ~ sex.gcse   0.060 0.024   2.516  0.012    0.013    0.107
## 4      Zsdq ~~     Zsdq   0.942 0.008 125.472  0.000    0.927    0.956
## 5      sex1 ~~     sex1   1.000 0.000      NA     NA    1.000    1.000
## 6      sex1 ~~    Zgcse  -0.053 0.012  -4.249  0.000   -0.077   -0.028
## 7      sex1 ~~ sex.gcse  -0.039 0.012  -3.182  0.001   -0.064   -0.015
## 8     Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 9     Zgcse ~~ sex.gcse   0.702 0.006 111.584  0.000    0.690    0.715
## 10 sex.gcse ~~ sex.gcse   1.000 0.000      NA     NA    1.000    1.000
## 11     Zsdq ~1            0.126 0.020   6.171  0.000    0.086    0.166
## 12     sex1 ~1            0.950 0.015  63.509  0.000    0.920    0.979
## 13    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
## 14 sex.gcse ~1           -0.037 0.012  -3.017  0.003   -0.062   -0.013
modelb1.sdq <- 'Zsdq ~ SESscore + Zgcse'
modelb1.sdqfit <- sem(modelb1.sdq, data = df, missing = "fiml", fixed.x = FALSE)
summary(modelb1.sdqfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 10 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                               181.064
##   Degrees of freedom                                 2
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -22213.709
##   Loglikelihood unrestricted model (H1)     -22213.709
##                                                       
##   Akaike (AIC)                               44445.418
##   Bayesian (BIC)                             44506.417
##   Sample-size adjusted Bayesian (SABIC)      44477.817
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zsdq ~                                                                
##     SESscore         -0.030    0.020   -1.522    0.128   -0.068    0.009
##     Zgcse            -0.214    0.019  -11.193    0.000   -0.252   -0.177
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.427    0.000    0.422    0.473
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsdq              0.044    0.016    2.727    0.006    0.013    0.076
##     SESscore         -0.034    0.012   -2.916    0.004   -0.057   -0.011
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsdq              0.953    0.022   43.330    0.000    0.910    0.996
##     SESscore          0.875    0.016   56.319    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zsdq              0.052
standardizedsolution(modelb1.sdqfit)
##        lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1     Zsdq  ~ SESscore  -0.028 0.018  -1.522  0.128   -0.063    0.008
## 2     Zsdq  ~    Zgcse  -0.214 0.019 -11.463  0.000   -0.250   -0.177
## 3     Zsdq ~~     Zsdq   0.948 0.007 128.088  0.000    0.933    0.962
## 4 SESscore ~~ SESscore   1.000 0.000      NA     NA    1.000    1.000
## 5 SESscore ~~    Zgcse   0.478 0.010  49.316  0.000    0.459    0.497
## 6    Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 7     Zsdq ~1            0.044 0.016   2.732  0.006    0.013    0.076
## 8 SESscore ~1           -0.036 0.013  -2.916  0.004   -0.061   -0.012
## 9    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
modelb2.sdq <- 'Zsdq ~ SESscore + Zgcse + SES.gcse'
modelb2.sdqfit <- sem(modelb2.sdq, data = df, missing = "fiml", fixed.x = FALSE)
summary(modelb2.sdqfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 10 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        14
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                               181.150
##   Degrees of freedom                                 3
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -30931.856
##   Loglikelihood unrestricted model (H1)     -30931.856
##                                                       
##   Akaike (AIC)                               61891.713
##   Bayesian (BIC)                             61986.601
##   Sample-size adjusted Bayesian (SABIC)      61942.112
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zsdq ~                                                                
##     SESscore         -0.031    0.020   -1.549    0.121   -0.070    0.008
##     Zgcse            -0.214    0.019  -11.172    0.000   -0.252   -0.177
##     SES.gcse          0.005    0.018    0.292    0.770   -0.030    0.040
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.427    0.000    0.422    0.473
##     SES.gcse         -0.013    0.011   -1.118    0.263   -0.035    0.010
##   Zgcse ~~                                                              
##     SES.gcse         -0.118    0.012   -9.665    0.000   -0.142   -0.094
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsdq              0.042    0.018    2.348    0.019    0.007    0.077
##     SESscore         -0.034    0.012   -2.916    0.004   -0.057   -0.011
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
##     SES.gcse          0.444    0.012   36.803    0.000    0.420    0.467
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsdq              0.953    0.022   43.330    0.000    0.910    0.996
##     SESscore          0.875    0.016   56.319    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     SES.gcse          0.925    0.016   56.379    0.000    0.893    0.957
## 
## R-Square:
##                    Estimate
##     Zsdq              0.053
standardizedsolution(modelb2.sdqfit)
##         lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1      Zsdq  ~ SESscore  -0.029 0.019  -1.550  0.121   -0.065    0.008
## 2      Zsdq  ~    Zgcse  -0.214 0.019 -11.437  0.000   -0.250   -0.177
## 3      Zsdq  ~ SES.gcse   0.005 0.017   0.292  0.770   -0.029    0.039
## 4      Zsdq ~~     Zsdq   0.947 0.008 125.034  0.000    0.933    0.962
## 5  SESscore ~~ SESscore   1.000 0.000      NA     NA    1.000    1.000
## 6  SESscore ~~    Zgcse   0.478 0.010  49.316  0.000    0.459    0.497
## 7  SESscore ~~ SES.gcse  -0.014 0.013  -1.119  0.263   -0.039    0.011
## 8     Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 9     Zgcse ~~ SES.gcse  -0.123 0.012  -9.883  0.000   -0.147   -0.098
## 10 SES.gcse ~~ SES.gcse   1.000 0.000      NA     NA    1.000    1.000
## 11     Zsdq ~1            0.042 0.018   2.349  0.019    0.007    0.077
## 12 SESscore ~1           -0.036 0.013  -2.916  0.004   -0.061   -0.012
## 13    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
## 14 SES.gcse ~1            0.461 0.013  35.005  0.000    0.436    0.487
#get change in R2 for models with vs. w/0 moderation (modela1 vs. a2 and b1 vs b2) 
(PE.modela1.sdq <- parameterEstimates(modela1.sdqfit, rsquare = TRUE)) 
##      lhs op   rhs    est    se       z pvalue ci.lower ci.upper
## 1   Zsdq  ~  sex1 -0.194 0.033  -5.942      0   -0.258   -0.130
## 2   Zsdq  ~ Zgcse -0.227 0.017 -13.533      0   -0.260   -0.194
## 3   Zsdq ~~  Zsdq  0.944 0.022  43.330      0    0.902    0.987
## 4   sex1 ~~  sex1  0.249 0.004  56.956      0    0.241    0.258
## 5   sex1 ~~ Zgcse -0.026 0.006  -4.232      0   -0.038   -0.014
## 6  Zgcse ~~ Zgcse  1.000 0.018  56.956      0    0.965    1.034
## 7   Zsdq ~1        0.120 0.020   5.851      0    0.080    0.160
## 8   sex1 ~1        0.474 0.006  76.503      0    0.462    0.486
## 9  Zgcse ~1        0.000 0.012   0.000      1   -0.024    0.024
## 10  Zsdq r2  Zsdq  0.058    NA      NA     NA       NA       NA
PE.modela1.sdq$est[PE.modela1.sdq$op == "r2"]
## [1] 0.05846109
(PE.modela2.sdq <- parameterEstimates(modela2.sdqfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se       z pvalue ci.lower ci.upper
## 1      Zsdq  ~     sex1 -0.211 0.033  -6.342  0.000   -0.277   -0.146
## 2      Zsdq  ~    Zgcse -0.261 0.022 -12.091  0.000   -0.304   -0.219
## 3      Zsdq  ~ sex.gcse  0.086 0.034   2.515  0.012    0.019    0.153
## 4      Zsdq ~~     Zsdq  0.943 0.022  43.330  0.000    0.900    0.985
## 5      sex1 ~~     sex1  0.249 0.004  56.956  0.000    0.241    0.258
## 6      sex1 ~~    Zgcse -0.026 0.006  -4.232  0.000   -0.038   -0.014
## 7      sex1 ~~ sex.gcse -0.014 0.004  -3.175  0.001   -0.022   -0.005
## 8     Zgcse ~~    Zgcse  1.000 0.018  56.956  0.000    0.965    1.034
## 9     Zgcse ~~ sex.gcse  0.492 0.011  46.289  0.000    0.471    0.513
## 10 sex.gcse ~~ sex.gcse  0.492 0.009  56.956  0.000    0.475    0.509
## 11     Zsdq ~1           0.126 0.021   6.129  0.000    0.086    0.167
## 12     sex1 ~1           0.474 0.006  76.503  0.000    0.462    0.486
## 13    Zgcse ~1           0.000 0.012   0.000  1.000   -0.024    0.024
## 14 sex.gcse ~1          -0.026 0.009  -3.018  0.003   -0.043   -0.009
## 15     Zsdq r2     Zsdq  0.058    NA      NA     NA       NA       NA
PE.modela2.sdq$est[PE.modela2.sdq$op == "r2"]
## [1] 0.05848994
(PE.modelb1.sdq <- parameterEstimates(modelb1.sdqfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se       z pvalue ci.lower ci.upper
## 1      Zsdq  ~ SESscore -0.030 0.020  -1.522  0.128   -0.068    0.009
## 2      Zsdq  ~    Zgcse -0.214 0.019 -11.193  0.000   -0.252   -0.177
## 3      Zsdq ~~     Zsdq  0.953 0.022  43.330  0.000    0.910    0.996
## 4  SESscore ~~ SESscore  0.875 0.016  56.319  0.000    0.844    0.905
## 5  SESscore ~~    Zgcse  0.447 0.013  34.427  0.000    0.422    0.473
## 6     Zgcse ~~    Zgcse  1.000 0.018  56.956  0.000    0.965    1.034
## 7      Zsdq ~1           0.044 0.016   2.727  0.006    0.013    0.076
## 8  SESscore ~1          -0.034 0.012  -2.916  0.004   -0.057   -0.011
## 9     Zgcse ~1           0.000 0.012   0.000  1.000   -0.024    0.024
## 10     Zsdq r2     Zsdq  0.052    NA      NA     NA       NA       NA
PE.modelb1.sdq$est[PE.modelb1.sdq$op == "r2"]
## [1] 0.05213449
(PE.modelb2.sdq <- parameterEstimates(modelb2.sdqfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se       z pvalue ci.lower ci.upper
## 1      Zsdq  ~ SESscore -0.031 0.020  -1.549  0.121   -0.070    0.008
## 2      Zsdq  ~    Zgcse -0.214 0.019 -11.172  0.000   -0.252   -0.177
## 3      Zsdq  ~ SES.gcse  0.005 0.018   0.292  0.770   -0.030    0.040
## 4      Zsdq ~~     Zsdq  0.953 0.022  43.330  0.000    0.910    0.996
## 5  SESscore ~~ SESscore  0.875 0.016  56.319  0.000    0.844    0.905
## 6  SESscore ~~    Zgcse  0.447 0.013  34.427  0.000    0.422    0.473
## 7  SESscore ~~ SES.gcse -0.013 0.011  -1.118  0.263   -0.035    0.010
## 8     Zgcse ~~    Zgcse  1.000 0.018  56.956  0.000    0.965    1.034
## 9     Zgcse ~~ SES.gcse -0.118 0.012  -9.665  0.000   -0.142   -0.094
## 10 SES.gcse ~~ SES.gcse  0.925 0.016  56.379  0.000    0.893    0.957
## 11     Zsdq ~1           0.042 0.018   2.348  0.019    0.007    0.077
## 12 SESscore ~1          -0.034 0.012  -2.916  0.004   -0.057   -0.011
## 13    Zgcse ~1           0.000 0.012   0.000  1.000   -0.024    0.024
## 14 SES.gcse ~1           0.444 0.012  36.803  0.000    0.420    0.467
## 15     Zsdq r2     Zsdq  0.053    NA      NA     NA       NA       NA
PE.modelb2.sdq$est[PE.modelb2.sdq$op == "r2"]
## [1] 0.05255736
r2diffa.sdq <- (PE.modela2.sdq$est[PE.modela2.sdq$op == "r2"] - PE.modela1.sdq$est[PE.modela1.sdq$op == "r2"])
print(r2diffa.sdq)    #difference modela1 vs a2, incremental explained variance by sexxGCSE
## [1] 2.885033e-05
r2diffb.sdq <- (PE.modelb2.sdq$est[PE.modelb2.sdq$op == "r2"] - PE.modelb1.sdq$est[PE.modelb1.sdq$op == "r2"])
print(r2diffb.sdq)    #difference modelb1 vs b2, incremental explained variance by SESxGCSE
## [1] 0.0004228697
modela1.alc <- 'Zalc ~ sex1 + Zgcse'
modela1.alcfit <- sem(modela1.alc, data = df, missing = "fiml", fixed.x = FALSE)
summary(modela1.alcfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 15 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                          6488
##   Number of missing patterns                         2
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                43.625
##   Degrees of freedom                                 2
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -18371.211
##   Loglikelihood unrestricted model (H1)     -18371.211
##                                                       
##   Akaike (AIC)                               36760.421
##   Bayesian (BIC)                             36821.420
##   Sample-size adjusted Bayesian (SABIC)      36792.821
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zalc ~                                                                
##     sex1              0.232    0.036    6.366    0.000    0.161    0.304
##     Zgcse             0.032    0.019    1.704    0.088   -0.005    0.069
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zalc             -0.094    0.023   -4.157    0.000   -0.139   -0.050
##     sex1              0.474    0.006   76.504    0.000    0.462    0.486
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zalc              0.986    0.025   39.806    0.000    0.937    1.035
##     sex1              0.249    0.004   56.957    0.000    0.241    0.258
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zalc              0.014
standardizedsolution(modela1.alcfit)
##     lhs op   rhs est.std    se       z pvalue ci.lower ci.upper
## 1  Zalc  ~  sex1   0.116 0.018   6.420  0.000    0.080    0.151
## 2  Zalc  ~ Zgcse   0.032 0.019   1.705  0.088   -0.005    0.069
## 3  Zalc ~~  Zalc   0.986 0.004 234.192  0.000    0.978    0.994
## 4  sex1 ~~  sex1   1.000 0.000      NA     NA    1.000    1.000
## 5  sex1 ~~ Zgcse  -0.053 0.012  -4.250  0.000   -0.077   -0.028
## 6 Zgcse ~~ Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 7  Zalc ~1        -0.094 0.023  -4.175  0.000   -0.138   -0.050
## 8  sex1 ~1         0.950 0.015  63.510  0.000    0.920    0.979
## 9 Zgcse ~1         0.000 0.012   0.000  1.000   -0.024    0.024
modela2.alc <- 'Zalc ~ sex1 + Zgcse + sex.gcse'
modela2.alcfit <- sem(modela2.alc, data = df, missing = "fiml", fixed.x = FALSE)
summary(modela2.alcfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 23 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        14
## 
##   Number of observations                          6488
##   Number of missing patterns                         2
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                43.625
##   Degrees of freedom                                 3
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -23069.887
##   Loglikelihood unrestricted model (H1)     -23069.887
##                                                       
##   Akaike (AIC)                               46167.774
##   Bayesian (BIC)                             46262.661
##   Sample-size adjusted Bayesian (SABIC)      46218.173
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zalc ~                                                                
##     sex1              0.232    0.038    6.172    0.000    0.158    0.306
##     Zgcse             0.032    0.024    1.325    0.185   -0.015    0.079
##     sex.gcse          0.000    0.039    0.013    0.990   -0.075    0.076
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     sex.gcse         -0.014    0.004   -3.175    0.001   -0.022   -0.005
##   Zgcse ~~                                                              
##     sex.gcse          0.492    0.011   46.289    0.000    0.471    0.513
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zalc             -0.094    0.023   -4.116    0.000   -0.139   -0.049
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
##     sex.gcse         -0.026    0.009   -3.018    0.003   -0.043   -0.009
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zalc              0.986    0.025   39.806    0.000    0.937    1.035
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     sex.gcse          0.492    0.009   56.956    0.000    0.475    0.509
## 
## R-Square:
##                    Estimate
##     Zalc              0.014
standardizedsolution(modela2.alcfit)
##         lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1      Zalc  ~     sex1   0.116 0.019   6.226  0.000    0.079    0.152
## 2      Zalc  ~    Zgcse   0.032 0.024   1.325  0.185   -0.015    0.079
## 3      Zalc  ~ sex.gcse   0.000 0.027   0.013  0.990   -0.053    0.053
## 4      Zalc ~~     Zalc   0.986 0.004 229.886  0.000    0.978    0.994
## 5      sex1 ~~     sex1   1.000 0.000      NA     NA    1.000    1.000
## 6      sex1 ~~    Zgcse  -0.053 0.012  -4.250  0.000   -0.077   -0.028
## 7      sex1 ~~ sex.gcse  -0.039 0.012  -3.182  0.001   -0.064   -0.015
## 8     Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 9     Zgcse ~~ sex.gcse   0.702 0.006 111.584  0.000    0.690    0.715
## 10 sex.gcse ~~ sex.gcse   1.000 0.000      NA     NA    1.000    1.000
## 11     Zalc ~1           -0.094 0.023  -4.134  0.000   -0.139   -0.050
## 12     sex1 ~1            0.950 0.015  63.510  0.000    0.920    0.979
## 13    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
## 14 sex.gcse ~1           -0.037 0.012  -3.017  0.003   -0.062   -0.013
modelb1.alc <- 'Zalc ~ SESscore + Zgcse'
modelb1.alcfit <- sem(modelb1.alc, data = df, missing = "fiml", fixed.x = FALSE)
summary(modelb1.alcfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 9 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                         9
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                32.815
##   Degrees of freedom                                 2
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -21456.335
##   Loglikelihood unrestricted model (H1)     -21456.335
##                                                       
##   Akaike (AIC)                               42930.671
##   Bayesian (BIC)                             42991.670
##   Sample-size adjusted Bayesian (SABIC)      42963.070
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zalc ~                                                                
##     SESscore          0.119    0.022    5.442    0.000    0.076    0.161
##     Zgcse            -0.020    0.021   -0.948    0.343   -0.062    0.022
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.430    0.000    0.422    0.473
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zalc             -0.004    0.018   -0.200    0.841   -0.039    0.032
##     SESscore         -0.034    0.012   -2.909    0.004   -0.057   -0.011
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zalc              0.989    0.025   39.800    0.000    0.941    1.038
##     SESscore          0.875    0.016   56.316    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zalc              0.011
standardizedsolution(modelb1.alcfit)
##        lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1     Zalc  ~ SESscore   0.111 0.020   5.473  0.000    0.071    0.151
## 2     Zalc  ~    Zgcse  -0.020 0.021  -0.948  0.343   -0.062    0.022
## 3     Zalc ~~     Zalc   0.989 0.004 270.316  0.000    0.982    0.997
## 4 SESscore ~~ SESscore   1.000 0.000      NA     NA    1.000    1.000
## 5 SESscore ~~    Zgcse   0.478 0.010  49.327  0.000    0.459    0.497
## 6    Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 7     Zalc ~1           -0.004 0.018  -0.200  0.841   -0.039    0.032
## 8 SESscore ~1           -0.036 0.013  -2.908  0.004   -0.061   -0.012
## 9    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
modelb2.alc <- 'Zalc ~ SESscore + Zgcse + SES.gcse'
modelb2.alcfit <- sem(modelb2.alc, data = df, missing = "fiml", fixed.x = FALSE)
summary(modelb2.alcfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 11 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        14
## 
##   Number of observations                          6488
##   Number of missing patterns                         4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                32.817
##   Degrees of freedom                                 3
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -30174.525
##   Loglikelihood unrestricted model (H1)     -30174.525
##                                                       
##   Akaike (AIC)                               60377.049
##   Bayesian (BIC)                             60471.937
##   Sample-size adjusted Bayesian (SABIC)      60427.449
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zalc ~                                                                
##     SESscore          0.118    0.022    5.289    0.000    0.075    0.162
##     Zgcse            -0.020    0.021   -0.946    0.344   -0.062    0.022
##     SES.gcse          0.001    0.021    0.051    0.959   -0.039    0.041
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.431    0.000    0.422    0.473
##     SES.gcse         -0.013    0.011   -1.119    0.263   -0.035    0.010
##   Zgcse ~~                                                              
##     SES.gcse         -0.118    0.012   -9.663    0.000   -0.142   -0.094
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zalc             -0.004    0.020   -0.203    0.839   -0.043    0.035
##     SESscore         -0.034    0.012   -2.909    0.004   -0.057   -0.011
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
##     SES.gcse          0.444    0.012   36.803    0.000    0.420    0.467
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zalc              0.989    0.025   39.800    0.000    0.941    1.038
##     SESscore          0.875    0.016   56.317    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     SES.gcse          0.925    0.016   56.379    0.000    0.893    0.957
## 
## R-Square:
##                    Estimate
##     Zalc              0.011
standardizedsolution(modelb2.alcfit)
##         lhs op      rhs est.std    se       z pvalue ci.lower ci.upper
## 1      Zalc  ~ SESscore   0.111 0.021   5.321  0.000    0.070    0.152
## 2      Zalc  ~    Zgcse  -0.020 0.021  -0.946  0.344   -0.062    0.022
## 3      Zalc  ~ SES.gcse   0.001 0.020   0.051  0.959   -0.038    0.040
## 4      Zalc ~~     Zalc   0.989 0.004 264.153  0.000    0.982    0.997
## 5  SESscore ~~ SESscore   1.000 0.000      NA     NA    1.000    1.000
## 6  SESscore ~~    Zgcse   0.478 0.010  49.328  0.000    0.459    0.497
## 7  SESscore ~~ SES.gcse  -0.014 0.013  -1.119  0.263   -0.039    0.011
## 8     Zgcse ~~    Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 9     Zgcse ~~ SES.gcse  -0.123 0.012  -9.881  0.000   -0.147   -0.098
## 10 SES.gcse ~~ SES.gcse   1.000 0.000      NA     NA    1.000    1.000
## 11     Zalc ~1           -0.004 0.020  -0.203  0.839   -0.043    0.035
## 12 SESscore ~1           -0.036 0.013  -2.908  0.004   -0.061   -0.012
## 13    Zgcse ~1            0.000 0.012   0.000  1.000   -0.024    0.024
## 14 SES.gcse ~1            0.461 0.013  35.006  0.000    0.436    0.487
#get change in R2 for models with vs. w/0 moderation (modela1 vs. a2 and b1 vs b2) 
(PE.modela1.alc <- parameterEstimates(modela1.alcfit, rsquare = TRUE)) 
##      lhs op   rhs    est    se      z pvalue ci.lower ci.upper
## 1   Zalc  ~  sex1  0.232 0.036  6.366  0.000    0.161    0.304
## 2   Zalc  ~ Zgcse  0.032 0.019  1.704  0.088   -0.005    0.069
## 3   Zalc ~~  Zalc  0.986 0.025 39.806  0.000    0.937    1.035
## 4   sex1 ~~  sex1  0.249 0.004 56.957  0.000    0.241    0.258
## 5   sex1 ~~ Zgcse -0.026 0.006 -4.232  0.000   -0.038   -0.014
## 6  Zgcse ~~ Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 7   Zalc ~1       -0.094 0.023 -4.157  0.000   -0.139   -0.050
## 8   sex1 ~1        0.474 0.006 76.504  0.000    0.462    0.486
## 9  Zgcse ~1        0.000 0.012  0.000  1.000   -0.024    0.024
## 10  Zalc r2  Zalc  0.014    NA     NA     NA       NA       NA
PE.modela1.alc$est[PE.modela1.alc$op == "r2"]
## [1] 0.01405924
(PE.modela2.alc <- parameterEstimates(modela2.alcfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1      Zalc  ~     sex1  0.232 0.038  6.172  0.000    0.158    0.306
## 2      Zalc  ~    Zgcse  0.032 0.024  1.325  0.185   -0.015    0.079
## 3      Zalc  ~ sex.gcse  0.000 0.039  0.013  0.990   -0.075    0.076
## 4      Zalc ~~     Zalc  0.986 0.025 39.806  0.000    0.937    1.035
## 5      sex1 ~~     sex1  0.249 0.004 56.956  0.000    0.241    0.258
## 6      sex1 ~~    Zgcse -0.026 0.006 -4.232  0.000   -0.038   -0.014
## 7      sex1 ~~ sex.gcse -0.014 0.004 -3.175  0.001   -0.022   -0.005
## 8     Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 9     Zgcse ~~ sex.gcse  0.492 0.011 46.289  0.000    0.471    0.513
## 10 sex.gcse ~~ sex.gcse  0.492 0.009 56.956  0.000    0.475    0.509
## 11     Zalc ~1          -0.094 0.023 -4.116  0.000   -0.139   -0.049
## 12     sex1 ~1           0.474 0.006 76.503  0.000    0.462    0.486
## 13    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 14 sex.gcse ~1          -0.026 0.009 -3.018  0.003   -0.043   -0.009
## 15     Zalc r2     Zalc  0.014    NA     NA     NA       NA       NA
PE.modela2.alc$est[PE.modela2.alc$op == "r2"]
## [1] 0.01404955
(PE.modelb1.alc <- parameterEstimates(modelb1.alcfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1      Zalc  ~ SESscore  0.119 0.022  5.442  0.000    0.076    0.161
## 2      Zalc  ~    Zgcse -0.020 0.021 -0.948  0.343   -0.062    0.022
## 3      Zalc ~~     Zalc  0.989 0.025 39.800  0.000    0.941    1.038
## 4  SESscore ~~ SESscore  0.875 0.016 56.316  0.000    0.844    0.905
## 5  SESscore ~~    Zgcse  0.447 0.013 34.430  0.000    0.422    0.473
## 6     Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 7      Zalc ~1          -0.004 0.018 -0.200  0.841   -0.039    0.032
## 8  SESscore ~1          -0.034 0.012 -2.909  0.004   -0.057   -0.011
## 9     Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 10     Zalc r2     Zalc  0.011    NA     NA     NA       NA       NA
PE.modelb1.alc$est[PE.modelb1.alc$op == "r2"]
## [1] 0.01058165
(PE.modelb2.alc <- parameterEstimates(modelb2.alcfit, rsquare = TRUE)) 
##         lhs op      rhs    est    se      z pvalue ci.lower ci.upper
## 1      Zalc  ~ SESscore  0.118 0.022  5.289  0.000    0.075    0.162
## 2      Zalc  ~    Zgcse -0.020 0.021 -0.946  0.344   -0.062    0.022
## 3      Zalc  ~ SES.gcse  0.001 0.021  0.051  0.959   -0.039    0.041
## 4      Zalc ~~     Zalc  0.989 0.025 39.800  0.000    0.941    1.038
## 5  SESscore ~~ SESscore  0.875 0.016 56.317  0.000    0.844    0.905
## 6  SESscore ~~    Zgcse  0.447 0.013 34.431  0.000    0.422    0.473
## 7  SESscore ~~ SES.gcse -0.013 0.011 -1.119  0.263   -0.035    0.010
## 8     Zgcse ~~    Zgcse  1.000 0.018 56.956  0.000    0.965    1.034
## 9     Zgcse ~~ SES.gcse -0.118 0.012 -9.663  0.000   -0.142   -0.094
## 10 SES.gcse ~~ SES.gcse  0.925 0.016 56.379  0.000    0.893    0.957
## 11     Zalc ~1          -0.004 0.020 -0.203  0.839   -0.043    0.035
## 12 SESscore ~1          -0.034 0.012 -2.909  0.004   -0.057   -0.011
## 13    Zgcse ~1           0.000 0.012  0.000  1.000   -0.024    0.024
## 14 SES.gcse ~1           0.444 0.012 36.803  0.000    0.420    0.467
## 15     Zalc r2     Zalc  0.011    NA     NA     NA       NA       NA
PE.modelb2.alc$est[PE.modelb2.alc$op == "r2"]
## [1] 0.01053766
r2diffa.alc <- (PE.modela2.alc$est[PE.modela2.alc$op == "r2"] - PE.modela1.alc$est[PE.modela1.alc$op == "r2"])
print(r2diffa.alc)    #difference modela1 vs a2, incremental explained variance by sexxGCSE
## [1] -9.687592e-06
r2diffb.alc <- (PE.modelb2.alc$est[PE.modelb2.alc$op == "r2"] - PE.modelb1.alc$est[PE.modelb1.alc$op == "r2"])
print(r2diffb.alc)    #difference modelb1 vs b2, incremental explained variance by SESxGCSE
## [1] -4.398784e-05

logistic and multi-nominal regression with moderation

modela1.benf <- 'u1cbenf11 ~ sex1 + Zgcse'
modela1.benffit <- sem(modela1.benf, data = df, ordered = c("u1cbenf11"), missing = "listwise")
summary(modela1.benffit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 11 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         3
## 
##                                                   Used       Total
##   Number of observations                          3736        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   u1cbenf11 ~                                                           
##     sex1             -0.186    0.077   -2.408    0.016   -0.338   -0.035
##     Zgcse            -0.294    0.037   -7.972    0.000   -0.367   -0.222
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .u1cbenf11         0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     u1cbenf11|t1      1.618    0.045   36.174    0.000    1.530    1.706
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .u1cbenf11         1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     u1cbenf11         1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     u1cbenf11         0.080
standardizedsolution(modela1.benffit)
##          lhs  op       rhs est.std    se      z pvalue ci.lower ci.upper
## 1  u1cbenf11   ~      sex1  -0.087 0.036 -2.427  0.015   -0.157   -0.017
## 2  u1cbenf11   ~     Zgcse  -0.268 0.031 -8.587  0.000   -0.329   -0.207
## 3  u1cbenf11   |        t1   1.552 0.046 33.437  0.000    1.461    1.643
## 4  u1cbenf11  ~~ u1cbenf11   0.920 0.018 52.144  0.000    0.886    0.955
## 5       sex1  ~~      sex1   1.000 0.000     NA     NA    1.000    1.000
## 6       sex1  ~~     Zgcse   0.011 0.000     NA     NA    0.011    0.011
## 7      Zgcse  ~~     Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 8  u1cbenf11 ~*~ u1cbenf11   1.000 0.000     NA     NA    1.000    1.000
## 9  u1cbenf11  ~1             0.000 0.000     NA     NA    0.000    0.000
## 10      sex1  ~1             0.788 0.000     NA     NA    0.788    0.788
## 11     Zgcse  ~1             0.206 0.000     NA     NA    0.206    0.206
modela2.benf <- 'u1cbenf11 ~ sex1 + Zgcse + sex.gcse'
modela2.benffit <- sem(modela2.benf, data = df, ordered = c("u1cbenf11"), missing = "listwise")
summary(modela2.benffit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 15 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         4
## 
##                                                   Used       Total
##   Number of observations                          3736        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   u1cbenf11 ~                                                           
##     sex1             -0.176    0.079   -2.235    0.025   -0.330   -0.022
##     Zgcse            -0.315    0.044   -7.225    0.000   -0.400   -0.229
##     sex.gcse          0.061    0.083    0.742    0.458   -0.101    0.223
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .u1cbenf11         0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     u1cbenf11|t1      1.622    0.045   36.216    0.000    1.534    1.709
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .u1cbenf11         1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     u1cbenf11         1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     u1cbenf11         0.077
standardizedsolution(modela2.benffit)
##          lhs  op       rhs est.std    se      z pvalue ci.lower ci.upper
## 1  u1cbenf11   ~      sex1  -0.082 0.036 -2.252  0.024   -0.154   -0.011
## 2  u1cbenf11   ~     Zgcse  -0.287 0.038 -7.560  0.000   -0.361   -0.212
## 3  u1cbenf11   ~  sex.gcse   0.036 0.048  0.740  0.459   -0.059    0.130
## 4  u1cbenf11   |        t1   1.558 0.047 33.343  0.000    1.466    1.649
## 5  u1cbenf11  ~~ u1cbenf11   0.923 0.018 51.244  0.000    0.888    0.958
## 6       sex1  ~~      sex1   1.000 0.000     NA     NA    1.000    1.000
## 7       sex1  ~~     Zgcse   0.011 0.000     NA     NA    0.011    0.011
## 8       sex1  ~~  sex.gcse   0.167 0.000     NA     NA    0.167    0.167
## 9      Zgcse  ~~     Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 10     Zgcse  ~~  sex.gcse   0.622 0.000     NA     NA    0.622    0.622
## 11  sex.gcse  ~~  sex.gcse   1.000 0.000     NA     NA    1.000    1.000
## 12 u1cbenf11 ~*~ u1cbenf11   1.000 0.000     NA     NA    1.000    1.000
## 13 u1cbenf11  ~1             0.000 0.000     NA     NA    0.000    0.000
## 14      sex1  ~1             0.788 0.000     NA     NA    0.788    0.788
## 15     Zgcse  ~1             0.206 0.000     NA     NA    0.206    0.206
## 16  sex.gcse  ~1             0.132 0.000     NA     NA    0.132    0.132
modelb1.benf <- 'u1cbenf11 ~ SESscore + Zgcse'
modelb1.benffit <- sem(modelb1.benf, data = df, ordered = c("u1cbenf11"), missing = "listwise")
summary(modelb1.benffit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 7 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         3
## 
##                                                   Used       Total
##   Number of observations                          3691        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   u1cbenf11 ~                                                           
##     SESscore         -0.140    0.043   -3.251    0.001   -0.224   -0.056
##     Zgcse            -0.232    0.041   -5.664    0.000   -0.312   -0.152
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .u1cbenf11         0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     u1cbenf11|t1      1.696    0.038   44.919    0.000    1.622    1.770
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .u1cbenf11         1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     u1cbenf11         1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     u1cbenf11         0.084
standardizedsolution(modelb1.benffit)
##          lhs  op       rhs est.std    se      z pvalue ci.lower ci.upper
## 1  u1cbenf11   ~  SESscore  -0.125 0.038 -3.297  0.001   -0.199   -0.051
## 2  u1cbenf11   ~     Zgcse  -0.209 0.036 -5.868  0.000   -0.279   -0.139
## 3  u1cbenf11   |        t1   1.623 0.036 44.801  0.000    1.552    1.694
## 4  u1cbenf11  ~~ u1cbenf11   0.916 0.018 49.897  0.000    0.880    0.952
## 5   SESscore  ~~  SESscore   1.000 0.000     NA     NA    1.000    1.000
## 6   SESscore  ~~     Zgcse   0.466 0.000     NA     NA    0.466    0.466
## 7      Zgcse  ~~     Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 8  u1cbenf11 ~*~ u1cbenf11   1.000 0.000     NA     NA    1.000    1.000
## 9  u1cbenf11  ~1             0.000 0.000     NA     NA    0.000    0.000
## 10  SESscore  ~1             0.060 0.000     NA     NA    0.060    0.060
## 11     Zgcse  ~1             0.212 0.000     NA     NA    0.212    0.212
modelb2.benf <- 'u1cbenf11 ~ SESscore + Zgcse + SES.gcse'
modelb2.benffit <- sem(modelb2.benf, data = df, ordered = c("u1cbenf11"), missing = "listwise")
summary(modelb2.benffit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 9 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         4
## 
##                                                   Used       Total
##   Number of observations                          3691        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   u1cbenf11 ~                                                           
##     SESscore         -0.139    0.043   -3.196    0.001   -0.224   -0.054
##     Zgcse            -0.227    0.043   -5.236    0.000   -0.312   -0.142
##     SES.gcse          0.015    0.039    0.384    0.701   -0.062    0.092
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .u1cbenf11         0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     u1cbenf11|t1      1.701    0.040   42.728    0.000    1.623    1.779
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .u1cbenf11         1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     u1cbenf11         1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     u1cbenf11         0.081
standardizedsolution(modelb2.benffit)
##          lhs  op       rhs est.std    se      z pvalue ci.lower ci.upper
## 1  u1cbenf11   ~  SESscore  -0.124 0.038 -3.246  0.001   -0.199   -0.049
## 2  u1cbenf11   ~     Zgcse  -0.206 0.038 -5.448  0.000   -0.280   -0.132
## 3  u1cbenf11   ~  SES.gcse   0.013 0.034  0.383  0.702   -0.054    0.080
## 4  u1cbenf11   |        t1   1.631 0.042 39.204  0.000    1.550    1.713
## 5  u1cbenf11  ~~ u1cbenf11   0.919 0.020 44.984  0.000    0.879    0.959
## 6   SESscore  ~~  SESscore   1.000 0.000     NA     NA    1.000    1.000
## 7   SESscore  ~~     Zgcse   0.466 0.000     NA     NA    0.466    0.466
## 8   SESscore  ~~  SES.gcse   0.173 0.000     NA     NA    0.173    0.173
## 9      Zgcse  ~~     Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 10     Zgcse  ~~  SES.gcse   0.038 0.000     NA     NA    0.038    0.038
## 11  SES.gcse  ~~  SES.gcse   1.000 0.000     NA     NA    1.000    1.000
## 12 u1cbenf11 ~*~ u1cbenf11   1.000 0.000     NA     NA    1.000    1.000
## 13 u1cbenf11  ~1             0.000 0.000     NA     NA    0.000    0.000
## 14  SESscore  ~1             0.060 0.000     NA     NA    0.060    0.060
## 15     Zgcse  ~1             0.212 0.000     NA     NA    0.212    0.212
## 16  SES.gcse  ~1             0.462 0.000     NA     NA    0.462    0.462
#get change in R2 for models with vs. w/0 moderation (modela1 vs. a2 and b1 vs b2) 
(PE.modela1.benf <- parameterEstimates(modela1.benffit, rsquare = TRUE)) 
##          lhs  op       rhs    est    se      z pvalue ci.lower ci.upper
## 1  u1cbenf11   ~      sex1 -0.186 0.077 -2.408  0.016   -0.338   -0.035
## 2  u1cbenf11   ~     Zgcse -0.294 0.037 -7.972  0.000   -0.367   -0.222
## 3  u1cbenf11   |        t1  1.618 0.045 36.174  0.000    1.530    1.706
## 4  u1cbenf11  ~~ u1cbenf11  1.000 0.000     NA     NA    1.000    1.000
## 5       sex1  ~~      sex1  0.236 0.000     NA     NA    0.236    0.236
## 6       sex1  ~~     Zgcse  0.005 0.000     NA     NA    0.005    0.005
## 7      Zgcse  ~~     Zgcse  0.898 0.000     NA     NA    0.898    0.898
## 8  u1cbenf11 ~*~ u1cbenf11  1.000 0.000     NA     NA    1.000    1.000
## 9  u1cbenf11  ~1            0.000 0.000     NA     NA    0.000    0.000
## 10      sex1  ~1            0.383 0.000     NA     NA    0.383    0.383
## 11     Zgcse  ~1            0.195 0.000     NA     NA    0.195    0.195
## 12 u1cbenf11  r2 u1cbenf11  0.080    NA     NA     NA       NA       NA
PE.modela1.benf$est[PE.modela1.benf$op == "r2"]
## [1] 0.07966791
(PE.modela2.benf <- parameterEstimates(modela2.benffit, rsquare = TRUE)) 
##          lhs  op       rhs    est    se      z pvalue ci.lower ci.upper
## 1  u1cbenf11   ~      sex1 -0.176 0.079 -2.235  0.025   -0.330   -0.022
## 2  u1cbenf11   ~     Zgcse -0.315 0.044 -7.225  0.000   -0.400   -0.229
## 3  u1cbenf11   ~  sex.gcse  0.061 0.083  0.742  0.458   -0.101    0.223
## 4  u1cbenf11   |        t1  1.622 0.045 36.216  0.000    1.534    1.709
## 5  u1cbenf11  ~~ u1cbenf11  1.000 0.000     NA     NA    1.000    1.000
## 6       sex1  ~~      sex1  0.236 0.000     NA     NA    0.236    0.236
## 7       sex1  ~~     Zgcse  0.005 0.000     NA     NA    0.005    0.005
## 8       sex1  ~~  sex.gcse  0.049 0.000     NA     NA    0.049    0.049
## 9      Zgcse  ~~     Zgcse  0.898 0.000     NA     NA    0.898    0.898
## 10     Zgcse  ~~  sex.gcse  0.357 0.000     NA     NA    0.357    0.357
## 11  sex.gcse  ~~  sex.gcse  0.366 0.000     NA     NA    0.366    0.366
## 12 u1cbenf11 ~*~ u1cbenf11  1.000 0.000     NA     NA    1.000    1.000
## 13 u1cbenf11  ~1            0.000 0.000     NA     NA    0.000    0.000
## 14      sex1  ~1            0.383 0.000     NA     NA    0.383    0.383
## 15     Zgcse  ~1            0.195 0.000     NA     NA    0.195    0.195
## 16  sex.gcse  ~1            0.080 0.000     NA     NA    0.080    0.080
## 17 u1cbenf11  r2 u1cbenf11  0.077    NA     NA     NA       NA       NA
PE.modela2.benf$est[PE.modela2.benf$op == "r2"]
## [1] 0.07705216
(PE.modelb1.benf <- parameterEstimates(modelb1.benffit, rsquare = TRUE)) 
##          lhs  op       rhs    est    se      z pvalue ci.lower ci.upper
## 1  u1cbenf11   ~  SESscore -0.140 0.043 -3.251  0.001   -0.224   -0.056
## 2  u1cbenf11   ~     Zgcse -0.232 0.041 -5.664  0.000   -0.312   -0.152
## 3  u1cbenf11   |        t1  1.696 0.038 44.919  0.000    1.622    1.770
## 4  u1cbenf11  ~~ u1cbenf11  1.000 0.000     NA     NA    1.000    1.000
## 5   SESscore  ~~  SESscore  0.871 0.000     NA     NA    0.871    0.871
## 6   SESscore  ~~     Zgcse  0.410 0.000     NA     NA    0.410    0.410
## 7      Zgcse  ~~     Zgcse  0.891 0.000     NA     NA    0.891    0.891
## 8  u1cbenf11 ~*~ u1cbenf11  1.000 0.000     NA     NA    1.000    1.000
## 9  u1cbenf11  ~1            0.000 0.000     NA     NA    0.000    0.000
## 10  SESscore  ~1            0.056 0.000     NA     NA    0.056    0.056
## 11     Zgcse  ~1            0.201 0.000     NA     NA    0.201    0.201
## 12 u1cbenf11  r2 u1cbenf11  0.084    NA     NA     NA       NA       NA
PE.modelb1.benf$est[PE.modelb1.benf$op == "r2"]
## [1] 0.08387213
(PE.modelb2.benf <- parameterEstimates(modelb2.benffit, rsquare = TRUE)) 
##          lhs  op       rhs    est    se      z pvalue ci.lower ci.upper
## 1  u1cbenf11   ~  SESscore -0.139 0.043 -3.196  0.001   -0.224   -0.054
## 2  u1cbenf11   ~     Zgcse -0.227 0.043 -5.236  0.000   -0.312   -0.142
## 3  u1cbenf11   ~  SES.gcse  0.015 0.039  0.384  0.701   -0.062    0.092
## 4  u1cbenf11   |        t1  1.701 0.040 42.728  0.000    1.623    1.779
## 5  u1cbenf11  ~~ u1cbenf11  1.000 0.000     NA     NA    1.000    1.000
## 6   SESscore  ~~  SESscore  0.871 0.000     NA     NA    0.871    0.871
## 7   SESscore  ~~     Zgcse  0.410 0.000     NA     NA    0.410    0.410
## 8   SESscore  ~~  SES.gcse  0.147 0.000     NA     NA    0.147    0.147
## 9      Zgcse  ~~     Zgcse  0.891 0.000     NA     NA    0.891    0.891
## 10     Zgcse  ~~  SES.gcse  0.033 0.000     NA     NA    0.033    0.033
## 11  SES.gcse  ~~  SES.gcse  0.834 0.000     NA     NA    0.834    0.834
## 12 u1cbenf11 ~*~ u1cbenf11  1.000 0.000     NA     NA    1.000    1.000
## 13 u1cbenf11  ~1            0.000 0.000     NA     NA    0.000    0.000
## 14  SESscore  ~1            0.056 0.000     NA     NA    0.056    0.056
## 15     Zgcse  ~1            0.201 0.000     NA     NA    0.201    0.201
## 16  SES.gcse  ~1            0.422 0.000     NA     NA    0.422    0.422
## 17 u1cbenf11  r2 u1cbenf11  0.081    NA     NA     NA       NA       NA
PE.modelb2.benf$est[PE.modelb2.benf$op == "r2"]
## [1] 0.08077858
r2diffa.benf <- (PE.modela2.benf$est[PE.modela2.benf$op == "r2"] - PE.modela1.benf$est[PE.modela1.benf$op == "r2"])
print(r2diffa.benf)    #difference modela1 vs a2, incremental explained variance by sexxGCSE
## [1] -0.002615749
r2diffb.benf <- (PE.modelb2.benf$est[PE.modelb2.benf$op == "r2"] - PE.modelb1.benf$est[PE.modelb1.benf$op == "r2"])
print(r2diffb.benf)    #difference modelb1 vs b2, incremental explained variance by SESxGCSE
## [1] -0.003093544
modela1.status_bin <- 'status_bin ~ sex1 + Zgcse'
modela1.status_binfit <- sem(modela1.status_bin, data = df, ordered = c("status_bin"), missing = "listwise")
summary(modela1.status_binfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 7 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         3
## 
##                                                   Used       Total
##   Number of observations                          3743        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   status_bin ~                                                          
##     sex1             -0.028    0.057   -0.490    0.624   -0.139    0.083
##     Zgcse            -0.016    0.028   -0.595    0.552   -0.071    0.038
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .status_bin        0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     status_bin|t1    -1.277    0.036  -35.627    0.000   -1.347   -1.206
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .status_bin        1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     status_bin        1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     status_bin        0.000
standardizedsolution(modela1.status_binfit)
##           lhs  op        rhs est.std    se       z pvalue ci.lower ci.upper
## 1  status_bin   ~       sex1  -0.014 0.028  -0.490  0.624   -0.068    0.041
## 2  status_bin   ~      Zgcse  -0.016 0.026  -0.595  0.552   -0.067    0.036
## 3  status_bin   |         t1  -1.276 0.035 -35.997  0.000   -1.346   -1.207
## 4  status_bin  ~~ status_bin   1.000 0.001 907.238  0.000    0.997    1.002
## 5        sex1  ~~       sex1   1.000 0.000      NA     NA    1.000    1.000
## 6        sex1  ~~      Zgcse   0.013 0.000      NA     NA    0.013    0.013
## 7       Zgcse  ~~      Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 8  status_bin ~*~ status_bin   1.000 0.000      NA     NA    1.000    1.000
## 9  status_bin  ~1              0.000 0.000      NA     NA    0.000    0.000
## 10       sex1  ~1              0.789 0.000      NA     NA    0.789    0.789
## 11      Zgcse  ~1              0.209 0.000      NA     NA    0.209    0.209
modela2.status_bin <- 'status_bin ~ sex1 + Zgcse + sex.gcse'
modela2.status_binfit <- sem(modela2.status_bin, data = df, ordered = c("status_bin"), missing = "listwise")
summary(modela2.status_binfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 13 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         4
## 
##                                                   Used       Total
##   Number of observations                          3743        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   status_bin ~                                                          
##     sex1             -0.023    0.058   -0.401    0.688   -0.137    0.091
##     Zgcse            -0.008    0.035   -0.232    0.816   -0.078    0.061
##     sex.gcse         -0.021    0.057   -0.363    0.716   -0.131    0.090
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .status_bin        0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     status_bin|t1    -1.275    0.036  -35.306    0.000   -1.346   -1.204
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .status_bin        1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     status_bin        1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     status_bin        0.001
standardizedsolution(modela2.status_binfit)
##           lhs  op        rhs est.std    se       z pvalue ci.lower ci.upper
## 1  status_bin   ~       sex1  -0.011 0.028  -0.401  0.688   -0.067    0.044
## 2  status_bin   ~      Zgcse  -0.008 0.033  -0.232  0.816   -0.073    0.058
## 3  status_bin   ~   sex.gcse  -0.012 0.034  -0.363  0.716   -0.080    0.055
## 4  status_bin   |         t1  -1.275 0.036 -35.626  0.000   -1.345   -1.205
## 5  status_bin  ~~ status_bin   0.999 0.001 830.245  0.000    0.997    1.002
## 6        sex1  ~~       sex1   1.000 0.000      NA     NA    1.000    1.000
## 7        sex1  ~~      Zgcse   0.013 0.000      NA     NA    0.013    0.013
## 8        sex1  ~~   sex.gcse   0.171 0.000      NA     NA    0.171    0.171
## 9       Zgcse  ~~      Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 10      Zgcse  ~~   sex.gcse   0.624 0.000      NA     NA    0.624    0.624
## 11   sex.gcse  ~~   sex.gcse   1.000 0.000      NA     NA    1.000    1.000
## 12 status_bin ~*~ status_bin   1.000 0.000      NA     NA    1.000    1.000
## 13 status_bin  ~1              0.000 0.000      NA     NA    0.000    0.000
## 14       sex1  ~1              0.789 0.000      NA     NA    0.789    0.789
## 15      Zgcse  ~1              0.209 0.000      NA     NA    0.209    0.209
## 16   sex.gcse  ~1              0.135 0.000      NA     NA    0.135    0.135
modelb1.status_bin <- 'status_bin ~ SESscore + Zgcse'
modelb1.status_binfit <- sem(modelb1.status_bin, data = df, ordered = c("status_bin"), missing = "listwise")
summary(modelb1.status_binfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 4 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         3
## 
##                                                   Used       Total
##   Number of observations                          3698        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   status_bin ~                                                          
##     SESscore         -0.065    0.034   -1.893    0.058   -0.132    0.002
##     Zgcse             0.011    0.033    0.320    0.749   -0.054    0.076
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .status_bin        0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     status_bin|t1    -1.268    0.029  -44.377    0.000   -1.324   -1.212
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .status_bin        1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     status_bin        1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     status_bin        0.003
standardizedsolution(modelb1.status_binfit)
##           lhs  op        rhs est.std    se       z pvalue ci.lower ci.upper
## 1  status_bin   ~   SESscore  -0.060 0.032  -1.898  0.058   -0.123    0.002
## 2  status_bin   ~      Zgcse   0.010 0.031   0.320  0.749   -0.051    0.071
## 3  status_bin   |         t1  -1.266 0.028 -44.459  0.000   -1.322   -1.210
## 4  status_bin  ~~ status_bin   0.997 0.003 321.026  0.000    0.991    1.003
## 5    SESscore  ~~   SESscore   1.000 0.000      NA     NA    1.000    1.000
## 6    SESscore  ~~      Zgcse   0.467 0.000      NA     NA    0.467    0.467
## 7       Zgcse  ~~      Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 8  status_bin ~*~ status_bin   1.000 0.000      NA     NA    1.000    1.000
## 9  status_bin  ~1              0.000 0.000      NA     NA    0.000    0.000
## 10   SESscore  ~1              0.059 0.000      NA     NA    0.059    0.059
## 11      Zgcse  ~1              0.216 0.000      NA     NA    0.216    0.216
modelb2.status_bin <- 'status_bin ~ SESscore + Zgcse + SES.gcse'
modelb2.status_binfit <- sem(modelb2.status_bin, data = df, ordered = c("status_bin"), missing = "listwise")
summary(modelb2.status_binfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 9 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         4
## 
##                                                   Used       Total
##   Number of observations                          3698        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   status_bin ~                                                          
##     SESscore         -0.053    0.034   -1.547    0.122   -0.121    0.014
##     Zgcse             0.009    0.033    0.261    0.794   -0.056    0.074
##     SES.gcse         -0.062    0.030   -2.079    0.038   -0.120   -0.004
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .status_bin        0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     status_bin|t1    -1.296    0.032  -40.572    0.000   -1.358   -1.233
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .status_bin        1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     status_bin        1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     status_bin        0.006
standardizedsolution(modelb2.status_binfit)
##           lhs  op        rhs est.std    se       z pvalue ci.lower ci.upper
## 1  status_bin   ~   SESscore  -0.050 0.032  -1.550  0.121   -0.112    0.013
## 2  status_bin   ~      Zgcse   0.008 0.031   0.261  0.794   -0.053    0.069
## 3  status_bin   ~   SES.gcse  -0.056 0.027  -2.086  0.037   -0.109   -0.003
## 4  status_bin   |         t1  -1.292 0.031 -41.716  0.000   -1.352   -1.231
## 5  status_bin  ~~ status_bin   0.994 0.004 229.405  0.000    0.985    1.002
## 6    SESscore  ~~   SESscore   1.000 0.000      NA     NA    1.000    1.000
## 7    SESscore  ~~      Zgcse   0.467 0.000      NA     NA    0.467    0.467
## 8    SESscore  ~~   SES.gcse   0.175 0.000      NA     NA    0.175    0.175
## 9       Zgcse  ~~      Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 10      Zgcse  ~~   SES.gcse   0.037 0.000      NA     NA    0.037    0.037
## 11   SES.gcse  ~~   SES.gcse   1.000 0.000      NA     NA    1.000    1.000
## 12 status_bin ~*~ status_bin   1.000 0.000      NA     NA    1.000    1.000
## 13 status_bin  ~1              0.000 0.000      NA     NA    0.000    0.000
## 14   SESscore  ~1              0.059 0.000      NA     NA    0.059    0.059
## 15      Zgcse  ~1              0.216 0.000      NA     NA    0.216    0.216
## 16   SES.gcse  ~1              0.463 0.000      NA     NA    0.463    0.463
#get change in R2 for models with vs. w/0 moderation (modela1 vs. a2 and b1 vs b2) 
(PE.modela1.status_bin <- parameterEstimates(modela1.status_binfit, rsquare = TRUE)) 
##           lhs  op        rhs    est    se       z pvalue ci.lower ci.upper
## 1  status_bin   ~       sex1 -0.028 0.057  -0.490  0.624   -0.139    0.083
## 2  status_bin   ~      Zgcse -0.016 0.028  -0.595  0.552   -0.071    0.038
## 3  status_bin   |         t1 -1.277 0.036 -35.627  0.000   -1.347   -1.206
## 4  status_bin  ~~ status_bin  1.000 0.000      NA     NA    1.000    1.000
## 5        sex1  ~~       sex1  0.237 0.000      NA     NA    0.237    0.237
## 6        sex1  ~~      Zgcse  0.006 0.000      NA     NA    0.006    0.006
## 7       Zgcse  ~~      Zgcse  0.893 0.000      NA     NA    0.893    0.893
## 8  status_bin ~*~ status_bin  1.000 0.000      NA     NA    1.000    1.000
## 9  status_bin  ~1             0.000 0.000      NA     NA    0.000    0.000
## 10       sex1  ~1             0.384 0.000      NA     NA    0.384    0.384
## 11      Zgcse  ~1             0.198 0.000      NA     NA    0.198    0.198
## 12 status_bin  r2 status_bin  0.000    NA      NA     NA       NA       NA
PE.modela1.status_bin$est[PE.modela1.status_bin$op == "r2"]
## [1] 0.0004300602
(PE.modela2.status_bin <- parameterEstimates(modela2.status_binfit, rsquare = TRUE)) 
##           lhs  op        rhs    est    se       z pvalue ci.lower ci.upper
## 1  status_bin   ~       sex1 -0.023 0.058  -0.401  0.688   -0.137    0.091
## 2  status_bin   ~      Zgcse -0.008 0.035  -0.232  0.816   -0.078    0.061
## 3  status_bin   ~   sex.gcse -0.021 0.057  -0.363  0.716   -0.131    0.090
## 4  status_bin   |         t1 -1.275 0.036 -35.306  0.000   -1.346   -1.204
## 5  status_bin  ~~ status_bin  1.000 0.000      NA     NA    1.000    1.000
## 6        sex1  ~~       sex1  0.237 0.000      NA     NA    0.237    0.237
## 7        sex1  ~~      Zgcse  0.006 0.000      NA     NA    0.006    0.006
## 8        sex1  ~~   sex.gcse  0.050 0.000      NA     NA    0.050    0.050
## 9       Zgcse  ~~      Zgcse  0.893 0.000      NA     NA    0.893    0.893
## 10      Zgcse  ~~   sex.gcse  0.357 0.000      NA     NA    0.357    0.357
## 11   sex.gcse  ~~   sex.gcse  0.366 0.000      NA     NA    0.366    0.366
## 12 status_bin ~*~ status_bin  1.000 0.000      NA     NA    1.000    1.000
## 13 status_bin  ~1             0.000 0.000      NA     NA    0.000    0.000
## 14       sex1  ~1             0.384 0.000      NA     NA    0.384    0.384
## 15      Zgcse  ~1             0.198 0.000      NA     NA    0.198    0.198
## 16   sex.gcse  ~1             0.082 0.000      NA     NA    0.082    0.082
## 17 status_bin  r2 status_bin  0.001    NA      NA     NA       NA       NA
PE.modela2.status_bin$est[PE.modela2.status_bin$op == "r2"]
## [1] 0.0005144954
(PE.modelb1.status_bin <- parameterEstimates(modelb1.status_binfit, rsquare = TRUE)) 
##           lhs  op        rhs    est    se       z pvalue ci.lower ci.upper
## 1  status_bin   ~   SESscore -0.065 0.034  -1.893  0.058   -0.132    0.002
## 2  status_bin   ~      Zgcse  0.011 0.033   0.320  0.749   -0.054    0.076
## 3  status_bin   |         t1 -1.268 0.029 -44.377  0.000   -1.324   -1.212
## 4  status_bin  ~~ status_bin  1.000 0.000      NA     NA    1.000    1.000
## 5    SESscore  ~~   SESscore  0.874 0.000      NA     NA    0.874    0.874
## 6    SESscore  ~~      Zgcse  0.411 0.000      NA     NA    0.411    0.411
## 7       Zgcse  ~~      Zgcse  0.888 0.000      NA     NA    0.888    0.888
## 8  status_bin ~*~ status_bin  1.000 0.000      NA     NA    1.000    1.000
## 9  status_bin  ~1             0.000 0.000      NA     NA    0.000    0.000
## 10   SESscore  ~1             0.055 0.000      NA     NA    0.055    0.055
## 11      Zgcse  ~1             0.203 0.000      NA     NA    0.203    0.203
## 12 status_bin  r2 status_bin  0.003    NA      NA     NA       NA       NA
PE.modelb1.status_bin$est[PE.modelb1.status_bin$op == "r2"]
## [1] 0.003179829
(PE.modelb2.status_bin <- parameterEstimates(modelb2.status_binfit, rsquare = TRUE)) 
##           lhs  op        rhs    est    se       z pvalue ci.lower ci.upper
## 1  status_bin   ~   SESscore -0.053 0.034  -1.547  0.122   -0.121    0.014
## 2  status_bin   ~      Zgcse  0.009 0.033   0.261  0.794   -0.056    0.074
## 3  status_bin   ~   SES.gcse -0.062 0.030  -2.079  0.038   -0.120   -0.004
## 4  status_bin   |         t1 -1.296 0.032 -40.572  0.000   -1.358   -1.233
## 5  status_bin  ~~ status_bin  1.000 0.000      NA     NA    1.000    1.000
## 6    SESscore  ~~   SESscore  0.874 0.000      NA     NA    0.874    0.874
## 7    SESscore  ~~      Zgcse  0.411 0.000      NA     NA    0.411    0.411
## 8    SESscore  ~~   SES.gcse  0.149 0.000      NA     NA    0.149    0.149
## 9       Zgcse  ~~      Zgcse  0.888 0.000      NA     NA    0.888    0.888
## 10      Zgcse  ~~   SES.gcse  0.032 0.000      NA     NA    0.032    0.032
## 11   SES.gcse  ~~   SES.gcse  0.833 0.000      NA     NA    0.833    0.833
## 12 status_bin ~*~ status_bin  1.000 0.000      NA     NA    1.000    1.000
## 13 status_bin  ~1             0.000 0.000      NA     NA    0.000    0.000
## 14   SESscore  ~1             0.055 0.000      NA     NA    0.055    0.055
## 15      Zgcse  ~1             0.203 0.000      NA     NA    0.203    0.203
## 16   SES.gcse  ~1             0.422 0.000      NA     NA    0.422    0.422
## 17 status_bin  r2 status_bin  0.006    NA      NA     NA       NA       NA
PE.modelb2.status_bin$est[PE.modelb2.status_bin$op == "r2"]
## [1] 0.006225163
r2diffa.status_bin <- (PE.modela2.status_bin$est[PE.modela2.status_bin$op == "r2"] - PE.modela1.status_bin$est[PE.modela1.status_bin$op == "r2"])
print(r2diffa.status_bin)    #difference modela1 vs a2, incremental explained variance by sexxGCSE
## [1] 8.443518e-05
r2diffb.status_bin <- (PE.modelb2.status_bin$est[PE.modelb2.status_bin$op == "r2"] - PE.modelb1.status_bin$est[PE.modelb1.status_bin$op == "r2"])
print(r2diffb.status_bin)    #difference modelb1 vs b2, incremental explained variance by SESxGCSE
## [1] 0.003045334

“Multinomial”/logistic regression with moderation for each category of employment status (dummy variables)

#create interaction term also in df-dummy dataset that contains the dummy variables for employment status
df_dummy$sex.gcse <- df_dummy$sex1*df$Zgcse
df_dummy$SES.gcse <- df_dummy$SESscore*df$Zgcse

##employment status: working vs. unemployed
modela1.st_working <- 'st_working ~ sex1 + Zgcse'
modela1.st_workingfit <- sem(modela1.st_working, data = df_dummy, ordered = c("st_working"), missing = "listwise")
summary(modela1.st_workingfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 8 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         3
## 
##                                                   Used       Total
##   Number of observations                          3743        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_working ~                                                          
##     sex1             -0.131    0.043   -3.058    0.002   -0.215   -0.047
##     Zgcse            -0.356    0.021  -16.717    0.000   -0.398   -0.315
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_working        0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_working|t1    -0.158    0.027   -5.849    0.000   -0.211   -0.105
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_working        1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_working        1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_working        0.106
standardizedsolution(modela1.st_workingfit)
##           lhs  op        rhs est.std    se       z pvalue ci.lower ci.upper
## 1  st_working   ~       sex1  -0.060 0.020  -3.069  0.002   -0.099   -0.022
## 2  st_working   ~      Zgcse  -0.318 0.017 -18.600  0.000   -0.352   -0.285
## 3  st_working   |         t1  -0.149 0.025  -5.900  0.000   -0.199   -0.100
## 4  st_working  ~~ st_working   0.894 0.011  80.605  0.000    0.873    0.916
## 5        sex1  ~~       sex1   1.000 0.000      NA     NA    1.000    1.000
## 6        sex1  ~~      Zgcse   0.013 0.000      NA     NA    0.013    0.013
## 7       Zgcse  ~~      Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 8  st_working ~*~ st_working   1.000 0.000      NA     NA    1.000    1.000
## 9  st_working  ~1              0.000 0.000      NA     NA    0.000    0.000
## 10       sex1  ~1              0.789 0.000      NA     NA    0.789    0.789
## 11      Zgcse  ~1              0.209 0.000      NA     NA    0.209    0.209
modela2.st_working <- 'st_working ~ sex1 + Zgcse + sex.gcse'
modela2.st_workingfit <- sem(modela2.st_working, data = df_dummy, ordered = c("st_working"), missing = "listwise")
summary(modela2.st_workingfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 11 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         4
## 
##                                                   Used       Total
##   Number of observations                          3743        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_working ~                                                          
##     sex1             -0.143    0.044   -3.270    0.001   -0.229   -0.057
##     Zgcse            -0.378    0.027  -13.770    0.000   -0.432   -0.324
##     sex.gcse          0.054    0.044    1.249    0.212   -0.031    0.140
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_working        0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_working|t1    -0.163    0.027   -6.001    0.000   -0.216   -0.110
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_working        1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_working        1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_working        0.106
standardizedsolution(modela2.st_workingfit)
##           lhs  op        rhs est.std    se       z pvalue ci.lower ci.upper
## 1  st_working   ~       sex1  -0.066 0.020  -3.283  0.001   -0.105   -0.027
## 2  st_working   ~      Zgcse  -0.338 0.023 -14.761  0.000   -0.383   -0.293
## 3  st_working   ~   sex.gcse   0.031 0.025   1.249  0.212   -0.018    0.080
## 4  st_working   |         t1  -0.154 0.025  -6.056  0.000   -0.204   -0.104
## 5  st_working  ~~ st_working   0.894 0.011  80.435  0.000    0.872    0.916
## 6        sex1  ~~       sex1   1.000 0.000      NA     NA    1.000    1.000
## 7        sex1  ~~      Zgcse   0.013 0.000      NA     NA    0.013    0.013
## 8        sex1  ~~   sex.gcse   0.171 0.000      NA     NA    0.171    0.171
## 9       Zgcse  ~~      Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 10      Zgcse  ~~   sex.gcse   0.624 0.000      NA     NA    0.624    0.624
## 11   sex.gcse  ~~   sex.gcse   1.000 0.000      NA     NA    1.000    1.000
## 12 st_working ~*~ st_working   1.000 0.000      NA     NA    1.000    1.000
## 13 st_working  ~1              0.000 0.000      NA     NA    0.000    0.000
## 14       sex1  ~1              0.789 0.000      NA     NA    0.789    0.789
## 15      Zgcse  ~1              0.209 0.000      NA     NA    0.209    0.209
## 16   sex.gcse  ~1              0.135 0.000      NA     NA    0.135    0.135
modelb1.st_working <- 'st_working ~ SESscore + Zgcse'
modelb1.st_workingfit <- sem(modelb1.st_working, data = df_dummy, ordered = c("st_working"), missing = "listwise")
summary(modelb1.st_workingfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 5 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         3
## 
##                                                   Used       Total
##   Number of observations                          3698        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_working ~                                                          
##     SESscore         -0.183    0.025   -7.204    0.000   -0.233   -0.133
##     Zgcse            -0.277    0.025  -11.255    0.000   -0.325   -0.228
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_working        0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_working|t1    -0.105    0.022   -4.859    0.000   -0.147   -0.063
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_working        1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_working        1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_working        0.122
standardizedsolution(modelb1.st_workingfit)
##           lhs  op        rhs est.std    se       z pvalue ci.lower ci.upper
## 1  st_working   ~   SESscore  -0.160 0.022  -7.353      0   -0.203   -0.118
## 2  st_working   ~      Zgcse  -0.244 0.021 -11.782      0   -0.285   -0.204
## 3  st_working   |         t1  -0.098 0.020  -4.882      0   -0.138   -0.059
## 4  st_working  ~~ st_working   0.878 0.012  73.184      0    0.855    0.902
## 5    SESscore  ~~   SESscore   1.000 0.000      NA     NA    1.000    1.000
## 6    SESscore  ~~      Zgcse   0.467 0.000      NA     NA    0.467    0.467
## 7       Zgcse  ~~      Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 8  st_working ~*~ st_working   1.000 0.000      NA     NA    1.000    1.000
## 9  st_working  ~1              0.000 0.000      NA     NA    0.000    0.000
## 10   SESscore  ~1              0.059 0.000      NA     NA    0.059    0.059
## 11      Zgcse  ~1              0.216 0.000      NA     NA    0.216    0.216
modelb2.st_working <- 'st_working ~ SESscore + Zgcse + SES.gcse'
modelb2.st_workingfit <- sem(modelb2.st_working, data = df_dummy, ordered = c("st_working"), missing = "listwise")
summary(modelb2.st_workingfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 7 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         4
## 
##                                                   Used       Total
##   Number of observations                          3698        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_working ~                                                          
##     SESscore         -0.176    0.026   -6.860    0.000   -0.226   -0.126
##     Zgcse            -0.278    0.025  -11.203    0.000   -0.326   -0.229
##     SES.gcse         -0.034    0.023   -1.497    0.134   -0.078    0.010
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_working        0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_working|t1    -0.118    0.024   -4.978    0.000   -0.164   -0.071
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_working        1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_working        1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_working        0.122
standardizedsolution(modelb2.st_workingfit)
##           lhs  op        rhs est.std    se       z pvalue ci.lower ci.upper
## 1  st_working   ~   SESscore  -0.154 0.022  -6.986  0.000   -0.198   -0.111
## 2  st_working   ~      Zgcse  -0.245 0.021 -11.742  0.000   -0.286   -0.204
## 3  st_working   ~   SES.gcse  -0.029 0.019  -1.499  0.134   -0.067    0.009
## 4  st_working   |         t1  -0.110 0.022  -5.011  0.000   -0.153   -0.067
## 5  st_working  ~~ st_working   0.878 0.012  72.102  0.000    0.854    0.902
## 6    SESscore  ~~   SESscore   1.000 0.000      NA     NA    1.000    1.000
## 7    SESscore  ~~      Zgcse   0.467 0.000      NA     NA    0.467    0.467
## 8    SESscore  ~~   SES.gcse   0.175 0.000      NA     NA    0.175    0.175
## 9       Zgcse  ~~      Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 10      Zgcse  ~~   SES.gcse   0.037 0.000      NA     NA    0.037    0.037
## 11   SES.gcse  ~~   SES.gcse   1.000 0.000      NA     NA    1.000    1.000
## 12 st_working ~*~ st_working   1.000 0.000      NA     NA    1.000    1.000
## 13 st_working  ~1              0.000 0.000      NA     NA    0.000    0.000
## 14   SESscore  ~1              0.059 0.000      NA     NA    0.059    0.059
## 15      Zgcse  ~1              0.216 0.000      NA     NA    0.216    0.216
## 16   SES.gcse  ~1              0.463 0.000      NA     NA    0.463    0.463
#get change in R2 for models with vs. w/0 moderation (modela1 vs. a2 and b1 vs b2) 
(PE.modela1.st_working <- parameterEstimates(modela1.st_workingfit, rsquare = TRUE)) 
##           lhs  op        rhs    est    se       z pvalue ci.lower ci.upper
## 1  st_working   ~       sex1 -0.131 0.043  -3.058  0.002   -0.215   -0.047
## 2  st_working   ~      Zgcse -0.356 0.021 -16.717  0.000   -0.398   -0.315
## 3  st_working   |         t1 -0.158 0.027  -5.849  0.000   -0.211   -0.105
## 4  st_working  ~~ st_working  1.000 0.000      NA     NA    1.000    1.000
## 5        sex1  ~~       sex1  0.237 0.000      NA     NA    0.237    0.237
## 6        sex1  ~~      Zgcse  0.006 0.000      NA     NA    0.006    0.006
## 7       Zgcse  ~~      Zgcse  0.893 0.000      NA     NA    0.893    0.893
## 8  st_working ~*~ st_working  1.000 0.000      NA     NA    1.000    1.000
## 9  st_working  ~1             0.000 0.000      NA     NA    0.000    0.000
## 10       sex1  ~1             0.384 0.000      NA     NA    0.384    0.384
## 11      Zgcse  ~1             0.198 0.000      NA     NA    0.198    0.198
## 12 st_working  r2 st_working  0.106    NA      NA     NA       NA       NA
PE.modela1.st_working$est[PE.modela1.st_working$op == "r2"]
## [1] 0.1055824
(PE.modela2.st_working <- parameterEstimates(modela2.st_workingfit, rsquare = TRUE)) 
##           lhs  op        rhs    est    se       z pvalue ci.lower ci.upper
## 1  st_working   ~       sex1 -0.143 0.044  -3.270  0.001   -0.229   -0.057
## 2  st_working   ~      Zgcse -0.378 0.027 -13.770  0.000   -0.432   -0.324
## 3  st_working   ~   sex.gcse  0.054 0.044   1.249  0.212   -0.031    0.140
## 4  st_working   |         t1 -0.163 0.027  -6.001  0.000   -0.216   -0.110
## 5  st_working  ~~ st_working  1.000 0.000      NA     NA    1.000    1.000
## 6        sex1  ~~       sex1  0.237 0.000      NA     NA    0.237    0.237
## 7        sex1  ~~      Zgcse  0.006 0.000      NA     NA    0.006    0.006
## 8        sex1  ~~   sex.gcse  0.050 0.000      NA     NA    0.050    0.050
## 9       Zgcse  ~~      Zgcse  0.893 0.000      NA     NA    0.893    0.893
## 10      Zgcse  ~~   sex.gcse  0.357 0.000      NA     NA    0.357    0.357
## 11   sex.gcse  ~~   sex.gcse  0.366 0.000      NA     NA    0.366    0.366
## 12 st_working ~*~ st_working  1.000 0.000      NA     NA    1.000    1.000
## 13 st_working  ~1             0.000 0.000      NA     NA    0.000    0.000
## 14       sex1  ~1             0.384 0.000      NA     NA    0.384    0.384
## 15      Zgcse  ~1             0.198 0.000      NA     NA    0.198    0.198
## 16   sex.gcse  ~1             0.082 0.000      NA     NA    0.082    0.082
## 17 st_working  r2 st_working  0.106    NA      NA     NA       NA       NA
PE.modela2.st_working$est[PE.modela2.st_working$op == "r2"]
## [1] 0.1062769
(PE.modelb1.st_working <- parameterEstimates(modelb1.st_workingfit, rsquare = TRUE)) 
##           lhs  op        rhs    est    se       z pvalue ci.lower ci.upper
## 1  st_working   ~   SESscore -0.183 0.025  -7.204      0   -0.233   -0.133
## 2  st_working   ~      Zgcse -0.277 0.025 -11.255      0   -0.325   -0.228
## 3  st_working   |         t1 -0.105 0.022  -4.859      0   -0.147   -0.063
## 4  st_working  ~~ st_working  1.000 0.000      NA     NA    1.000    1.000
## 5    SESscore  ~~   SESscore  0.874 0.000      NA     NA    0.874    0.874
## 6    SESscore  ~~      Zgcse  0.411 0.000      NA     NA    0.411    0.411
## 7       Zgcse  ~~      Zgcse  0.888 0.000      NA     NA    0.888    0.888
## 8  st_working ~*~ st_working  1.000 0.000      NA     NA    1.000    1.000
## 9  st_working  ~1             0.000 0.000      NA     NA    0.000    0.000
## 10   SESscore  ~1             0.055 0.000      NA     NA    0.055    0.055
## 11      Zgcse  ~1             0.203 0.000      NA     NA    0.203    0.203
## 12 st_working  r2 st_working  0.122    NA      NA     NA       NA       NA
PE.modelb1.st_working$est[PE.modelb1.st_working$op == "r2"]
## [1] 0.1219176
(PE.modelb2.st_working <- parameterEstimates(modelb2.st_workingfit, rsquare = TRUE)) 
##           lhs  op        rhs    est    se       z pvalue ci.lower ci.upper
## 1  st_working   ~   SESscore -0.176 0.026  -6.860  0.000   -0.226   -0.126
## 2  st_working   ~      Zgcse -0.278 0.025 -11.203  0.000   -0.326   -0.229
## 3  st_working   ~   SES.gcse -0.034 0.023  -1.497  0.134   -0.078    0.010
## 4  st_working   |         t1 -0.118 0.024  -4.978  0.000   -0.164   -0.071
## 5  st_working  ~~ st_working  1.000 0.000      NA     NA    1.000    1.000
## 6    SESscore  ~~   SESscore  0.874 0.000      NA     NA    0.874    0.874
## 7    SESscore  ~~      Zgcse  0.411 0.000      NA     NA    0.411    0.411
## 8    SESscore  ~~   SES.gcse  0.149 0.000      NA     NA    0.149    0.149
## 9       Zgcse  ~~      Zgcse  0.888 0.000      NA     NA    0.888    0.888
## 10      Zgcse  ~~   SES.gcse  0.032 0.000      NA     NA    0.032    0.032
## 11   SES.gcse  ~~   SES.gcse  0.833 0.000      NA     NA    0.833    0.833
## 12 st_working ~*~ st_working  1.000 0.000      NA     NA    1.000    1.000
## 13 st_working  ~1             0.000 0.000      NA     NA    0.000    0.000
## 14   SESscore  ~1             0.055 0.000      NA     NA    0.055    0.055
## 15      Zgcse  ~1             0.203 0.000      NA     NA    0.203    0.203
## 16   SES.gcse  ~1             0.422 0.000      NA     NA    0.422    0.422
## 17 st_working  r2 st_working  0.122    NA      NA     NA       NA       NA
PE.modelb2.st_working$est[PE.modelb2.st_working$op == "r2"]
## [1] 0.1221907
r2diffa.st_working <- (PE.modela2.st_working$est[PE.modela2.st_working$op == "r2"] - PE.modela1.st_working$est[PE.modela1.st_working$op == "r2"])
print(r2diffa.st_working)    #difference modela1 vs a2, incremental explained variance by sexxGCSE
## [1] 0.000694489
r2diffb.st_working <- (PE.modelb2.st_working$est[PE.modelb2.st_working$op == "r2"] - PE.modelb1.st_working$est[PE.modelb1.st_working$op == "r2"])
print(r2diffb.st_working)    #difference modelb1 vs b2, incremental explained variance by SESxGCSE
## [1] 0.0002730553
##employment status: studying/apprenticeship vs. unemployed
modela1.st_studying <- 'st_studying ~ sex1 + Zgcse'
modela1.st_studyingfit <- sem(modela1.st_studying, data = df_dummy, ordered = c("st_studying"), missing = "listwise")
summary(modela1.st_studyingfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 7 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         3
## 
##                                                   Used       Total
##   Number of observations                          3743        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_studying ~                                                         
##     sex1              0.124    0.044    2.851    0.004    0.039    0.210
##     Zgcse             0.376    0.023   16.472    0.000    0.331    0.420
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_studying       0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_studying|t1    0.441    0.028   15.646    0.000    0.385    0.496
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_studying       1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_studying       1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_studying       0.115
standardizedsolution(modela1.st_studyingfit)
##            lhs  op         rhs est.std    se      z pvalue ci.lower ci.upper
## 1  st_studying   ~        sex1   0.057 0.020  2.861  0.004    0.018    0.096
## 2  st_studying   ~       Zgcse   0.334 0.018 18.542  0.000    0.299    0.369
## 3  st_studying   |          t1   0.414 0.026 16.130  0.000    0.364    0.465
## 4  st_studying  ~~ st_studying   0.885 0.012 72.442  0.000    0.861    0.909
## 5         sex1  ~~        sex1   1.000 0.000     NA     NA    1.000    1.000
## 6         sex1  ~~       Zgcse   0.013 0.000     NA     NA    0.013    0.013
## 7        Zgcse  ~~       Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 8  st_studying ~*~ st_studying   1.000 0.000     NA     NA    1.000    1.000
## 9  st_studying  ~1               0.000 0.000     NA     NA    0.000    0.000
## 10        sex1  ~1               0.789 0.000     NA     NA    0.789    0.789
## 11       Zgcse  ~1               0.209 0.000     NA     NA    0.209    0.209
modela2.st_studying <- 'st_studying ~ sex1 + Zgcse + sex.gcse'
modela2.st_studyingfit <- sem(modela2.st_studying, data = df_dummy, ordered = c("st_studying"), missing = "listwise")
summary(modela2.st_studyingfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 12 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         4
## 
##                                                   Used       Total
##   Number of observations                          3743        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_studying ~                                                         
##     sex1              0.148    0.045    3.256    0.001    0.059    0.237
##     Zgcse             0.410    0.029   13.901    0.000    0.352    0.468
##     sex.gcse         -0.083    0.047   -1.793    0.073   -0.175    0.008
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_studying       0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_studying|t1    0.450    0.028   15.809    0.000    0.395    0.506
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_studying       1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_studying       1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_studying       0.117
standardizedsolution(modela2.st_studyingfit)
##            lhs  op         rhs est.std    se      z pvalue ci.lower ci.upper
## 1  st_studying   ~        sex1   0.068 0.021  3.271  0.001    0.027    0.108
## 2  st_studying   ~       Zgcse   0.364 0.024 15.097  0.000    0.317    0.411
## 3  st_studying   ~    sex.gcse  -0.047 0.026 -1.796  0.073   -0.099    0.004
## 4  st_studying   |          t1   0.423 0.026 16.331  0.000    0.372    0.474
## 5  st_studying  ~~ st_studying   0.883 0.012 71.789  0.000    0.859    0.907
## 6         sex1  ~~        sex1   1.000 0.000     NA     NA    1.000    1.000
## 7         sex1  ~~       Zgcse   0.013 0.000     NA     NA    0.013    0.013
## 8         sex1  ~~    sex.gcse   0.171 0.000     NA     NA    0.171    0.171
## 9        Zgcse  ~~       Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 10       Zgcse  ~~    sex.gcse   0.624 0.000     NA     NA    0.624    0.624
## 11    sex.gcse  ~~    sex.gcse   1.000 0.000     NA     NA    1.000    1.000
## 12 st_studying ~*~ st_studying   1.000 0.000     NA     NA    1.000    1.000
## 13 st_studying  ~1               0.000 0.000     NA     NA    0.000    0.000
## 14        sex1  ~1               0.789 0.000     NA     NA    0.789    0.789
## 15       Zgcse  ~1               0.209 0.000     NA     NA    0.209    0.209
## 16    sex.gcse  ~1               0.135 0.000     NA     NA    0.135    0.135
modelb1.st_studying <- 'st_studying ~ SESscore + Zgcse'
modelb1.st_studyingfit <- sem(modelb1.st_studying, data = df_dummy, ordered = c("st_studying"), missing = "listwise")
summary(modelb1.st_studyingfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 4 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         3
## 
##                                                   Used       Total
##   Number of observations                          3698        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_studying ~                                                         
##     SESscore          0.159    0.026    6.216    0.000    0.109    0.209
##     Zgcse             0.303    0.026   11.834    0.000    0.253    0.353
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_studying       0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_studying|t1    0.391    0.022   17.417    0.000    0.347    0.435
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_studying       1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_studying       1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_studying       0.125
standardizedsolution(modelb1.st_studyingfit)
##            lhs  op         rhs est.std    se      z pvalue ci.lower ci.upper
## 1  st_studying   ~    SESscore   0.139 0.022  6.315      0    0.096    0.182
## 2  st_studying   ~       Zgcse   0.267 0.021 12.540      0    0.225    0.309
## 3  st_studying   |          t1   0.366 0.020 17.885      0    0.326    0.406
## 4  st_studying  ~~ st_studying   0.875 0.013 68.878      0    0.850    0.899
## 5     SESscore  ~~    SESscore   1.000 0.000     NA     NA    1.000    1.000
## 6     SESscore  ~~       Zgcse   0.467 0.000     NA     NA    0.467    0.467
## 7        Zgcse  ~~       Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 8  st_studying ~*~ st_studying   1.000 0.000     NA     NA    1.000    1.000
## 9  st_studying  ~1               0.000 0.000     NA     NA    0.000    0.000
## 10    SESscore  ~1               0.059 0.000     NA     NA    0.059    0.059
## 11       Zgcse  ~1               0.216 0.000     NA     NA    0.216    0.216
modelb2.st_studying <- 'st_studying ~ SESscore + Zgcse + SES.gcse'
modelb2.st_studyingfit <- sem(modelb2.st_studying, data = df_dummy, ordered = c("st_studying"), missing = "listwise")
summary(modelb2.st_studyingfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 7 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         4
## 
##                                                   Used       Total
##   Number of observations                          3698        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_studying ~                                                         
##     SESscore          0.166    0.026    6.307    0.000    0.114    0.218
##     Zgcse             0.304    0.026   11.878    0.000    0.254    0.354
##     SES.gcse         -0.026    0.024   -1.094    0.274   -0.072    0.020
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_studying       0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_studying|t1    0.382    0.024   15.661    0.000    0.334    0.430
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_studying       1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_studying       1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_studying       0.128
standardizedsolution(modelb2.st_studyingfit)
##            lhs  op         rhs est.std    se      z pvalue ci.lower ci.upper
## 1  st_studying   ~    SESscore   0.145 0.023  6.411  0.000    0.101    0.189
## 2  st_studying   ~       Zgcse   0.267 0.021 12.573  0.000    0.226    0.309
## 3  st_studying   ~    SES.gcse  -0.022 0.020 -1.095  0.274   -0.061    0.017
## 4  st_studying   |          t1   0.357 0.022 15.938  0.000    0.313    0.401
## 5  st_studying  ~~ st_studying   0.872 0.013 68.764  0.000    0.847    0.897
## 6     SESscore  ~~    SESscore   1.000 0.000     NA     NA    1.000    1.000
## 7     SESscore  ~~       Zgcse   0.467 0.000     NA     NA    0.467    0.467
## 8     SESscore  ~~    SES.gcse   0.175 0.000     NA     NA    0.175    0.175
## 9        Zgcse  ~~       Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 10       Zgcse  ~~    SES.gcse   0.037 0.000     NA     NA    0.037    0.037
## 11    SES.gcse  ~~    SES.gcse   1.000 0.000     NA     NA    1.000    1.000
## 12 st_studying ~*~ st_studying   1.000 0.000     NA     NA    1.000    1.000
## 13 st_studying  ~1               0.000 0.000     NA     NA    0.000    0.000
## 14    SESscore  ~1               0.059 0.000     NA     NA    0.059    0.059
## 15       Zgcse  ~1               0.216 0.000     NA     NA    0.216    0.216
## 16    SES.gcse  ~1               0.463 0.000     NA     NA    0.463    0.463
#get change in R2 for models with vs. w/0 moderation (modela1 vs. a2 and b1 vs b2) 
(PE.modela1.st_studying <- parameterEstimates(modela1.st_studyingfit, rsquare = TRUE)) 
##            lhs  op         rhs   est    se      z pvalue ci.lower ci.upper
## 1  st_studying   ~        sex1 0.124 0.044  2.851  0.004    0.039    0.210
## 2  st_studying   ~       Zgcse 0.376 0.023 16.472  0.000    0.331    0.420
## 3  st_studying   |          t1 0.441 0.028 15.646  0.000    0.385    0.496
## 4  st_studying  ~~ st_studying 1.000 0.000     NA     NA    1.000    1.000
## 5         sex1  ~~        sex1 0.237 0.000     NA     NA    0.237    0.237
## 6         sex1  ~~       Zgcse 0.006 0.000     NA     NA    0.006    0.006
## 7        Zgcse  ~~       Zgcse 0.893 0.000     NA     NA    0.893    0.893
## 8  st_studying ~*~ st_studying 1.000 0.000     NA     NA    1.000    1.000
## 9  st_studying  ~1             0.000 0.000     NA     NA    0.000    0.000
## 10        sex1  ~1             0.384 0.000     NA     NA    0.384    0.384
## 11       Zgcse  ~1             0.198 0.000     NA     NA    0.198    0.198
## 12 st_studying  r2 st_studying 0.115    NA     NA     NA       NA       NA
PE.modela1.st_studying$est[PE.modela1.st_studying$op == "r2"]
## [1] 0.1152685
(PE.modela2.st_studying <- parameterEstimates(modela2.st_studyingfit, rsquare = TRUE)) 
##            lhs  op         rhs    est    se      z pvalue ci.lower ci.upper
## 1  st_studying   ~        sex1  0.148 0.045  3.256  0.001    0.059    0.237
## 2  st_studying   ~       Zgcse  0.410 0.029 13.901  0.000    0.352    0.468
## 3  st_studying   ~    sex.gcse -0.083 0.047 -1.793  0.073   -0.175    0.008
## 4  st_studying   |          t1  0.450 0.028 15.809  0.000    0.395    0.506
## 5  st_studying  ~~ st_studying  1.000 0.000     NA     NA    1.000    1.000
## 6         sex1  ~~        sex1  0.237 0.000     NA     NA    0.237    0.237
## 7         sex1  ~~       Zgcse  0.006 0.000     NA     NA    0.006    0.006
## 8         sex1  ~~    sex.gcse  0.050 0.000     NA     NA    0.050    0.050
## 9        Zgcse  ~~       Zgcse  0.893 0.000     NA     NA    0.893    0.893
## 10       Zgcse  ~~    sex.gcse  0.357 0.000     NA     NA    0.357    0.357
## 11    sex.gcse  ~~    sex.gcse  0.366 0.000     NA     NA    0.366    0.366
## 12 st_studying ~*~ st_studying  1.000 0.000     NA     NA    1.000    1.000
## 13 st_studying  ~1              0.000 0.000     NA     NA    0.000    0.000
## 14        sex1  ~1              0.384 0.000     NA     NA    0.384    0.384
## 15       Zgcse  ~1              0.198 0.000     NA     NA    0.198    0.198
## 16    sex.gcse  ~1              0.082 0.000     NA     NA    0.082    0.082
## 17 st_studying  r2 st_studying  0.117    NA     NA     NA       NA       NA
PE.modela2.st_studying$est[PE.modela2.st_studying$op == "r2"]
## [1] 0.1173589
(PE.modelb1.st_studying <- parameterEstimates(modelb1.st_studyingfit, rsquare = TRUE)) 
##            lhs  op         rhs   est    se      z pvalue ci.lower ci.upper
## 1  st_studying   ~    SESscore 0.159 0.026  6.216      0    0.109    0.209
## 2  st_studying   ~       Zgcse 0.303 0.026 11.834      0    0.253    0.353
## 3  st_studying   |          t1 0.391 0.022 17.417      0    0.347    0.435
## 4  st_studying  ~~ st_studying 1.000 0.000     NA     NA    1.000    1.000
## 5     SESscore  ~~    SESscore 0.874 0.000     NA     NA    0.874    0.874
## 6     SESscore  ~~       Zgcse 0.411 0.000     NA     NA    0.411    0.411
## 7        Zgcse  ~~       Zgcse 0.888 0.000     NA     NA    0.888    0.888
## 8  st_studying ~*~ st_studying 1.000 0.000     NA     NA    1.000    1.000
## 9  st_studying  ~1             0.000 0.000     NA     NA    0.000    0.000
## 10    SESscore  ~1             0.055 0.000     NA     NA    0.055    0.055
## 11       Zgcse  ~1             0.203 0.000     NA     NA    0.203    0.203
## 12 st_studying  r2 st_studying 0.125    NA     NA     NA       NA       NA
PE.modelb1.st_studying$est[PE.modelb1.st_studying$op == "r2"]
## [1] 0.1253878
(PE.modelb2.st_studying <- parameterEstimates(modelb2.st_studyingfit, rsquare = TRUE)) 
##            lhs  op         rhs    est    se      z pvalue ci.lower ci.upper
## 1  st_studying   ~    SESscore  0.166 0.026  6.307  0.000    0.114    0.218
## 2  st_studying   ~       Zgcse  0.304 0.026 11.878  0.000    0.254    0.354
## 3  st_studying   ~    SES.gcse -0.026 0.024 -1.094  0.274   -0.072    0.020
## 4  st_studying   |          t1  0.382 0.024 15.661  0.000    0.334    0.430
## 5  st_studying  ~~ st_studying  1.000 0.000     NA     NA    1.000    1.000
## 6     SESscore  ~~    SESscore  0.874 0.000     NA     NA    0.874    0.874
## 7     SESscore  ~~       Zgcse  0.411 0.000     NA     NA    0.411    0.411
## 8     SESscore  ~~    SES.gcse  0.149 0.000     NA     NA    0.149    0.149
## 9        Zgcse  ~~       Zgcse  0.888 0.000     NA     NA    0.888    0.888
## 10       Zgcse  ~~    SES.gcse  0.032 0.000     NA     NA    0.032    0.032
## 11    SES.gcse  ~~    SES.gcse  0.833 0.000     NA     NA    0.833    0.833
## 12 st_studying ~*~ st_studying  1.000 0.000     NA     NA    1.000    1.000
## 13 st_studying  ~1              0.000 0.000     NA     NA    0.000    0.000
## 14    SESscore  ~1              0.055 0.000     NA     NA    0.055    0.055
## 15       Zgcse  ~1              0.203 0.000     NA     NA    0.203    0.203
## 16    SES.gcse  ~1              0.422 0.000     NA     NA    0.422    0.422
## 17 st_studying  r2 st_studying  0.128    NA     NA     NA       NA       NA
PE.modelb2.st_studying$est[PE.modelb2.st_studying$op == "r2"]
## [1] 0.1276366
r2diffa.st_studying <- (PE.modela2.st_studying$est[PE.modela2.st_studying$op == "r2"] - PE.modela1.st_studying$est[PE.modela1.st_studying$op == "r2"])
print(r2diffa.st_studying)    #difference modela1 vs a2, incremental explained variance by sexxGCSE
## [1] 0.002090444
r2diffb.st_studying <- (PE.modelb2.st_studying$est[PE.modelb2.st_studying$op == "r2"] - PE.modelb1.st_studying$est[PE.modelb1.st_studying$op == "r2"])
print(r2diffb.st_studying)    #difference modelb1 vs b2, incremental explained variance by SESxGCSE
## [1] 0.002248734
##employment status: full-time parent vs. unemployed
modela1.st_parent <- 'st_parent ~ sex1 + Zgcse'
modela1.st_parentfit <- sem(modela1.st_parent, data = df_dummy, ordered = c("st_parent"), missing = "listwise")
summary(modela1.st_parentfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 10 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         3
## 
##                                                   Used       Total
##   Number of observations                          3743        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_parent ~                                                           
##     sex1             -0.542    0.221   -2.453    0.014   -0.976   -0.109
##     Zgcse            -0.420    0.077   -5.450    0.000   -0.571   -0.269
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_parent         0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_parent|t1      2.497    0.100   25.066    0.000    2.302    2.692
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_parent         1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_parent         1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_parent         0.187
standardizedsolution(modela1.st_parentfit)
##          lhs  op       rhs est.std    se      z pvalue ci.lower ci.upper
## 1  st_parent   ~      sex1  -0.238 0.091 -2.623  0.009   -0.416   -0.060
## 2  st_parent   ~     Zgcse  -0.358 0.057 -6.335  0.000   -0.469   -0.247
## 3  st_parent   |        t1   2.251 0.113 19.864  0.000    2.029    2.474
## 4  st_parent  ~~ st_parent   0.813 0.058 13.934  0.000    0.699    0.927
## 5       sex1  ~~      sex1   1.000 0.000     NA     NA    1.000    1.000
## 6       sex1  ~~     Zgcse   0.013 0.000     NA     NA    0.013    0.013
## 7      Zgcse  ~~     Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 8  st_parent ~*~ st_parent   1.000 0.000     NA     NA    1.000    1.000
## 9  st_parent  ~1             0.000 0.000     NA     NA    0.000    0.000
## 10      sex1  ~1             0.789 0.000     NA     NA    0.789    0.789
## 11     Zgcse  ~1             0.209 0.000     NA     NA    0.209    0.209
modela2.st_parent <- 'st_parent ~ sex1 + Zgcse + sex.gcse'
modela2.st_parentfit <- sem(modela2.st_parent, data = df_dummy, ordered = c("st_parent"), missing = "listwise")
summary(modela2.st_parentfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 11 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         4
## 
##                                                   Used       Total
##   Number of observations                          3743        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_parent ~                                                           
##     sex1             -0.540    0.338   -1.599    0.110   -1.203    0.122
##     Zgcse            -0.421    0.081   -5.175    0.000   -0.580   -0.261
##     sex.gcse          0.002    0.257    0.009    0.993   -0.501    0.506
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_parent         0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_parent|t1      2.497    0.101   24.778    0.000    2.300    2.695
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_parent         1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_parent         1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_parent         0.186
standardizedsolution(modela2.st_parentfit)
##          lhs  op       rhs est.std    se      z pvalue ci.lower ci.upper
## 1  st_parent   ~      sex1  -0.237 0.134 -1.767  0.077   -0.500    0.026
## 2  st_parent   ~     Zgcse  -0.359 0.070 -5.090  0.000   -0.497   -0.221
## 3  st_parent   ~  sex.gcse   0.001 0.140  0.009  0.993   -0.274    0.276
## 4  st_parent   |        t1   2.253 0.180 12.503  0.000    1.899    2.606
## 5  st_parent  ~~ st_parent   0.814 0.108  7.517  0.000    0.602    1.026
## 6       sex1  ~~      sex1   1.000 0.000     NA     NA    1.000    1.000
## 7       sex1  ~~     Zgcse   0.013 0.000     NA     NA    0.013    0.013
## 8       sex1  ~~  sex.gcse   0.171 0.000     NA     NA    0.171    0.171
## 9      Zgcse  ~~     Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 10     Zgcse  ~~  sex.gcse   0.624 0.000     NA     NA    0.624    0.624
## 11  sex.gcse  ~~  sex.gcse   1.000 0.000     NA     NA    1.000    1.000
## 12 st_parent ~*~ st_parent   1.000 0.000     NA     NA    1.000    1.000
## 13 st_parent  ~1             0.000 0.000     NA     NA    0.000    0.000
## 14      sex1  ~1             0.789 0.000     NA     NA    0.789    0.789
## 15     Zgcse  ~1             0.209 0.000     NA     NA    0.209    0.209
## 16  sex.gcse  ~1             0.135 0.000     NA     NA    0.135    0.135
modelb1.st_parent <- 'st_parent ~ SESscore + Zgcse'
modelb1.st_parentfit <- sem(modelb1.st_parent, data = df_dummy, ordered = c("st_parent"), missing = "listwise")
summary(modelb1.st_parentfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 9 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         3
## 
##                                                   Used       Total
##   Number of observations                          3698        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_parent ~                                                           
##     SESscore         -0.349    0.109   -3.215    0.001   -0.563   -0.136
##     Zgcse            -0.301    0.086   -3.504    0.000   -0.469   -0.133
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_parent         0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_parent|t1      2.754    0.116   23.646    0.000    2.525    2.982
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_parent         1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_parent         1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_parent         0.215
standardizedsolution(modelb1.st_parentfit)
##          lhs  op       rhs est.std    se      z pvalue ci.lower ci.upper
## 1  st_parent   ~  SESscore  -0.289 0.083 -3.497      0   -0.452   -0.127
## 2  st_parent   ~     Zgcse  -0.251 0.069 -3.655      0   -0.386   -0.116
## 3  st_parent   |        t1   2.440 0.075 32.676      0    2.294    2.587
## 4  st_parent  ~~ st_parent   0.785 0.058 13.629      0    0.672    0.898
## 5   SESscore  ~~  SESscore   1.000 0.000     NA     NA    1.000    1.000
## 6   SESscore  ~~     Zgcse   0.467 0.000     NA     NA    0.467    0.467
## 7      Zgcse  ~~     Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 8  st_parent ~*~ st_parent   1.000 0.000     NA     NA    1.000    1.000
## 9  st_parent  ~1             0.000 0.000     NA     NA    0.000    0.000
## 10  SESscore  ~1             0.059 0.000     NA     NA    0.059    0.059
## 11     Zgcse  ~1             0.216 0.000     NA     NA    0.216    0.216
modelb2.st_parent <- 'st_parent ~ SESscore + Zgcse + SES.gcse'
modelb2.st_parentfit <- sem(modelb2.st_parent, data = df_dummy, ordered = c("st_parent"), missing = "listwise")
summary(modelb2.st_parentfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 18 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         4
## 
##                                                   Used       Total
##   Number of observations                          3698        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_parent ~                                                           
##     SESscore         -0.325    0.118   -2.745    0.006   -0.557   -0.093
##     Zgcse            -0.252    0.191   -1.317    0.188   -0.627    0.123
##     SES.gcse          0.054    0.135    0.399    0.690   -0.211    0.318
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_parent         0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_parent|t1      2.746    0.123   22.328    0.000    2.505    2.987
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_parent         1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_parent         1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_parent         0.175
standardizedsolution(modelb2.st_parentfit)
##          lhs  op       rhs est.std    se      z pvalue ci.lower ci.upper
## 1  st_parent   ~  SESscore  -0.276 0.088 -3.124  0.002   -0.449   -0.103
## 2  st_parent   ~     Zgcse  -0.215 0.150 -1.438  0.151   -0.509    0.078
## 3  st_parent   ~  SES.gcse   0.045 0.115  0.389  0.697   -0.180    0.270
## 4  st_parent   |        t1   2.494 0.150 16.624  0.000    2.200    2.788
## 5  st_parent  ~~ st_parent   0.825 0.123  6.717  0.000    0.584    1.066
## 6   SESscore  ~~  SESscore   1.000 0.000     NA     NA    1.000    1.000
## 7   SESscore  ~~     Zgcse   0.467 0.000     NA     NA    0.467    0.467
## 8   SESscore  ~~  SES.gcse   0.175 0.000     NA     NA    0.175    0.175
## 9      Zgcse  ~~     Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 10     Zgcse  ~~  SES.gcse   0.037 0.000     NA     NA    0.037    0.037
## 11  SES.gcse  ~~  SES.gcse   1.000 0.000     NA     NA    1.000    1.000
## 12 st_parent ~*~ st_parent   1.000 0.000     NA     NA    1.000    1.000
## 13 st_parent  ~1             0.000 0.000     NA     NA    0.000    0.000
## 14  SESscore  ~1             0.059 0.000     NA     NA    0.059    0.059
## 15     Zgcse  ~1             0.216 0.000     NA     NA    0.216    0.216
## 16  SES.gcse  ~1             0.463 0.000     NA     NA    0.463    0.463
#get change in R2 for models with vs. w/0 moderation (modela1 vs. a2 and b1 vs b2) 
(PE.modela1.st_parent <- parameterEstimates(modela1.st_parentfit, rsquare = TRUE)) 
##          lhs  op       rhs    est    se      z pvalue ci.lower ci.upper
## 1  st_parent   ~      sex1 -0.542 0.221 -2.453  0.014   -0.976   -0.109
## 2  st_parent   ~     Zgcse -0.420 0.077 -5.450  0.000   -0.571   -0.269
## 3  st_parent   |        t1  2.497 0.100 25.066  0.000    2.302    2.692
## 4  st_parent  ~~ st_parent  1.000 0.000     NA     NA    1.000    1.000
## 5       sex1  ~~      sex1  0.237 0.000     NA     NA    0.237    0.237
## 6       sex1  ~~     Zgcse  0.006 0.000     NA     NA    0.006    0.006
## 7      Zgcse  ~~     Zgcse  0.893 0.000     NA     NA    0.893    0.893
## 8  st_parent ~*~ st_parent  1.000 0.000     NA     NA    1.000    1.000
## 9  st_parent  ~1            0.000 0.000     NA     NA    0.000    0.000
## 10      sex1  ~1            0.384 0.000     NA     NA    0.384    0.384
## 11     Zgcse  ~1            0.198 0.000     NA     NA    0.198    0.198
## 12 st_parent  r2 st_parent  0.187    NA     NA     NA       NA       NA
PE.modela1.st_parent$est[PE.modela1.st_parent$op == "r2"]
## [1] 0.1870129
(PE.modela2.st_parent <- parameterEstimates(modela2.st_parentfit, rsquare = TRUE)) 
##          lhs  op       rhs    est    se      z pvalue ci.lower ci.upper
## 1  st_parent   ~      sex1 -0.540 0.338 -1.599  0.110   -1.203    0.122
## 2  st_parent   ~     Zgcse -0.421 0.081 -5.175  0.000   -0.580   -0.261
## 3  st_parent   ~  sex.gcse  0.002 0.257  0.009  0.993   -0.501    0.506
## 4  st_parent   |        t1  2.497 0.101 24.778  0.000    2.300    2.695
## 5  st_parent  ~~ st_parent  1.000 0.000     NA     NA    1.000    1.000
## 6       sex1  ~~      sex1  0.237 0.000     NA     NA    0.237    0.237
## 7       sex1  ~~     Zgcse  0.006 0.000     NA     NA    0.006    0.006
## 8       sex1  ~~  sex.gcse  0.050 0.000     NA     NA    0.050    0.050
## 9      Zgcse  ~~     Zgcse  0.893 0.000     NA     NA    0.893    0.893
## 10     Zgcse  ~~  sex.gcse  0.357 0.000     NA     NA    0.357    0.357
## 11  sex.gcse  ~~  sex.gcse  0.366 0.000     NA     NA    0.366    0.366
## 12 st_parent ~*~ st_parent  1.000 0.000     NA     NA    1.000    1.000
## 13 st_parent  ~1            0.000 0.000     NA     NA    0.000    0.000
## 14      sex1  ~1            0.384 0.000     NA     NA    0.384    0.384
## 15     Zgcse  ~1            0.198 0.000     NA     NA    0.198    0.198
## 16  sex.gcse  ~1            0.082 0.000     NA     NA    0.082    0.082
## 17 st_parent  r2 st_parent  0.186    NA     NA     NA       NA       NA
PE.modela2.st_parent$est[PE.modela2.st_parent$op == "r2"]
## [1] 0.1863282
(PE.modelb1.st_parent <- parameterEstimates(modelb1.st_parentfit, rsquare = TRUE)) 
##          lhs  op       rhs    est    se      z pvalue ci.lower ci.upper
## 1  st_parent   ~  SESscore -0.349 0.109 -3.215  0.001   -0.563   -0.136
## 2  st_parent   ~     Zgcse -0.301 0.086 -3.504  0.000   -0.469   -0.133
## 3  st_parent   |        t1  2.754 0.116 23.646  0.000    2.525    2.982
## 4  st_parent  ~~ st_parent  1.000 0.000     NA     NA    1.000    1.000
## 5   SESscore  ~~  SESscore  0.874 0.000     NA     NA    0.874    0.874
## 6   SESscore  ~~     Zgcse  0.411 0.000     NA     NA    0.411    0.411
## 7      Zgcse  ~~     Zgcse  0.888 0.000     NA     NA    0.888    0.888
## 8  st_parent ~*~ st_parent  1.000 0.000     NA     NA    1.000    1.000
## 9  st_parent  ~1            0.000 0.000     NA     NA    0.000    0.000
## 10  SESscore  ~1            0.055 0.000     NA     NA    0.055    0.055
## 11     Zgcse  ~1            0.203 0.000     NA     NA    0.203    0.203
## 12 st_parent  r2 st_parent  0.215    NA     NA     NA       NA       NA
PE.modelb1.st_parent$est[PE.modelb1.st_parent$op == "r2"]
## [1] 0.2147373
(PE.modelb2.st_parent <- parameterEstimates(modelb2.st_parentfit, rsquare = TRUE)) 
##          lhs  op       rhs    est    se      z pvalue ci.lower ci.upper
## 1  st_parent   ~  SESscore -0.325 0.118 -2.745  0.006   -0.557   -0.093
## 2  st_parent   ~     Zgcse -0.252 0.191 -1.317  0.188   -0.627    0.123
## 3  st_parent   ~  SES.gcse  0.054 0.135  0.399  0.690   -0.211    0.318
## 4  st_parent   |        t1  2.746 0.123 22.328  0.000    2.505    2.987
## 5  st_parent  ~~ st_parent  1.000 0.000     NA     NA    1.000    1.000
## 6   SESscore  ~~  SESscore  0.874 0.000     NA     NA    0.874    0.874
## 7   SESscore  ~~     Zgcse  0.411 0.000     NA     NA    0.411    0.411
## 8   SESscore  ~~  SES.gcse  0.149 0.000     NA     NA    0.149    0.149
## 9      Zgcse  ~~     Zgcse  0.888 0.000     NA     NA    0.888    0.888
## 10     Zgcse  ~~  SES.gcse  0.032 0.000     NA     NA    0.032    0.032
## 11  SES.gcse  ~~  SES.gcse  0.833 0.000     NA     NA    0.833    0.833
## 12 st_parent ~*~ st_parent  1.000 0.000     NA     NA    1.000    1.000
## 13 st_parent  ~1            0.000 0.000     NA     NA    0.000    0.000
## 14  SESscore  ~1            0.055 0.000     NA     NA    0.055    0.055
## 15     Zgcse  ~1            0.203 0.000     NA     NA    0.203    0.203
## 16  SES.gcse  ~1            0.422 0.000     NA     NA    0.422    0.422
## 17 st_parent  r2 st_parent  0.175    NA     NA     NA       NA       NA
PE.modelb2.st_parent$est[PE.modelb2.st_parent$op == "r2"]
## [1] 0.1750283
r2diffa.st_parent <- (PE.modela2.st_parent$est[PE.modela2.st_parent$op == "r2"] - PE.modela1.st_parent$est[PE.modela1.st_parent$op == "r2"])
print(r2diffa.st_parent)    #difference modela1 vs a2, incremental explained variance by sexxGCSE
## [1] -0.0006847078
r2diffb.st_parent <- (PE.modelb2.st_parent$est[PE.modelb2.st_parent$op == "r2"] - PE.modelb1.st_parent$est[PE.modelb1.st_parent$op == "r2"])
print(r2diffb.st_parent)    #difference modelb1 vs b2, incremental explained variance by SESxGCSE
## [1] -0.03970895
##employment status: gap year/travelling vs. unemployed
modela1.st_gapyear <- 'st_gapyear ~ sex1 + Zgcse'
modela1.st_gapyearfit <- sem(modela1.st_gapyear, data = df_dummy, ordered = c("st_gapyear"), missing = "listwise")
summary(modela1.st_gapyearfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 8 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         3
## 
##                                                   Used       Total
##   Number of observations                          3743        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_gapyear ~                                                          
##     sex1             -0.078    0.082   -0.951    0.342   -0.238    0.083
##     Zgcse             0.121    0.044    2.770    0.006    0.035    0.206
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_gapyear        0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_gapyear|t1     1.819    0.052   34.720    0.000    1.716    1.921
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_gapyear        1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_gapyear        1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_gapyear        0.014
standardizedsolution(modela1.st_gapyearfit)
##           lhs  op        rhs est.std    se       z pvalue ci.lower ci.upper
## 1  st_gapyear   ~       sex1  -0.038 0.040  -0.952  0.341   -0.115    0.040
## 2  st_gapyear   ~      Zgcse   0.113 0.040   2.805  0.005    0.034    0.193
## 3  st_gapyear   |         t1   1.806 0.051  35.244  0.000    1.705    1.906
## 4  st_gapyear  ~~ st_gapyear   0.986 0.009 106.962  0.000    0.968    1.004
## 5        sex1  ~~       sex1   1.000 0.000      NA     NA    1.000    1.000
## 6        sex1  ~~      Zgcse   0.013 0.000      NA     NA    0.013    0.013
## 7       Zgcse  ~~      Zgcse   1.000 0.000      NA     NA    1.000    1.000
## 8  st_gapyear ~*~ st_gapyear   1.000 0.000      NA     NA    1.000    1.000
## 9  st_gapyear  ~1              0.000 0.000      NA     NA    0.000    0.000
## 10       sex1  ~1              0.789 0.000      NA     NA    0.789    0.789
## 11      Zgcse  ~1              0.209 0.000      NA     NA    0.209    0.209
modela2.st_gapyear <- 'st_gapyear ~ sex1 + Zgcse + sex.gcse'
modela2.st_gapyearfit <- sem(modela2.st_gapyear, data = df_dummy, ordered = c("st_gapyear"), missing = "listwise")
summary(modela2.st_gapyearfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 17 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         4
## 
##                                                   Used       Total
##   Number of observations                          3743        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_gapyear ~                                                          
##     sex1             -0.030    0.087   -0.341    0.733   -0.199    0.140
##     Zgcse             0.176    0.057    3.109    0.002    0.065    0.288
##     sex.gcse         -0.144    0.090   -1.609    0.108   -0.320    0.031
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_gapyear        0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_gapyear|t1     1.840    0.054   34.024    0.000    1.734    1.946
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_gapyear        1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_gapyear        1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_gapyear        0.018
standardizedsolution(modela2.st_gapyearfit)
##           lhs  op        rhs est.std    se      z pvalue ci.lower ci.upper
## 1  st_gapyear   ~       sex1  -0.014 0.042 -0.341  0.733   -0.096    0.068
## 2  st_gapyear   ~      Zgcse   0.165 0.052  3.159  0.002    0.063    0.268
## 3  st_gapyear   ~   sex.gcse  -0.086 0.054 -1.616  0.106   -0.191    0.018
## 4  st_gapyear   |         t1   1.824 0.051 35.419  0.000    1.723    1.924
## 5  st_gapyear  ~~ st_gapyear   0.982 0.010 94.221  0.000    0.962    1.003
## 6        sex1  ~~       sex1   1.000 0.000     NA     NA    1.000    1.000
## 7        sex1  ~~      Zgcse   0.013 0.000     NA     NA    0.013    0.013
## 8        sex1  ~~   sex.gcse   0.171 0.000     NA     NA    0.171    0.171
## 9       Zgcse  ~~      Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 10      Zgcse  ~~   sex.gcse   0.624 0.000     NA     NA    0.624    0.624
## 11   sex.gcse  ~~   sex.gcse   1.000 0.000     NA     NA    1.000    1.000
## 12 st_gapyear ~*~ st_gapyear   1.000 0.000     NA     NA    1.000    1.000
## 13 st_gapyear  ~1              0.000 0.000     NA     NA    0.000    0.000
## 14       sex1  ~1              0.789 0.000     NA     NA    0.789    0.789
## 15      Zgcse  ~1              0.209 0.000     NA     NA    0.209    0.209
## 16   sex.gcse  ~1              0.135 0.000     NA     NA    0.135    0.135
modelb1.st_gapyear <- 'st_gapyear ~ SESscore + Zgcse'
modelb1.st_gapyearfit <- sem(modelb1.st_gapyear, data = df_dummy, ordered = c("st_gapyear"), missing = "listwise")
summary(modelb1.st_gapyearfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 6 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         3
## 
##                                                   Used       Total
##   Number of observations                          3698        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_gapyear ~                                                          
##     SESscore          0.138    0.049    2.832    0.005    0.043    0.234
##     Zgcse             0.052    0.050    1.030    0.303   -0.047    0.150
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_gapyear        0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_gapyear|t1     1.850    0.043   43.479    0.000    1.767    1.934
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_gapyear        1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_gapyear        1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_gapyear        0.024
standardizedsolution(modelb1.st_gapyearfit)
##           lhs  op        rhs est.std    se      z pvalue ci.lower ci.upper
## 1  st_gapyear   ~   SESscore   0.128 0.045  2.868  0.004    0.040    0.215
## 2  st_gapyear   ~      Zgcse   0.048 0.047  1.032  0.302   -0.043    0.140
## 3  st_gapyear   |         t1   1.828 0.040 45.965  0.000    1.750    1.906
## 4  st_gapyear  ~~ st_gapyear   0.976 0.012 80.658  0.000    0.952    0.999
## 5    SESscore  ~~   SESscore   1.000 0.000     NA     NA    1.000    1.000
## 6    SESscore  ~~      Zgcse   0.467 0.000     NA     NA    0.467    0.467
## 7       Zgcse  ~~      Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 8  st_gapyear ~*~ st_gapyear   1.000 0.000     NA     NA    1.000    1.000
## 9  st_gapyear  ~1              0.000 0.000     NA     NA    0.000    0.000
## 10   SESscore  ~1              0.059 0.000     NA     NA    0.059    0.059
## 11      Zgcse  ~1              0.216 0.000     NA     NA    0.216    0.216
modelb2.st_gapyear <- 'st_gapyear ~ SESscore + Zgcse + SES.gcse'
modelb2.st_gapyearfit <- sem(modelb2.st_gapyear, data = df_dummy, ordered = c("st_gapyear"), missing = "listwise")
summary(modelb2.st_gapyearfit, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 7 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                         4
## 
##                                                   Used       Total
##   Number of observations                          3698        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_gapyear ~                                                          
##     SESscore          0.135    0.049    2.723    0.006    0.038    0.232
##     Zgcse             0.049    0.053    0.921    0.357   -0.056    0.154
##     SES.gcse          0.015    0.053    0.284    0.776   -0.089    0.120
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_gapyear        0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_gapyear|t1     1.856    0.046   40.303    0.000    1.765    1.946
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_gapyear        1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_gapyear        1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_gapyear        0.024
standardizedsolution(modelb2.st_gapyearfit)
##           lhs  op        rhs est.std    se      z pvalue ci.lower ci.upper
## 1  st_gapyear   ~   SESscore   0.124 0.045  2.756  0.006    0.036    0.213
## 2  st_gapyear   ~      Zgcse   0.046 0.050  0.923  0.356   -0.052    0.143
## 3  st_gapyear   ~   SES.gcse   0.014 0.048  0.284  0.776   -0.081    0.108
## 4  st_gapyear   |         t1   1.834 0.044 41.498  0.000    1.747    1.920
## 5  st_gapyear  ~~ st_gapyear   0.976 0.012 80.806  0.000    0.953    1.000
## 6    SESscore  ~~   SESscore   1.000 0.000     NA     NA    1.000    1.000
## 7    SESscore  ~~      Zgcse   0.467 0.000     NA     NA    0.467    0.467
## 8    SESscore  ~~   SES.gcse   0.175 0.000     NA     NA    0.175    0.175
## 9       Zgcse  ~~      Zgcse   1.000 0.000     NA     NA    1.000    1.000
## 10      Zgcse  ~~   SES.gcse   0.037 0.000     NA     NA    0.037    0.037
## 11   SES.gcse  ~~   SES.gcse   1.000 0.000     NA     NA    1.000    1.000
## 12 st_gapyear ~*~ st_gapyear   1.000 0.000     NA     NA    1.000    1.000
## 13 st_gapyear  ~1              0.000 0.000     NA     NA    0.000    0.000
## 14   SESscore  ~1              0.059 0.000     NA     NA    0.059    0.059
## 15      Zgcse  ~1              0.216 0.000     NA     NA    0.216    0.216
## 16   SES.gcse  ~1              0.463 0.000     NA     NA    0.463    0.463
#get change in R2 for models with vs. w/0 moderation (modela1 vs. a2 and b1 vs b2) 
(PE.modela1.st_gapyear <- parameterEstimates(modela1.st_gapyearfit, rsquare = TRUE)) 
##           lhs  op        rhs    est    se      z pvalue ci.lower ci.upper
## 1  st_gapyear   ~       sex1 -0.078 0.082 -0.951  0.342   -0.238    0.083
## 2  st_gapyear   ~      Zgcse  0.121 0.044  2.770  0.006    0.035    0.206
## 3  st_gapyear   |         t1  1.819 0.052 34.720  0.000    1.716    1.921
## 4  st_gapyear  ~~ st_gapyear  1.000 0.000     NA     NA    1.000    1.000
## 5        sex1  ~~       sex1  0.237 0.000     NA     NA    0.237    0.237
## 6        sex1  ~~      Zgcse  0.006 0.000     NA     NA    0.006    0.006
## 7       Zgcse  ~~      Zgcse  0.893 0.000     NA     NA    0.893    0.893
## 8  st_gapyear ~*~ st_gapyear  1.000 0.000     NA     NA    1.000    1.000
## 9  st_gapyear  ~1             0.000 0.000     NA     NA    0.000    0.000
## 10       sex1  ~1             0.384 0.000     NA     NA    0.384    0.384
## 11      Zgcse  ~1             0.198 0.000     NA     NA    0.198    0.198
## 12 st_gapyear  r2 st_gapyear  0.014    NA     NA     NA       NA       NA
PE.modela1.st_gapyear$est[PE.modela1.st_gapyear$op == "r2"]
## [1] 0.0141686
(PE.modela2.st_gapyear <- parameterEstimates(modela2.st_gapyearfit, rsquare = TRUE)) 
##           lhs  op        rhs    est    se      z pvalue ci.lower ci.upper
## 1  st_gapyear   ~       sex1 -0.030 0.087 -0.341  0.733   -0.199    0.140
## 2  st_gapyear   ~      Zgcse  0.176 0.057  3.109  0.002    0.065    0.288
## 3  st_gapyear   ~   sex.gcse -0.144 0.090 -1.609  0.108   -0.320    0.031
## 4  st_gapyear   |         t1  1.840 0.054 34.024  0.000    1.734    1.946
## 5  st_gapyear  ~~ st_gapyear  1.000 0.000     NA     NA    1.000    1.000
## 6        sex1  ~~       sex1  0.237 0.000     NA     NA    0.237    0.237
## 7        sex1  ~~      Zgcse  0.006 0.000     NA     NA    0.006    0.006
## 8        sex1  ~~   sex.gcse  0.050 0.000     NA     NA    0.050    0.050
## 9       Zgcse  ~~      Zgcse  0.893 0.000     NA     NA    0.893    0.893
## 10      Zgcse  ~~   sex.gcse  0.357 0.000     NA     NA    0.357    0.357
## 11   sex.gcse  ~~   sex.gcse  0.366 0.000     NA     NA    0.366    0.366
## 12 st_gapyear ~*~ st_gapyear  1.000 0.000     NA     NA    1.000    1.000
## 13 st_gapyear  ~1             0.000 0.000     NA     NA    0.000    0.000
## 14       sex1  ~1             0.384 0.000     NA     NA    0.384    0.384
## 15      Zgcse  ~1             0.198 0.000     NA     NA    0.198    0.198
## 16   sex.gcse  ~1             0.082 0.000     NA     NA    0.082    0.082
## 17 st_gapyear  r2 st_gapyear  0.018    NA     NA     NA       NA       NA
PE.modela2.st_gapyear$est[PE.modela2.st_gapyear$op == "r2"]
## [1] 0.01755005
(PE.modelb1.st_gapyear <- parameterEstimates(modelb1.st_gapyearfit, rsquare = TRUE)) 
##           lhs  op        rhs   est    se      z pvalue ci.lower ci.upper
## 1  st_gapyear   ~   SESscore 0.138 0.049  2.832  0.005    0.043    0.234
## 2  st_gapyear   ~      Zgcse 0.052 0.050  1.030  0.303   -0.047    0.150
## 3  st_gapyear   |         t1 1.850 0.043 43.479  0.000    1.767    1.934
## 4  st_gapyear  ~~ st_gapyear 1.000 0.000     NA     NA    1.000    1.000
## 5    SESscore  ~~   SESscore 0.874 0.000     NA     NA    0.874    0.874
## 6    SESscore  ~~      Zgcse 0.411 0.000     NA     NA    0.411    0.411
## 7       Zgcse  ~~      Zgcse 0.888 0.000     NA     NA    0.888    0.888
## 8  st_gapyear ~*~ st_gapyear 1.000 0.000     NA     NA    1.000    1.000
## 9  st_gapyear  ~1            0.000 0.000     NA     NA    0.000    0.000
## 10   SESscore  ~1            0.055 0.000     NA     NA    0.055    0.055
## 11      Zgcse  ~1            0.203 0.000     NA     NA    0.203    0.203
## 12 st_gapyear  r2 st_gapyear 0.024    NA     NA     NA       NA       NA
PE.modelb1.st_gapyear$est[PE.modelb1.st_gapyear$op == "r2"]
## [1] 0.02442277
(PE.modelb2.st_gapyear <- parameterEstimates(modelb2.st_gapyearfit, rsquare = TRUE)) 
##           lhs  op        rhs   est    se      z pvalue ci.lower ci.upper
## 1  st_gapyear   ~   SESscore 0.135 0.049  2.723  0.006    0.038    0.232
## 2  st_gapyear   ~      Zgcse 0.049 0.053  0.921  0.357   -0.056    0.154
## 3  st_gapyear   ~   SES.gcse 0.015 0.053  0.284  0.776   -0.089    0.120
## 4  st_gapyear   |         t1 1.856 0.046 40.303  0.000    1.765    1.946
## 5  st_gapyear  ~~ st_gapyear 1.000 0.000     NA     NA    1.000    1.000
## 6    SESscore  ~~   SESscore 0.874 0.000     NA     NA    0.874    0.874
## 7    SESscore  ~~      Zgcse 0.411 0.000     NA     NA    0.411    0.411
## 8    SESscore  ~~   SES.gcse 0.149 0.000     NA     NA    0.149    0.149
## 9       Zgcse  ~~      Zgcse 0.888 0.000     NA     NA    0.888    0.888
## 10      Zgcse  ~~   SES.gcse 0.032 0.000     NA     NA    0.032    0.032
## 11   SES.gcse  ~~   SES.gcse 0.833 0.000     NA     NA    0.833    0.833
## 12 st_gapyear ~*~ st_gapyear 1.000 0.000     NA     NA    1.000    1.000
## 13 st_gapyear  ~1            0.000 0.000     NA     NA    0.000    0.000
## 14   SESscore  ~1            0.055 0.000     NA     NA    0.055    0.055
## 15      Zgcse  ~1            0.203 0.000     NA     NA    0.203    0.203
## 16   SES.gcse  ~1            0.422 0.000     NA     NA    0.422    0.422
## 17 st_gapyear  r2 st_gapyear 0.024    NA     NA     NA       NA       NA
PE.modelb2.st_gapyear$est[PE.modelb2.st_gapyear$op == "r2"]
## [1] 0.02371756
r2diffa.st_gapyear <- (PE.modela2.st_gapyear$est[PE.modela2.st_gapyear$op == "r2"] - PE.modela1.st_gapyear$est[PE.modela1.st_gapyear$op == "r2"])
print(r2diffa.st_gapyear)    #difference modela1 vs a2, incremental explained variance by sexxGCSE
## [1] 0.003381456
r2diffb.st_gapyear <- (PE.modelb2.st_gapyear$est[PE.modelb2.st_gapyear$op == "r2"] - PE.modelb1.st_gapyear$est[PE.modelb1.st_gapyear$op == "r2"])
print(r2diffb.st_gapyear)    #difference modelb1 vs b2, incremental explained variance by SESxGCSE
## [1] -0.0007052047

#Step 5: #Multi-group regression models

To test the robustness of our findings and reduce the likelihood of detecting spurious associations, we will fit a series of multi-group models to confirm the results of our hierarchical regression models across both samples of twins. We will use ANOVA tests to compare the fit of the ‘free’ model, where all parameters are unrestricted between both samples, to the restricted model, where all parameters are constrained to be equal. If the fit differences between the restricted and the unrestricted models are non-significant (pcorrected <.004), results will be interpreted as robust across both samples.

define model, fit without constrains for both groups (twin 1 and 2 according to random-variable), then constrain parameters to be equal and compare nested models with LRT

#linear: Zhqual, Zocprestige, Zinc, Zfina, Zwellb, Zanx, Zsdq, Zalc # logistic: u1cbenf11, status_bin # logistic w/ dummy coding: status1

#Linear multi-group regression models

rm(list=ls())
ls()
## character(0)
#read in both twins-dataset
df <- read.csv("/Users/cgb538/Library/CloudStorage/GoogleDrive-alexandra.starr@york.ac.uk/My Drive/projects and papers/DevPsych_prediction grades adulthood/data/grades_adulth_prepared_bothtwins.csv", header = T, strip.white = T,na.strings = c('NA', '', ' '
))


model2.hqual <- 'Zhqual ~ sex1 + SESscore + Zgcse'
multi.hqual.free <- sem(model2.hqual, data = df, group = "random", missing = "fiml", fixed.x = FALSE)
summary(multi.hqual.free, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 24 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        28
## 
##   Number of observations per group:                   
##     0                                             6493
##     1                                             6488
##   Number of missing patterns per group:               
##     0                                                4
##     1                                                4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
##   Test statistic for each group:
##     0                                            0.000
##     1                                            0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                              2725.674
##   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
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -52425.772
##   Loglikelihood unrestricted model (H1)     -52425.772
##                                                       
##   Akaike (AIC)                              104907.545
##   Bayesian (BIC)                            105116.739
##   Sample-size adjusted Bayesian (SABIC)     105027.758
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## 
## Group 1 [0]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zhqual ~                                                              
##     sex1             -0.035    0.028   -1.242    0.214   -0.089    0.020
##     SESscore          0.126    0.017    7.465    0.000    0.093    0.159
##     Zgcse             0.530    0.016   32.219    0.000    0.498    0.562
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.015    0.006    2.581    0.010    0.004    0.026
##     Zgcse            -0.031    0.006   -4.947    0.000   -0.043   -0.019
##   SESscore ~~                                                           
##     Zgcse             0.459    0.013   35.254    0.000    0.434    0.485
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zhqual           -0.106    0.017   -6.071    0.000   -0.140   -0.071
##     sex1              0.469    0.006   75.700    0.000    0.457    0.481
##     SESscore         -0.035    0.012   -3.037    0.002   -0.058   -0.013
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zhqual            0.676    0.016   43.130    0.000    0.645    0.707
##     sex1              0.249    0.004   56.978    0.000    0.240    0.258
##     SESscore          0.874    0.015   56.405    0.000    0.844    0.904
##     Zgcse             1.000    0.018   56.978    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zhqual            0.345
## 
## 
## Group 2 [1]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zhqual ~                                                              
##     sex1             -0.038    0.029   -1.320    0.187   -0.093    0.018
##     SESscore          0.133    0.017    7.900    0.000    0.100    0.167
##     Zgcse             0.504    0.017   30.177    0.000    0.472    0.537
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.429    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.433    0.000    0.422    0.473
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zhqual           -0.099    0.018   -5.485    0.000   -0.134   -0.063
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.034    0.012   -2.928    0.003   -0.057   -0.011
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zhqual            0.708    0.016   42.936    0.000    0.676    0.740
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.318    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zhqual            0.319
multi.hqual.cons <- sem(model2.hqual, data = df, group = "random", group.equal = c("intercepts", "regressions"), missing = "fiml", fixed.x = FALSE)
summary(multi.hqual.cons, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 29 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        28
##   Number of equality constraints                     4
## 
##   Number of observations per group:                   
##     0                                             6493
##     1                                             6488
##   Number of missing patterns per group:               
##     0                                                4
##     1                                                4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 1.242
##   Degrees of freedom                                 4
##   P-value (Chi-square)                           0.871
##   Test statistic for each group:
##     0                                            0.605
##     1                                            0.636
## 
## Model Test Baseline Model:
## 
##   Test statistic                              2725.674
##   Degrees of freedom                                 6
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.002
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.001
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -52426.393
##   Loglikelihood unrestricted model (H1)     -52425.772
##                                                       
##   Akaike (AIC)                              104900.786
##   Bayesian (BIC)                            105080.096
##   Sample-size adjusted Bayesian (SABIC)     105003.827
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.009
##   P-value H_0: RMSEA <= 0.050                    1.000
##   P-value H_0: RMSEA >= 0.080                    0.000
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.014
##   P-value H_0: Robust RMSEA <= 0.050             1.000
##   P-value H_0: Robust RMSEA >= 0.080             0.000
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.004
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## 
## Group 1 [0]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zhqual ~                                                              
##     sex1    (.p1.)   -0.036    0.020   -1.823    0.068   -0.075    0.003
##     SESscor (.p2.)    0.130    0.012   10.884    0.000    0.106    0.153
##     Zgcse   (.p3.)    0.517    0.012   44.140    0.000    0.494    0.540
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.015    0.006    2.581    0.010    0.004    0.026
##     Zgcse            -0.031    0.006   -4.947    0.000   -0.043   -0.019
##   SESscore ~~                                                           
##     Zgcse             0.459    0.013   35.255    0.000    0.434    0.485
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zhqual  (.11.)   -0.102    0.012   -8.167    0.000   -0.127   -0.078
##     sex1              0.469    0.006   75.700    0.000    0.457    0.481
##     SESscor          -0.036    0.012   -3.038    0.002   -0.058   -0.013
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zhqual            0.676    0.016   43.126    0.000    0.646    0.707
##     sex1              0.249    0.004   56.978    0.000    0.240    0.258
##     SESscore          0.874    0.015   56.404    0.000    0.844    0.904
##     Zgcse             1.000    0.018   56.978    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zhqual            0.338
## 
## 
## Group 2 [1]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zhqual ~                                                              
##     sex1    (.p1.)   -0.036    0.020   -1.823    0.068   -0.075    0.003
##     SESscor (.p2.)    0.130    0.012   10.884    0.000    0.106    0.153
##     Zgcse   (.p3.)    0.517    0.012   44.140    0.000    0.494    0.540
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.429    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.432    0.000    0.422    0.473
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zhqual  (.11.)   -0.102    0.012   -8.167    0.000   -0.127   -0.078
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscor          -0.034    0.012   -2.928    0.003   -0.057   -0.011
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zhqual            0.708    0.016   42.933    0.000    0.676    0.741
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.318    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zhqual            0.327
lavTestLRT(multi.hqual.free, multi.hqual.cons)
## 
## Chi-Squared Difference Test
## 
##                  Df    AIC    BIC  Chisq Chisq diff RMSEA Df diff Pr(>Chisq)
## multi.hqual.free  0 104908 105117 0.0000                                    
## multi.hqual.cons  4 104901 105080 1.2417     1.2417     0       4     0.8712
#anova(multi.hqual.free, multi.hqual.cons)    #<--- does exactly the same thing (Chi2 Diff test)
model3.degree <- 'Zdegree ~ sex1 + SESscore + Zgcse'
multi.degree.free <- sem(model3.degree, data = df, group = "random", missing = "fiml", fixed.x = FALSE)
summary(multi.degree.free, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 27 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        28
## 
##   Number of observations per group:                   
##     0                                             6493
##     1                                             6488
##   Number of missing patterns per group:               
##     0                                                4
##     1                                                4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
##   Test statistic for each group:
##     0                                            0.000
##     1                                            0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                               287.580
##   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
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -48162.041
##   Loglikelihood unrestricted model (H1)     -48162.041
##                                                       
##   Akaike (AIC)                               96380.081
##   Bayesian (BIC)                             96589.276
##   Sample-size adjusted Bayesian (SABIC)      96500.295
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## 
## Group 1 [0]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zdegree ~                                                             
##     sex1              0.013    0.047    0.276    0.783   -0.080    0.106
##     SESscore         -0.019    0.028   -0.676    0.499   -0.075    0.036
##     Zgcse             0.371    0.033   11.141    0.000    0.306    0.437
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.015    0.006    2.587    0.010    0.004    0.027
##     Zgcse            -0.031    0.006   -4.947    0.000   -0.043   -0.019
##   SESscore ~~                                                           
##     Zgcse             0.459    0.013   35.248    0.000    0.434    0.485
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zdegree          -0.209    0.034   -6.227    0.000   -0.274   -0.143
##     sex1              0.469    0.006   75.701    0.000    0.457    0.481
##     SESscore         -0.035    0.012   -3.025    0.002   -0.058   -0.012
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zdegree           0.926    0.031   29.774    0.000    0.865    0.987
##     sex1              0.249    0.004   56.978    0.000    0.240    0.258
##     SESscore          0.874    0.015   56.410    0.000    0.844    0.904
##     Zgcse             1.000    0.018   56.979    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zdegree           0.124
## 
## 
## Group 2 [1]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zdegree ~                                                             
##     sex1             -0.080    0.048   -1.672    0.095   -0.173    0.014
##     SESscore          0.014    0.028    0.505    0.613   -0.041    0.070
##     Zgcse             0.375    0.033   11.366    0.000    0.310    0.439
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.435    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.437    0.000    0.422    0.473
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zdegree          -0.170    0.032   -5.307    0.000   -0.232   -0.107
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.034    0.012   -2.928    0.003   -0.057   -0.011
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zdegree           0.917    0.031   29.792    0.000    0.857    0.978
##     sex1              0.249    0.004   56.957    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.312    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.957    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zdegree           0.139
multi.degree.cons <- sem(model3.degree, data = df, group = "random", group.equal = c("intercepts", "regressions"), missing = "fiml", fixed.x = FALSE)
summary(multi.degree.cons, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 37 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        28
##   Number of equality constraints                     4
## 
##   Number of observations per group:                   
##     0                                             6493
##     1                                             6488
##   Number of missing patterns per group:               
##     0                                                4
##     1                                                4
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 2.879
##   Degrees of freedom                                 4
##   P-value (Chi-square)                           0.578
##   Test statistic for each group:
##     0                                            1.419
##     1                                            1.460
## 
## Model Test Baseline Model:
## 
##   Test statistic                               287.580
##   Degrees of freedom                                 6
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.006
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.006
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -48163.480
##   Loglikelihood unrestricted model (H1)     -48162.041
##                                                       
##   Akaike (AIC)                               96374.960
##   Bayesian (BIC)                             96554.270
##   Sample-size adjusted Bayesian (SABIC)      96478.001
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.016
##   P-value H_0: RMSEA <= 0.050                    1.000
##   P-value H_0: RMSEA >= 0.080                    0.000
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.032
##   P-value H_0: Robust RMSEA <= 0.050             0.997
##   P-value H_0: Robust RMSEA >= 0.080             0.000
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.008
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## 
## Group 1 [0]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zdegree ~                                                             
##     sex1    (.p1.)   -0.033    0.034   -0.980    0.327   -0.099    0.033
##     SESscor (.p2.)   -0.003    0.020   -0.130    0.896   -0.042    0.037
##     Zgcse   (.p3.)    0.372    0.023   15.877    0.000    0.326    0.418
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.015    0.006    2.587    0.010    0.004    0.027
##     Zgcse            -0.031    0.006   -4.947    0.000   -0.043   -0.019
##   SESscore ~~                                                           
##     Zgcse             0.459    0.013   35.248    0.000    0.434    0.485
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zdegree (.11.)   -0.189    0.023   -8.156    0.000   -0.234   -0.143
##     sex1              0.469    0.006   75.700    0.000    0.457    0.481
##     SESscor          -0.035    0.012   -3.026    0.002   -0.058   -0.012
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zdegree           0.927    0.031   29.762    0.000    0.866    0.988
##     sex1              0.249    0.004   56.978    0.000    0.240    0.258
##     SESscore          0.874    0.015   56.409    0.000    0.844    0.904
##     Zgcse             1.000    0.018   56.978    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zdegree           0.130
## 
## 
## Group 2 [1]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zdegree ~                                                             
##     sex1    (.p1.)   -0.033    0.034   -0.980    0.327   -0.099    0.033
##     SESscor (.p2.)   -0.003    0.020   -0.130    0.896   -0.042    0.037
##     Zgcse   (.p3.)    0.372    0.023   15.877    0.000    0.326    0.418
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.434    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.437    0.000    0.422    0.473
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zdegree (.11.)   -0.189    0.023   -8.156    0.000   -0.234   -0.143
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscor          -0.034    0.012   -2.928    0.003   -0.057   -0.011
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zdegree           0.918    0.031   29.779    0.000    0.858    0.979
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.312    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
## 
## R-Square:
##                    Estimate
##     Zdegree           0.131
lavTestLRT(multi.degree.free, multi.degree.cons)
## 
## Chi-Squared Difference Test
## 
##                   Df   AIC   BIC  Chisq Chisq diff RMSEA Df diff Pr(>Chisq)
## multi.degree.free  0 96380 96589 0.0000                                    
## multi.degree.cons  4 96375 96554 2.8791      2.879     0       4     0.5783
model3.ocprestige <- 'Zsoc ~ sex1 + SESscore + Zgcse + Zhqual'
multi.ocprestige.free <- sem(model3.ocprestige, data = df, group = "random", missing = "fiml", fixed.x = FALSE)
summary(multi.ocprestige.free, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 30 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        40
## 
##   Number of observations per group:                   
##     0                                             6493
##     1                                             6488
##   Number of missing patterns per group:               
##     0                                                7
##     1                                                7
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
##   Test statistic for each group:
##     0                                            0.000
##     1                                            0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                               415.912
##   Degrees of freedom                                 8
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -57116.411
##   Loglikelihood unrestricted model (H1)     -57116.411
##                                                       
##   Akaike (AIC)                              114312.821
##   Bayesian (BIC)                            114611.671
##   Sample-size adjusted Bayesian (SABIC)     114484.555
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## 
## Group 1 [0]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zsoc ~                                                                
##     sex1              0.037    0.046    0.794    0.427   -0.054    0.128
##     SESscore          0.061    0.029    2.125    0.034    0.005    0.117
##     Zgcse             0.218    0.030    7.156    0.000    0.158    0.278
##     Zhqual            0.127    0.026    4.890    0.000    0.076    0.178
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.015    0.006    2.578    0.010    0.004    0.026
##     Zgcse            -0.031    0.006   -4.947    0.000   -0.043   -0.019
##     Zhqual           -0.023    0.008   -2.911    0.004   -0.038   -0.007
##   SESscore ~~                                                           
##     Zgcse             0.459    0.013   35.254    0.000    0.434    0.485
##     Zhqual            0.353    0.015   23.236    0.000    0.323    0.382
##   Zgcse ~~                                                              
##     Zhqual            0.588    0.018   33.319    0.000    0.554    0.623
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsoc              0.044    0.029    1.493    0.135   -0.014    0.101
##     sex1              0.469    0.006   75.700    0.000    0.457    0.481
##     SESscore         -0.035    0.012   -3.035    0.002   -0.058   -0.013
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
##     Zhqual           -0.126    0.016   -7.946    0.000   -0.157   -0.095
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsoc              0.889    0.030   29.712    0.000    0.830    0.947
##     sex1              0.249    0.004   56.978    0.000    0.240    0.258
##     SESscore          0.874    0.015   56.405    0.000    0.844    0.904
##     Zgcse             1.000    0.018   56.978    0.000    0.965    1.034
##     Zhqual            1.033    0.024   43.200    0.000    0.986    1.080
## 
## R-Square:
##                    Estimate
##     Zsoc              0.117
## 
## 
## Group 2 [1]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zsoc ~                                                                
##     sex1              0.183    0.048    3.824    0.000    0.089    0.276
##     SESscore          0.046    0.029    1.606    0.108   -0.010    0.102
##     Zgcse             0.191    0.031    6.067    0.000    0.129    0.252
##     Zhqual            0.168    0.025    6.601    0.000    0.118    0.218
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.428    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     Zhqual           -0.021    0.008   -2.610    0.009   -0.036   -0.005
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.433    0.000    0.422    0.473
##     Zhqual            0.342    0.015   22.301    0.000    0.312    0.372
##   Zgcse ~~                                                              
##     Zhqual            0.565    0.018   31.575    0.000    0.530    0.601
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsoc             -0.000    0.030   -0.003    0.998   -0.058    0.058
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.034    0.012   -2.929    0.003   -0.057   -0.011
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
##     Zhqual           -0.121    0.016   -7.532    0.000   -0.153   -0.090
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsoc              0.883    0.030   29.023    0.000    0.823    0.942
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.318    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     Zhqual            1.040    0.024   42.563    0.000    0.992    1.088
## 
## R-Square:
##                    Estimate
##     Zsoc              0.122
multi.ocprestige.cons <- sem(model3.ocprestige, data = df, group = "random", group.equal = c("intercepts", "regressions"), missing = "fiml", fixed.x = FALSE)
summary(multi.ocprestige.cons, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 36 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        40
##   Number of equality constraints                     5
## 
##   Number of observations per group:                   
##     0                                             6493
##     1                                             6488
##   Number of missing patterns per group:               
##     0                                                7
##     1                                                7
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 5.905
##   Degrees of freedom                                 5
##   P-value (Chi-square)                           0.316
##   Test statistic for each group:
##     0                                            2.866
##     1                                            3.039
## 
## Model Test Baseline Model:
## 
##   Test statistic                               415.912
##   Degrees of freedom                                 8
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.998
##   Tucker-Lewis Index (TLI)                       0.996
##                                                       
##   Robust Comparative Fit Index (CFI)             0.997
##   Robust Tucker-Lewis Index (TLI)                0.995
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -57119.363
##   Loglikelihood unrestricted model (H1)     -57116.411
##                                                       
##   Akaike (AIC)                              114308.727
##   Bayesian (BIC)                            114570.220
##   Sample-size adjusted Bayesian (SABIC)     114458.994
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.005
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.019
##   P-value H_0: RMSEA <= 0.050                    1.000
##   P-value H_0: RMSEA >= 0.080                    0.000
##                                                       
##   Robust RMSEA                                   0.013
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.039
##   P-value H_0: Robust RMSEA <= 0.050             0.995
##   P-value H_0: Robust RMSEA >= 0.080             0.000
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.009
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## 
## Group 1 [0]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zsoc ~                                                                
##     sex1    (.p1.)    0.107    0.033    3.214    0.001    0.042    0.173
##     SESscor (.p2.)    0.053    0.020    2.620    0.009    0.013    0.093
##     Zgcse   (.p3.)    0.205    0.022    9.378    0.000    0.162    0.248
##     Zhqual  (.p4.)    0.147    0.018    8.106    0.000    0.112    0.183
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.015    0.006    2.578    0.010    0.004    0.026
##     Zgcse            -0.031    0.006   -4.947    0.000   -0.043   -0.019
##     Zhqual           -0.023    0.008   -2.913    0.004   -0.038   -0.007
##   SESscore ~~                                                           
##     Zgcse             0.459    0.013   35.254    0.000    0.434    0.485
##     Zhqual            0.353    0.015   23.237    0.000    0.323    0.382
##   Zgcse ~~                                                              
##     Zhqual            0.588    0.018   33.319    0.000    0.554    0.623
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsoc    (.16.)    0.022    0.021    1.054    0.292   -0.019    0.063
##     sex1              0.469    0.006   75.700    0.000    0.457    0.481
##     SESscor          -0.035    0.012   -3.035    0.002   -0.058   -0.013
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
##     Zhqual           -0.126    0.016   -7.947    0.000   -0.157   -0.095
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsoc              0.890    0.030   29.687    0.000    0.831    0.949
##     sex1              0.249    0.004   56.978    0.000    0.240    0.258
##     SESscore          0.874    0.015   56.405    0.000    0.844    0.904
##     Zgcse             1.000    0.018   56.978    0.000    0.965    1.034
##     Zhqual            1.033    0.024   43.202    0.000    0.986    1.080
## 
## R-Square:
##                    Estimate
##     Zsoc              0.118
## 
## 
## Group 2 [1]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zsoc ~                                                                
##     sex1    (.p1.)    0.107    0.033    3.214    0.001    0.042    0.173
##     SESscor (.p2.)    0.053    0.020    2.620    0.009    0.013    0.093
##     Zgcse   (.p3.)    0.205    0.022    9.378    0.000    0.162    0.248
##     Zhqual  (.p4.)    0.147    0.018    8.106    0.000    0.112    0.183
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.429    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     Zhqual           -0.021    0.008   -2.608    0.009   -0.036   -0.005
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.433    0.000    0.422    0.473
##     Zhqual            0.342    0.015   22.298    0.000    0.312    0.372
##   Zgcse ~~                                                              
##     Zhqual            0.565    0.018   31.571    0.000    0.530    0.600
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsoc    (.16.)    0.022    0.021    1.054    0.292   -0.019    0.063
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscor          -0.034    0.012   -2.930    0.003   -0.057   -0.011
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
##     Zhqual           -0.121    0.016   -7.529    0.000   -0.153   -0.090
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsoc              0.884    0.030   28.999    0.000    0.825    0.944
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.318    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     Zhqual            1.040    0.024   42.564    0.000    0.992    1.088
## 
## R-Square:
##                    Estimate
##     Zsoc              0.117
lavTestLRT(multi.ocprestige.free, multi.ocprestige.cons)
## 
## Chi-Squared Difference Test
## 
##                       Df    AIC    BIC  Chisq Chisq diff     RMSEA Df diff
## multi.ocprestige.free  0 114313 114612 0.0000                             
## multi.ocprestige.cons  5 114309 114570 5.9055     5.9055 0.0052823       5
##                       Pr(>Chisq)
## multi.ocprestige.free           
## multi.ocprestige.cons     0.3155
model3.inc <- 'Zinc ~ sex1 + SESscore + Zgcse + Zhqual'
multi.inc.free <- sem(model3.inc, data = df, group = "random", missing = "fiml", fixed.x = FALSE)
summary(multi.inc.free, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 33 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        40
## 
##   Number of observations per group:                   
##     0                                             6493
##     1                                             6488
##   Number of missing patterns per group:               
##     0                                                7
##     1                                                7
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
##   Test statistic for each group:
##     0                                            0.000
##     1                                            0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                               269.817
##   Degrees of freedom                                 8
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -57680.411
##   Loglikelihood unrestricted model (H1)     -57680.411
##                                                       
##   Akaike (AIC)                              115440.822
##   Bayesian (BIC)                            115739.672
##   Sample-size adjusted Bayesian (SABIC)     115612.556
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## 
## Group 1 [0]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zinc ~                                                                
##     sex1              0.405    0.046    8.869    0.000    0.316    0.495
##     SESscore          0.040    0.028    1.427    0.154   -0.015    0.096
##     Zgcse             0.180    0.030    5.959    0.000    0.121    0.239
##     Zhqual           -0.018    0.026   -0.677    0.498   -0.069    0.033
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.015    0.006    2.584    0.010    0.004    0.027
##     Zgcse            -0.031    0.006   -4.947    0.000   -0.043   -0.019
##     Zhqual           -0.023    0.008   -2.922    0.003   -0.038   -0.008
##   SESscore ~~                                                           
##     Zgcse             0.459    0.013   35.254    0.000    0.434    0.485
##     Zhqual            0.353    0.015   23.225    0.000    0.323    0.382
##   Zgcse ~~                                                              
##     Zhqual            0.589    0.018   33.329    0.000    0.554    0.623
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zinc             -0.144    0.029   -5.011    0.000   -0.201   -0.088
##     sex1              0.469    0.006   75.701    0.000    0.457    0.481
##     SESscore         -0.035    0.012   -3.035    0.002   -0.058   -0.013
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
##     Zhqual           -0.126    0.016   -7.950    0.000   -0.157   -0.095
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zinc              0.931    0.030   30.966    0.000    0.872    0.990
##     sex1              0.249    0.004   56.978    0.000    0.240    0.258
##     SESscore          0.874    0.015   56.405    0.000    0.844    0.904
##     Zgcse             1.000    0.018   56.978    0.000    0.965    1.034
##     Zhqual            1.033    0.024   43.188    0.000    0.986    1.080
## 
## R-Square:
##                    Estimate
##     Zinc              0.073
## 
## 
## Group 2 [1]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zinc ~                                                                
##     sex1              0.388    0.046    8.349    0.000    0.297    0.479
##     SESscore          0.041    0.028    1.482    0.138   -0.013    0.096
##     Zgcse             0.162    0.030    5.404    0.000    0.103    0.221
##     Zhqual            0.020    0.025    0.802    0.423   -0.029    0.069
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.428    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     Zhqual           -0.021    0.008   -2.607    0.009   -0.036   -0.005
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.432    0.000    0.422    0.473
##     Zhqual            0.342    0.015   22.279    0.000    0.312    0.372
##   Zgcse ~~                                                              
##     Zhqual            0.565    0.018   31.552    0.000    0.530    0.600
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zinc             -0.121    0.029   -4.209    0.000   -0.177   -0.065
##     sex1              0.474    0.006   76.502    0.000    0.462    0.486
##     SESscore         -0.034    0.012   -2.929    0.003   -0.057   -0.011
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
##     Zhqual           -0.121    0.016   -7.517    0.000   -0.153   -0.089
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zinc              0.931    0.030   30.666    0.000    0.871    0.990
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.318    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     Zhqual            1.040    0.024   42.569    0.000    0.992    1.087
## 
## R-Square:
##                    Estimate
##     Zinc              0.073
multi.inc.cons <- sem(model3.inc, data = df, group = "random", group.equal = c("intercepts", "regressions"), missing = "fiml", fixed.x = FALSE)
summary(multi.inc.cons, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 38 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        40
##   Number of equality constraints                     5
## 
##   Number of observations per group:                   
##     0                                             6493
##     1                                             6488
##   Number of missing patterns per group:               
##     0                                                7
##     1                                                7
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 1.285
##   Degrees of freedom                                 5
##   P-value (Chi-square)                           0.936
##   Test statistic for each group:
##     0                                            0.661
##     1                                            0.624
## 
## Model Test Baseline Model:
## 
##   Test statistic                               269.817
##   Degrees of freedom                                 8
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.023
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.022
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -57681.054
##   Loglikelihood unrestricted model (H1)     -57680.411
##                                                       
##   Akaike (AIC)                              115432.107
##   Bayesian (BIC)                            115693.601
##   Sample-size adjusted Bayesian (SABIC)     115582.374
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.004
##   P-value H_0: RMSEA <= 0.050                    1.000
##   P-value H_0: RMSEA >= 0.080                    0.000
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.004
##   P-value H_0: Robust RMSEA <= 0.050             1.000
##   P-value H_0: Robust RMSEA >= 0.080             0.000
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.004
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## 
## Group 1 [0]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zinc ~                                                                
##     sex1    (.p1.)    0.397    0.033   12.172    0.000    0.333    0.461
##     SESscor (.p2.)    0.040    0.020    2.033    0.042    0.001    0.079
##     Zgcse   (.p3.)    0.170    0.021    8.001    0.000    0.128    0.212
##     Zhqual  (.p4.)    0.002    0.018    0.109    0.913   -0.033    0.037
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.015    0.006    2.584    0.010    0.004    0.027
##     Zgcse            -0.031    0.006   -4.947    0.000   -0.043   -0.019
##     Zhqual           -0.023    0.008   -2.922    0.003   -0.038   -0.008
##   SESscore ~~                                                           
##     Zgcse             0.459    0.013   35.254    0.000    0.434    0.485
##     Zhqual            0.353    0.015   23.227    0.000    0.323    0.382
##   Zgcse ~~                                                              
##     Zhqual            0.589    0.018   33.329    0.000    0.554    0.623
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zinc    (.16.)   -0.132    0.020   -6.511    0.000   -0.172   -0.092
##     sex1              0.469    0.006   75.700    0.000    0.457    0.481
##     SESscor          -0.035    0.012   -3.035    0.002   -0.058   -0.013
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
##     Zhqual           -0.126    0.016   -7.950    0.000   -0.157   -0.095
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zinc              0.931    0.030   30.962    0.000    0.873    0.990
##     sex1              0.249    0.004   56.978    0.000    0.240    0.258
##     SESscore          0.874    0.015   56.405    0.000    0.844    0.904
##     Zgcse             1.000    0.018   56.978    0.000    0.965    1.034
##     Zhqual            1.033    0.024   43.188    0.000    0.986    1.080
## 
## R-Square:
##                    Estimate
##     Zinc              0.072
## 
## 
## Group 2 [1]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zinc ~                                                                
##     sex1    (.p1.)    0.397    0.033   12.172    0.000    0.333    0.461
##     SESscor (.p2.)    0.040    0.020    2.033    0.042    0.001    0.079
##     Zgcse   (.p3.)    0.170    0.021    8.001    0.000    0.128    0.212
##     Zhqual  (.p4.)    0.002    0.018    0.109    0.913   -0.033    0.037
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.428    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     Zhqual           -0.021    0.008   -2.604    0.009   -0.036   -0.005
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.432    0.000    0.422    0.473
##     Zhqual            0.342    0.015   22.274    0.000    0.312    0.372
##   Zgcse ~~                                                              
##     Zhqual            0.565    0.018   31.549    0.000    0.530    0.600
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zinc    (.16.)   -0.132    0.020   -6.511    0.000   -0.172   -0.092
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscor          -0.034    0.012   -2.929    0.003   -0.057   -0.011
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
##     Zhqual           -0.121    0.016   -7.515    0.000   -0.153   -0.089
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zinc              0.931    0.030   30.662    0.000    0.871    0.991
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.318    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     Zhqual            1.039    0.024   42.573    0.000    0.992    1.087
## 
## R-Square:
##                    Estimate
##     Zinc              0.073
lavTestLRT(multi.inc.free, multi.inc.cons)
## 
## Chi-Squared Difference Test
## 
##                Df    AIC    BIC  Chisq Chisq diff RMSEA Df diff Pr(>Chisq)
## multi.inc.free  0 115441 115740 0.0000                                    
## multi.inc.cons  5 115432 115694 1.2853     1.2853     0       5     0.9364
model3.mon <- 'Zmon ~ sex1 + SESscore + Zgcse + Zhqual'
multi.mon.free <- sem(model3.mon, data = df, group = "random", missing = "fiml", fixed.x = FALSE)
summary(multi.mon.free, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 22 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        40
## 
##   Number of observations per group:                   
##     0                                             6493
##     1                                             6488
##   Number of missing patterns per group:               
##     0                                                7
##     1                                                7
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
##   Test statistic for each group:
##     0                                            0.000
##     1                                            0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                               127.475
##   Degrees of freedom                                 8
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -62824.287
##   Loglikelihood unrestricted model (H1)     -62824.287
##                                                       
##   Akaike (AIC)                              125728.575
##   Bayesian (BIC)                            126027.424
##   Sample-size adjusted Bayesian (SABIC)     125900.308
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## 
## Group 1 [0]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zmon ~                                                                
##     sex1             -0.134    0.034   -3.982    0.000   -0.200   -0.068
##     SESscore         -0.092    0.020   -4.505    0.000   -0.132   -0.052
##     Zgcse             0.099    0.022    4.411    0.000    0.055    0.143
##     Zhqual           -0.013    0.020   -0.637    0.524   -0.052    0.027
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.015    0.006    2.582    0.010    0.004    0.026
##     Zgcse            -0.031    0.006   -4.947    0.000   -0.043   -0.019
##     Zhqual           -0.023    0.008   -2.919    0.004   -0.038   -0.008
##   SESscore ~~                                                           
##     Zgcse             0.459    0.013   35.255    0.000    0.434    0.485
##     Zhqual            0.353    0.015   23.252    0.000    0.323    0.383
##   Zgcse ~~                                                              
##     Zhqual            0.588    0.018   33.325    0.000    0.554    0.623
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zmon              0.035    0.021    1.666    0.096   -0.006    0.077
##     sex1              0.469    0.006   75.700    0.000    0.457    0.481
##     SESscore         -0.036    0.012   -3.047    0.002   -0.059   -0.013
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
##     Zhqual           -0.126    0.016   -7.947    0.000   -0.157   -0.095
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zmon              0.987    0.023   43.089    0.000    0.942    1.032
##     sex1              0.249    0.004   56.978    0.000    0.240    0.258
##     SESscore          0.874    0.015   56.403    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.978    0.000    0.965    1.034
##     Zhqual            1.033    0.024   43.191    0.000    0.986    1.080
## 
## R-Square:
##                    Estimate
##     Zmon              0.014
## 
## 
## Group 2 [1]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zmon ~                                                                
##     sex1             -0.230    0.034   -6.828    0.000   -0.295   -0.164
##     SESscore         -0.094    0.020   -4.614    0.000   -0.133   -0.054
##     Zgcse             0.084    0.022    3.806    0.000    0.041    0.127
##     Zhqual            0.024    0.020    1.209    0.227   -0.015    0.062
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.426    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     Zhqual           -0.021    0.008   -2.604    0.009   -0.036   -0.005
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.423    0.000    0.422    0.473
##     Zhqual            0.342    0.015   22.278    0.000    0.312    0.372
##   Zgcse ~~                                                              
##     Zhqual            0.565    0.018   31.554    0.000    0.530    0.600
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zmon              0.077    0.021    3.618    0.000    0.035    0.119
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.034    0.012   -2.924    0.003   -0.057   -0.011
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
##     Zhqual           -0.121    0.016   -7.517    0.000   -0.153   -0.089
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zmon              0.978    0.023   42.773    0.000    0.933    1.023
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.874    0.016   56.325    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     Zhqual            1.040    0.024   42.571    0.000    0.992    1.087
## 
## R-Square:
##                    Estimate
##     Zmon              0.024
multi.mon.cons <- sem(model3.mon, data = df, group = "random", group.equal = c("intercepts", "regressions"), missing = "fiml", fixed.x = FALSE)
summary(multi.mon.cons, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 30 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        40
##   Number of equality constraints                     5
## 
##   Number of observations per group:                   
##     0                                             6493
##     1                                             6488
##   Number of missing patterns per group:               
##     0                                                7
##     1                                                7
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 5.858
##   Degrees of freedom                                 5
##   P-value (Chi-square)                           0.320
##   Test statistic for each group:
##     0                                            2.946
##     1                                            2.912
## 
## Model Test Baseline Model:
## 
##   Test statistic                               127.475
##   Degrees of freedom                                 8
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.993
##   Tucker-Lewis Index (TLI)                       0.989
##                                                       
##   Robust Comparative Fit Index (CFI)             0.993
##   Robust Tucker-Lewis Index (TLI)                0.988
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -62827.216
##   Loglikelihood unrestricted model (H1)     -62824.287
##                                                       
##   Akaike (AIC)                              125724.432
##   Bayesian (BIC)                            125985.926
##   Sample-size adjusted Bayesian (SABIC)     125874.699
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.005
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.019
##   P-value H_0: RMSEA <= 0.050                    1.000
##   P-value H_0: RMSEA >= 0.080                    0.000
##                                                       
##   Robust RMSEA                                   0.007
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.026
##   P-value H_0: Robust RMSEA <= 0.050             1.000
##   P-value H_0: Robust RMSEA >= 0.080             0.000
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.007
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## 
## Group 1 [0]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zmon ~                                                                
##     sex1    (.p1.)   -0.182    0.024   -7.636    0.000   -0.229   -0.135
##     SESscor (.p2.)   -0.093    0.014   -6.442    0.000   -0.121   -0.065
##     Zgcse   (.p3.)    0.091    0.016    5.763    0.000    0.060    0.121
##     Zhqual  (.p4.)    0.006    0.014    0.420    0.674   -0.022    0.033
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.015    0.006    2.581    0.010    0.004    0.026
##     Zgcse            -0.031    0.006   -4.947    0.000   -0.043   -0.019
##     Zhqual           -0.023    0.008   -2.921    0.003   -0.038   -0.008
##   SESscore ~~                                                           
##     Zgcse             0.459    0.013   35.255    0.000    0.434    0.485
##     Zhqual            0.353    0.015   23.253    0.000    0.323    0.383
##   Zgcse ~~                                                              
##     Zhqual            0.589    0.018   33.330    0.000    0.554    0.623
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zmon    (.16.)    0.056    0.015    3.735    0.000    0.027    0.086
##     sex1              0.469    0.006   75.700    0.000    0.457    0.481
##     SESscor          -0.036    0.012   -3.047    0.002   -0.059   -0.013
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
##     Zhqual           -0.126    0.016   -7.949    0.000   -0.157   -0.095
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zmon              0.988    0.023   43.073    0.000    0.943    1.033
##     sex1              0.249    0.004   56.978    0.000    0.240    0.258
##     SESscore          0.874    0.015   56.403    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.978    0.000    0.965    1.034
##     Zhqual            1.033    0.024   43.188    0.000    0.986    1.080
## 
## R-Square:
##                    Estimate
##     Zmon              0.018
## 
## 
## Group 2 [1]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zmon ~                                                                
##     sex1    (.p1.)   -0.182    0.024   -7.636    0.000   -0.229   -0.135
##     SESscor (.p2.)   -0.093    0.014   -6.442    0.000   -0.121   -0.065
##     Zgcse   (.p3.)    0.091    0.016    5.763    0.000    0.060    0.121
##     Zhqual  (.p4.)    0.006    0.014    0.420    0.674   -0.022    0.033
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.426    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     Zhqual           -0.021    0.008   -2.604    0.009   -0.036   -0.005
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.423    0.000    0.422    0.472
##     Zhqual            0.342    0.015   22.277    0.000    0.312    0.372
##   Zgcse ~~                                                              
##     Zhqual            0.565    0.018   31.551    0.000    0.530    0.600
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zmon    (.16.)    0.056    0.015    3.735    0.000    0.027    0.086
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscor          -0.034    0.012   -2.924    0.003   -0.057   -0.011
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
##     Zhqual           -0.121    0.016   -7.517    0.000   -0.153   -0.089
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zmon              0.979    0.023   42.757    0.000    0.934    1.024
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.874    0.016   56.326    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     Zhqual            1.039    0.024   42.573    0.000    0.992    1.087
## 
## R-Square:
##                    Estimate
##     Zmon              0.018
lavTestLRT(multi.mon.free, multi.mon.cons)
## 
## Chi-Squared Difference Test
## 
##                Df    AIC    BIC  Chisq Chisq diff     RMSEA Df diff Pr(>Chisq)
## multi.mon.free  0 125729 126027 0.0000                                        
## multi.mon.cons  5 125724 125986 5.8577     5.8577 0.0051409       5     0.3203
model3.fina <- 'Zfina ~ sex1 + SESscore + Zgcse + Zhqual'
multi.fina.free <- sem(model3.fina, data = df, group = "random", missing = "fiml", fixed.x = FALSE)
summary(multi.fina.free, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 26 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        40
## 
##   Number of observations per group:                   
##     0                                             6493
##     1                                             6488
##   Number of missing patterns per group:               
##     0                                                7
##     1                                                7
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
##   Test statistic for each group:
##     0                                            0.000
##     1                                            0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                                90.109
##   Degrees of freedom                                 8
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -62845.808
##   Loglikelihood unrestricted model (H1)     -62845.808
##                                                       
##   Akaike (AIC)                              125771.617
##   Bayesian (BIC)                            126070.466
##   Sample-size adjusted Bayesian (SABIC)     125943.350
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## 
## Group 1 [0]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zfina ~                                                               
##     sex1              0.080    0.034    2.382    0.017    0.014    0.146
##     SESscore         -0.036    0.020   -1.761    0.078   -0.076    0.004
##     Zgcse             0.107    0.022    4.778    0.000    0.063    0.151
##     Zhqual           -0.132    0.020   -6.575    0.000   -0.172   -0.093
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.015    0.006    2.578    0.010    0.004    0.026
##     Zgcse            -0.031    0.006   -4.947    0.000   -0.043   -0.019
##     Zhqual           -0.023    0.008   -2.925    0.003   -0.038   -0.008
##   SESscore ~~                                                           
##     Zgcse             0.459    0.013   35.255    0.000    0.434    0.485
##     Zhqual            0.352    0.015   23.230    0.000    0.323    0.382
##   Zgcse ~~                                                              
##     Zhqual            0.588    0.018   33.310    0.000    0.553    0.623
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zfina            -0.051    0.021   -2.402    0.016   -0.092   -0.009
##     sex1              0.469    0.006   75.700    0.000    0.457    0.481
##     SESscore         -0.035    0.012   -3.038    0.002   -0.058   -0.013
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
##     Zhqual           -0.126    0.016   -7.941    0.000   -0.157   -0.095
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zfina             0.985    0.023   43.079    0.000    0.940    1.029
##     sex1              0.249    0.004   56.978    0.000    0.240    0.258
##     SESscore          0.874    0.015   56.404    0.000    0.844    0.904
##     Zgcse             1.000    0.018   56.978    0.000    0.965    1.034
##     Zhqual            1.032    0.024   43.208    0.000    0.986    1.079
## 
## R-Square:
##                    Estimate
##     Zfina             0.015
## 
## 
## Group 2 [1]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zfina ~                                                               
##     sex1              0.063    0.034    1.863    0.063   -0.003    0.129
##     SESscore         -0.069    0.020   -3.376    0.001   -0.109   -0.029
##     Zgcse             0.084    0.022    3.788    0.000    0.040    0.127
##     Zhqual           -0.079    0.020   -4.006    0.000   -0.118   -0.040
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.425    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     Zhqual           -0.021    0.008   -2.595    0.009   -0.036   -0.005
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.428    0.000    0.422    0.473
##     Zhqual            0.342    0.015   22.274    0.000    0.312    0.372
##   Zgcse ~~                                                              
##     Zhqual            0.565    0.018   31.549    0.000    0.530    0.600
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zfina            -0.038    0.021   -1.768    0.077   -0.080    0.004
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.034    0.012   -2.918    0.004   -0.057   -0.011
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
##     Zhqual           -0.121    0.016   -7.527    0.000   -0.153   -0.090
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zfina             0.990    0.023   42.784    0.000    0.945    1.036
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.322    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     Zhqual            1.039    0.024   42.579    0.000    0.991    1.087
## 
## R-Square:
##                    Estimate
##     Zfina             0.010
multi.fina.cons <- sem(model3.fina, data = df, group = "random", group.equal = c("intercepts", "regressions"), missing = "fiml", fixed.x = FALSE)
summary(multi.fina.cons, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 34 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        40
##   Number of equality constraints                     5
## 
##   Number of observations per group:                   
##     0                                             6493
##     1                                             6488
##   Number of missing patterns per group:               
##     0                                                7
##     1                                                7
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 4.660
##   Degrees of freedom                                 5
##   P-value (Chi-square)                           0.459
##   Test statistic for each group:
##     0                                            2.362
##     1                                            2.298
## 
## Model Test Baseline Model:
## 
##   Test statistic                                90.109
##   Degrees of freedom                                 8
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.007
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.010
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -62848.138
##   Loglikelihood unrestricted model (H1)     -62845.808
##                                                       
##   Akaike (AIC)                              125766.277
##   Bayesian (BIC)                            126027.770
##   Sample-size adjusted Bayesian (SABIC)     125916.544
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.017
##   P-value H_0: RMSEA <= 0.050                    1.000
##   P-value H_0: RMSEA >= 0.080                    0.000
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.022
##   P-value H_0: Robust RMSEA <= 0.050             1.000
##   P-value H_0: Robust RMSEA >= 0.080             0.000
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.004
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## 
## Group 1 [0]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zfina ~                                                               
##     sex1    (.p1.)    0.072    0.024    3.001    0.003    0.025    0.118
##     SESscor (.p2.)   -0.052    0.014   -3.627    0.000   -0.081   -0.024
##     Zgcse   (.p3.)    0.095    0.016    6.036    0.000    0.064    0.126
##     Zhqual  (.p4.)   -0.105    0.014   -7.457    0.000   -0.133   -0.078
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.015    0.006    2.577    0.010    0.004    0.026
##     Zgcse            -0.031    0.006   -4.947    0.000   -0.043   -0.019
##     Zhqual           -0.023    0.008   -2.924    0.003   -0.038   -0.008
##   SESscore ~~                                                           
##     Zgcse             0.459    0.013   35.255    0.000    0.434    0.485
##     Zhqual            0.353    0.015   23.232    0.000    0.323    0.382
##   Zgcse ~~                                                              
##     Zhqual            0.588    0.018   33.313    0.000    0.553    0.623
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zfina   (.16.)   -0.044    0.015   -2.945    0.003   -0.074   -0.015
##     sex1              0.469    0.006   75.700    0.000    0.457    0.481
##     SESscor          -0.036    0.012   -3.038    0.002   -0.058   -0.013
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
##     Zhqual           -0.126    0.016   -7.942    0.000   -0.157   -0.095
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zfina             0.985    0.023   43.068    0.000    0.940    1.030
##     sex1              0.249    0.004   56.978    0.000    0.240    0.258
##     SESscore          0.874    0.015   56.404    0.000    0.844    0.904
##     Zgcse             1.000    0.018   56.978    0.000    0.965    1.034
##     Zhqual            1.033    0.024   43.204    0.000    0.986    1.079
## 
## R-Square:
##                    Estimate
##     Zfina             0.012
## 
## 
## Group 2 [1]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zfina ~                                                               
##     sex1    (.p1.)    0.072    0.024    3.001    0.003    0.025    0.118
##     SESscor (.p2.)   -0.052    0.014   -3.627    0.000   -0.081   -0.024
##     Zgcse   (.p3.)    0.095    0.016    6.036    0.000    0.064    0.126
##     Zhqual  (.p4.)   -0.105    0.014   -7.457    0.000   -0.133   -0.078
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.426    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     Zhqual           -0.021    0.008   -2.591    0.010   -0.036   -0.005
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.429    0.000    0.422    0.473
##     Zhqual            0.342    0.015   22.273    0.000    0.312    0.372
##   Zgcse ~~                                                              
##     Zhqual            0.565    0.018   31.550    0.000    0.530    0.600
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zfina   (.16.)   -0.044    0.015   -2.945    0.003   -0.074   -0.015
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscor          -0.034    0.012   -2.920    0.003   -0.057   -0.011
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
##     Zhqual           -0.121    0.016   -7.531    0.000   -0.153   -0.090
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zfina             0.991    0.023   42.770    0.000    0.945    1.036
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.321    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     Zhqual            1.039    0.024   42.581    0.000    0.991    1.087
## 
## R-Square:
##                    Estimate
##     Zfina             0.012
lavTestLRT(multi.fina.free, multi.fina.cons)
## 
## Chi-Squared Difference Test
## 
##                 Df    AIC    BIC  Chisq Chisq diff RMSEA Df diff Pr(>Chisq)
## multi.fina.free  0 125772 126070 0.0000                                    
## multi.fina.cons  5 125766 126028 4.6603     4.6603     0       5     0.4587
model3.wellb <- 'Zwellb ~ sex1 + SESscore + Zgcse + Zhqual'
multi.wellb.free <- sem(model3.wellb, data = df, group = "random", missing = "fiml", fixed.x = FALSE)
summary(multi.wellb.free, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 24 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        40
## 
##   Number of observations per group:                   
##     0                                             6493
##     1                                             6488
##   Number of missing patterns per group:               
##     0                                                7
##     1                                                8
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
##   Test statistic for each group:
##     0                                            0.000
##     1                                            0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                               251.998
##   Degrees of freedom                                 8
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -63003.246
##   Loglikelihood unrestricted model (H1)     -63003.246
##                                                       
##   Akaike (AIC)                              126086.491
##   Bayesian (BIC)                            126385.341
##   Sample-size adjusted Bayesian (SABIC)     126258.225
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## 
## Group 1 [0]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zwellb ~                                                              
##     sex1              0.312    0.033    9.476    0.000    0.248    0.377
##     SESscore          0.013    0.020    0.656    0.512   -0.026    0.053
##     Zgcse             0.105    0.022    4.787    0.000    0.062    0.148
##     Zhqual            0.009    0.020    0.446    0.656   -0.030    0.048
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.015    0.006    2.583    0.010    0.004    0.027
##     Zgcse            -0.031    0.006   -4.947    0.000   -0.043   -0.019
##     Zhqual           -0.023    0.008   -2.922    0.003   -0.038   -0.008
##   SESscore ~~                                                           
##     Zgcse             0.459    0.013   35.254    0.000    0.434    0.485
##     Zhqual            0.353    0.015   23.233    0.000    0.323    0.382
##   Zgcse ~~                                                              
##     Zhqual            0.589    0.018   33.330    0.000    0.554    0.623
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zwellb           -0.140    0.021   -6.767    0.000   -0.181   -0.100
##     sex1              0.469    0.006   75.700    0.000    0.457    0.481
##     SESscore         -0.035    0.012   -3.038    0.002   -0.058   -0.013
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
##     Zhqual           -0.126    0.016   -7.952    0.000   -0.157   -0.095
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zwellb            0.964    0.022   43.531    0.000    0.921    1.008
##     sex1              0.249    0.004   56.978    0.000    0.240    0.258
##     SESscore          0.874    0.015   56.405    0.000    0.844    0.904
##     Zgcse             1.000    0.018   56.978    0.000    0.965    1.034
##     Zhqual            1.033    0.024   43.187    0.000    0.986    1.080
## 
## R-Square:
##                    Estimate
##     Zwellb            0.036
## 
## 
## Group 2 [1]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zwellb ~                                                              
##     sex1              0.266    0.033    8.034    0.000    0.201    0.331
##     SESscore          0.006    0.020    0.316    0.752   -0.033    0.045
##     Zgcse             0.085    0.022    3.953    0.000    0.043    0.128
##     Zhqual            0.048    0.019    2.455    0.014    0.010    0.086
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.430    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     Zhqual           -0.021    0.008   -2.600    0.009   -0.036   -0.005
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.433    0.000    0.422    0.473
##     Zhqual            0.342    0.015   22.281    0.000    0.312    0.372
##   Zgcse ~~                                                              
##     Zhqual            0.565    0.018   31.558    0.000    0.530    0.600
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zwellb           -0.119    0.021   -5.712    0.000   -0.160   -0.078
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.034    0.012   -2.928    0.003   -0.057   -0.011
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
##     Zhqual           -0.121    0.016   -7.522    0.000   -0.153   -0.090
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zwellb            0.969    0.022   43.322    0.000    0.925    1.013
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.318    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     Zhqual            1.040    0.024   42.569    0.000    0.992    1.088
## 
## R-Square:
##                    Estimate
##     Zwellb            0.031
multi.wellb.cons <- sem(model3.wellb, data = df, group = "random", group.equal = c("intercepts", "regressions"), missing = "fiml", fixed.x = FALSE)
summary(multi.wellb.cons, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 30 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        40
##   Number of equality constraints                     5
## 
##   Number of observations per group:                   
##     0                                             6493
##     1                                             6488
##   Number of missing patterns per group:               
##     0                                                7
##     1                                                8
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 2.986
##   Degrees of freedom                                 5
##   P-value (Chi-square)                           0.702
##   Test statistic for each group:
##     0                                            1.525
##     1                                            1.461
## 
## Model Test Baseline Model:
## 
##   Test statistic                               251.998
##   Degrees of freedom                                 8
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.013
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.014
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -63004.739
##   Loglikelihood unrestricted model (H1)     -63003.246
##                                                       
##   Akaike (AIC)                              126079.477
##   Bayesian (BIC)                            126340.971
##   Sample-size adjusted Bayesian (SABIC)     126229.744
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.013
##   P-value H_0: RMSEA <= 0.050                    1.000
##   P-value H_0: RMSEA >= 0.080                    0.000
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.018
##   P-value H_0: Robust RMSEA <= 0.050             1.000
##   P-value H_0: Robust RMSEA >= 0.080             0.000
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.004
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## 
## Group 1 [0]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zwellb ~                                                              
##     sex1    (.p1.)    0.289    0.023   12.376    0.000    0.243    0.335
##     SESscor (.p2.)    0.010    0.014    0.690    0.490   -0.018    0.037
##     Zgcse   (.p3.)    0.095    0.015    6.143    0.000    0.064    0.125
##     Zhqual  (.p4.)    0.029    0.014    2.076    0.038    0.002    0.056
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.015    0.006    2.582    0.010    0.004    0.027
##     Zgcse            -0.031    0.006   -4.947    0.000   -0.043   -0.019
##     Zhqual           -0.023    0.008   -2.923    0.003   -0.038   -0.008
##   SESscore ~~                                                           
##     Zgcse             0.459    0.013   35.254    0.000    0.434    0.485
##     Zhqual            0.353    0.015   23.236    0.000    0.323    0.382
##   Zgcse ~~                                                              
##     Zhqual            0.589    0.018   33.332    0.000    0.554    0.623
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zwellb  (.16.)   -0.130    0.015   -8.815    0.000   -0.158   -0.101
##     sex1              0.469    0.006   75.700    0.000    0.457    0.481
##     SESscor          -0.035    0.012   -3.038    0.002   -0.058   -0.013
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
##     Zhqual           -0.126    0.016   -7.960    0.000   -0.158   -0.095
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zwellb            0.965    0.022   43.523    0.000    0.921    1.008
##     sex1              0.249    0.004   56.978    0.000    0.240    0.258
##     SESscore          0.874    0.015   56.405    0.000    0.844    0.904
##     Zgcse             1.000    0.018   56.978    0.000    0.965    1.034
##     Zhqual            1.033    0.024   43.186    0.000    0.986    1.080
## 
## R-Square:
##                    Estimate
##     Zwellb            0.033
## 
## 
## Group 2 [1]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zwellb ~                                                              
##     sex1    (.p1.)    0.289    0.023   12.376    0.000    0.243    0.335
##     SESscor (.p2.)    0.010    0.014    0.690    0.490   -0.018    0.037
##     Zgcse   (.p3.)    0.095    0.015    6.143    0.000    0.064    0.125
##     Zhqual  (.p4.)    0.029    0.014    2.076    0.038    0.002    0.056
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.430    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     Zhqual           -0.021    0.008   -2.602    0.009   -0.036   -0.005
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.433    0.000    0.422    0.473
##     Zhqual            0.342    0.015   22.278    0.000    0.312    0.372
##   Zgcse ~~                                                              
##     Zhqual            0.565    0.018   31.554    0.000    0.530    0.600
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zwellb  (.16.)   -0.130    0.015   -8.815    0.000   -0.158   -0.101
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscor          -0.034    0.012   -2.929    0.003   -0.057   -0.011
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
##     Zhqual           -0.121    0.016   -7.520    0.000   -0.153   -0.090
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zwellb            0.970    0.022   43.314    0.000    0.926    1.014
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.317    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     Zhqual            1.040    0.024   42.571    0.000    0.992    1.087
## 
## R-Square:
##                    Estimate
##     Zwellb            0.033
lavTestLRT(multi.wellb.free, multi.wellb.cons)
## 
## Chi-Squared Difference Test
## 
##                  Df    AIC    BIC Chisq Chisq diff RMSEA Df diff Pr(>Chisq)
## multi.wellb.free  0 126086 126385 0.000                                    
## multi.wellb.cons  5 126079 126341 2.986      2.986     0       5     0.7022
model3.anx <- 'Zanx ~ sex1 + SESscore + Zgcse + Zhqual'
multi.anx.free <- sem(model3.anx, data = df, group = "random", missing = "fiml", fixed.x = FALSE)
summary(multi.anx.free, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 27 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        40
## 
##   Number of observations per group:                   
##     0                                             6493
##     1                                             6488
##   Number of missing patterns per group:               
##     0                                                8
##     1                                                8
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
##   Test statistic for each group:
##     0                                            0.000
##     1                                            0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                               190.721
##   Degrees of freedom                                 8
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -62020.762
##   Loglikelihood unrestricted model (H1)     -62020.762
##                                                       
##   Akaike (AIC)                              124121.524
##   Bayesian (BIC)                            124420.373
##   Sample-size adjusted Bayesian (SABIC)     124293.257
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## 
## Group 1 [0]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zanx ~                                                                
##     sex1             -0.339    0.035   -9.644    0.000   -0.408   -0.270
##     SESscore          0.006    0.021    0.285    0.776   -0.036    0.048
##     Zgcse            -0.060    0.024   -2.535    0.011   -0.106   -0.014
##     Zhqual            0.008    0.022    0.368    0.713   -0.036    0.052
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.015    0.006    2.580    0.010    0.004    0.026
##     Zgcse            -0.031    0.006   -4.947    0.000   -0.043   -0.019
##     Zhqual           -0.023    0.008   -2.921    0.003   -0.038   -0.008
##   SESscore ~~                                                           
##     Zgcse             0.459    0.013   35.254    0.000    0.434    0.485
##     Zhqual            0.353    0.015   23.231    0.000    0.323    0.382
##   Zgcse ~~                                                              
##     Zhqual            0.589    0.018   33.329    0.000    0.554    0.623
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zanx              0.136    0.022    6.260    0.000    0.094    0.179
##     sex1              0.469    0.006   75.700    0.000    0.457    0.481
##     SESscore         -0.035    0.012   -3.037    0.002   -0.058   -0.013
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
##     Zhqual           -0.126    0.016   -7.949    0.000   -0.157   -0.095
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zanx              0.971    0.024   41.237    0.000    0.925    1.017
##     sex1              0.249    0.004   56.978    0.000    0.240    0.258
##     SESscore          0.874    0.015   56.405    0.000    0.844    0.904
##     Zgcse             1.000    0.018   56.978    0.000    0.965    1.034
##     Zhqual            1.033    0.024   43.188    0.000    0.986    1.080
## 
## R-Square:
##                    Estimate
##     Zanx              0.030
## 
## 
## Group 2 [1]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zanx ~                                                                
##     sex1             -0.334    0.035   -9.542    0.000   -0.402   -0.265
##     SESscore         -0.003    0.021   -0.161    0.872   -0.044    0.038
##     Zgcse            -0.003    0.023   -0.145    0.884   -0.048    0.041
##     Zhqual           -0.010    0.021   -0.479    0.632   -0.051    0.031
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.429    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     Zhqual           -0.021    0.008   -2.604    0.009   -0.036   -0.005
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.432    0.000    0.422    0.473
##     Zhqual            0.342    0.015   22.274    0.000    0.312    0.372
##   Zgcse ~~                                                              
##     Zhqual            0.565    0.018   31.550    0.000    0.530    0.600
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zanx              0.124    0.022    5.753    0.000    0.082    0.167
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.034    0.012   -2.928    0.003   -0.057   -0.011
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
##     Zhqual           -0.121    0.016   -7.515    0.000   -0.153   -0.089
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zanx              0.973    0.024   41.406    0.000    0.927    1.020
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.318    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     Zhqual            1.039    0.024   42.573    0.000    0.992    1.087
## 
## R-Square:
##                    Estimate
##     Zanx              0.028
multi.anx.cons <- sem(model3.anx, data = df, group = "random", group.equal = c("intercepts", "regressions"), missing = "fiml", fixed.x = FALSE)
summary(multi.anx.cons, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 31 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        40
##   Number of equality constraints                     5
## 
##   Number of observations per group:                   
##     0                                             6493
##     1                                             6488
##   Number of missing patterns per group:               
##     0                                                8
##     1                                                8
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 3.246
##   Degrees of freedom                                 5
##   P-value (Chi-square)                           0.662
##   Test statistic for each group:
##     0                                            1.663
##     1                                            1.583
## 
## Model Test Baseline Model:
## 
##   Test statistic                               190.721
##   Degrees of freedom                                 8
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.015
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.015
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -62022.385
##   Loglikelihood unrestricted model (H1)     -62020.762
##                                                       
##   Akaike (AIC)                              124114.770
##   Bayesian (BIC)                            124376.263
##   Sample-size adjusted Bayesian (SABIC)     124265.037
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.014
##   P-value H_0: RMSEA <= 0.050                    1.000
##   P-value H_0: RMSEA >= 0.080                    0.000
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.020
##   P-value H_0: Robust RMSEA <= 0.050             1.000
##   P-value H_0: Robust RMSEA >= 0.080             0.000
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.005
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## 
## Group 1 [0]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zanx ~                                                                
##     sex1    (.p1.)   -0.335    0.025  -13.525    0.000   -0.384   -0.287
##     SESscor (.p2.)    0.001    0.015    0.074    0.941   -0.028    0.030
##     Zgcse   (.p3.)   -0.031    0.016   -1.872    0.061   -0.063    0.001
##     Zhqual  (.p4.)   -0.002    0.015   -0.105    0.917   -0.032    0.029
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.015    0.006    2.581    0.010    0.004    0.026
##     Zgcse            -0.031    0.006   -4.947    0.000   -0.043   -0.019
##     Zhqual           -0.023    0.008   -2.922    0.003   -0.038   -0.008
##   SESscore ~~                                                           
##     Zgcse             0.459    0.013   35.254    0.000    0.434    0.485
##     Zhqual            0.353    0.015   23.232    0.000    0.323    0.382
##   Zgcse ~~                                                              
##     Zhqual            0.589    0.018   33.329    0.000    0.554    0.623
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zanx    (.16.)    0.130    0.015    8.452    0.000    0.099    0.160
##     sex1              0.469    0.006   75.700    0.000    0.457    0.481
##     SESscor          -0.035    0.012   -3.037    0.002   -0.058   -0.013
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
##     Zhqual           -0.126    0.016   -7.950    0.000   -0.157   -0.095
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zanx              0.971    0.024   41.227    0.000    0.925    1.018
##     sex1              0.249    0.004   56.978    0.000    0.240    0.258
##     SESscore          0.874    0.015   56.405    0.000    0.844    0.904
##     Zgcse             1.000    0.018   56.978    0.000    0.965    1.034
##     Zhqual            1.033    0.024   43.188    0.000    0.986    1.080
## 
## R-Square:
##                    Estimate
##     Zanx              0.028
## 
## 
## Group 2 [1]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zanx ~                                                                
##     sex1    (.p1.)   -0.335    0.025  -13.525    0.000   -0.384   -0.287
##     SESscor (.p2.)    0.001    0.015    0.074    0.941   -0.028    0.030
##     Zgcse   (.p3.)   -0.031    0.016   -1.872    0.061   -0.063    0.001
##     Zhqual  (.p4.)   -0.002    0.015   -0.105    0.917   -0.032    0.029
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.429    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     Zhqual           -0.021    0.008   -2.604    0.009   -0.036   -0.005
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.433    0.000    0.422    0.473
##     Zhqual            0.342    0.015   22.274    0.000    0.312    0.372
##   Zgcse ~~                                                              
##     Zhqual            0.565    0.018   31.549    0.000    0.530    0.600
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zanx    (.16.)    0.130    0.015    8.452    0.000    0.099    0.160
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscor          -0.034    0.012   -2.928    0.003   -0.057   -0.011
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
##     Zhqual           -0.121    0.016   -7.515    0.000   -0.153   -0.089
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zanx              0.974    0.024   41.397    0.000    0.928    1.020
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.318    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     Zhqual            1.039    0.024   42.574    0.000    0.992    1.087
## 
## R-Square:
##                    Estimate
##     Zanx              0.028
lavTestLRT(multi.anx.free, multi.anx.cons)
## 
## Chi-Squared Difference Test
## 
##                Df    AIC    BIC  Chisq Chisq diff RMSEA Df diff Pr(>Chisq)
## multi.anx.free  0 124122 124420 0.0000                                    
## multi.anx.cons  5 124115 124376 3.2462     3.2462     0       5     0.6621
model3.sdq <- 'Zsdq ~ sex1 + SESscore + Zgcse + Zhqual'
multi.sdq.free <- sem(model3.sdq, data = df, group = "random", missing = "fiml", fixed.x = FALSE)
summary(multi.sdq.free, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 23 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        40
## 
##   Number of observations per group:                   
##     0                                             6493
##     1                                             6488
##   Number of missing patterns per group:               
##     0                                                7
##     1                                                8
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
##   Test statistic for each group:
##     0                                            0.000
##     1                                            0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                               484.210
##   Degrees of freedom                                 8
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -62894.234
##   Loglikelihood unrestricted model (H1)     -62894.234
##                                                       
##   Akaike (AIC)                              125868.468
##   Bayesian (BIC)                            126167.318
##   Sample-size adjusted Bayesian (SABIC)     126040.202
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## 
## Group 1 [0]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zsdq ~                                                                
##     sex1             -0.171    0.032   -5.255    0.000   -0.234   -0.107
##     SESscore         -0.038    0.020   -1.897    0.058   -0.076    0.001
##     Zgcse            -0.175    0.022   -8.064    0.000   -0.217   -0.132
##     Zhqual           -0.070    0.020   -3.559    0.000   -0.108   -0.031
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.015    0.006    2.586    0.010    0.004    0.027
##     Zgcse            -0.031    0.006   -4.947    0.000   -0.043   -0.019
##     Zhqual           -0.023    0.008   -2.936    0.003   -0.039   -0.008
##   SESscore ~~                                                           
##     Zgcse             0.459    0.013   35.256    0.000    0.434    0.485
##     Zhqual            0.353    0.015   23.239    0.000    0.323    0.383
##   Zgcse ~~                                                              
##     Zhqual            0.589    0.018   33.344    0.000    0.554    0.623
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsdq              0.101    0.020    4.961    0.000    0.061    0.142
##     sex1              0.469    0.006   75.700    0.000    0.457    0.481
##     SESscore         -0.036    0.012   -3.040    0.002   -0.058   -0.013
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
##     Zhqual           -0.127    0.016   -7.978    0.000   -0.158   -0.096
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsdq              0.939    0.022   43.547    0.000    0.896    0.981
##     sex1              0.249    0.004   56.978    0.000    0.240    0.258
##     SESscore          0.874    0.015   56.402    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.978    0.000    0.965    1.034
##     Zhqual            1.034    0.024   43.179    0.000    0.987    1.080
## 
## R-Square:
##                    Estimate
##     Zsdq              0.064
## 
## 
## Group 2 [1]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zsdq ~                                                                
##     sex1             -0.197    0.033   -6.046    0.000   -0.260   -0.133
##     SESscore         -0.010    0.020   -0.489    0.625   -0.048    0.029
##     Zgcse            -0.163    0.021   -7.685    0.000   -0.205   -0.122
##     Zhqual           -0.105    0.019   -5.520    0.000   -0.143   -0.068
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.430    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     Zhqual           -0.021    0.008   -2.594    0.009   -0.036   -0.005
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.433    0.000    0.422    0.473
##     Zhqual            0.342    0.015   22.287    0.000    0.312    0.372
##   Zgcse ~~                                                              
##     Zhqual            0.565    0.018   31.574    0.000    0.530    0.601
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsdq              0.108    0.020    5.268    0.000    0.068    0.148
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.034    0.012   -2.929    0.003   -0.057   -0.011
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
##     Zhqual           -0.121    0.016   -7.530    0.000   -0.153   -0.090
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsdq              0.936    0.022   43.319    0.000    0.894    0.979
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.317    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     Zhqual            1.040    0.024   42.565    0.000    0.992    1.088
## 
## R-Square:
##                    Estimate
##     Zsdq              0.067
multi.sdq.cons <- sem(model3.sdq, data = df, group = "random", group.equal = c("intercepts", "regressions"), missing = "fiml", fixed.x = FALSE)
summary(multi.sdq.cons, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 28 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        40
##   Number of equality constraints                     5
## 
##   Number of observations per group:                   
##     0                                             6493
##     1                                             6488
##   Number of missing patterns per group:               
##     0                                                7
##     1                                                8
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 2.659
##   Degrees of freedom                                 5
##   P-value (Chi-square)                           0.752
##   Test statistic for each group:
##     0                                            1.354
##     1                                            1.305
## 
## Model Test Baseline Model:
## 
##   Test statistic                               484.210
##   Degrees of freedom                                 8
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.008
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.008
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -62895.563
##   Loglikelihood unrestricted model (H1)     -62894.234
##                                                       
##   Akaike (AIC)                              125861.127
##   Bayesian (BIC)                            126122.620
##   Sample-size adjusted Bayesian (SABIC)     126011.394
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.012
##   P-value H_0: RMSEA <= 0.050                    1.000
##   P-value H_0: RMSEA >= 0.080                    0.000
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.016
##   P-value H_0: Robust RMSEA <= 0.050             1.000
##   P-value H_0: Robust RMSEA >= 0.080             0.000
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.003
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## 
## Group 1 [0]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zsdq ~                                                                
##     sex1    (.p1.)   -0.184    0.023   -7.987    0.000   -0.229   -0.139
##     SESscor (.p2.)   -0.023    0.014   -1.682    0.092   -0.051    0.004
##     Zgcse   (.p3.)   -0.169    0.015  -11.134    0.000   -0.199   -0.139
##     Zhqual  (.p4.)   -0.088    0.014   -6.436    0.000   -0.115   -0.061
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.015    0.006    2.584    0.010    0.004    0.027
##     Zgcse            -0.031    0.006   -4.947    0.000   -0.043   -0.019
##     Zhqual           -0.023    0.008   -2.941    0.003   -0.039   -0.008
##   SESscore ~~                                                           
##     Zgcse             0.459    0.013   35.255    0.000    0.434    0.485
##     Zhqual            0.353    0.015   23.242    0.000    0.323    0.383
##   Zgcse ~~                                                              
##     Zhqual            0.589    0.018   33.349    0.000    0.554    0.624
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsdq    (.16.)    0.105    0.014    7.229    0.000    0.076    0.133
##     sex1              0.469    0.006   75.700    0.000    0.457    0.481
##     SESscor          -0.036    0.012   -3.039    0.002   -0.058   -0.013
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
##     Zhqual           -0.127    0.016   -7.986    0.000   -0.158   -0.096
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsdq              0.939    0.022   43.539    0.000    0.897    0.981
##     sex1              0.249    0.004   56.978    0.000    0.240    0.258
##     SESscore          0.874    0.015   56.403    0.000    0.844    0.904
##     Zgcse             1.000    0.018   56.978    0.000    0.965    1.034
##     Zhqual            1.034    0.024   43.177    0.000    0.987    1.081
## 
## R-Square:
##                    Estimate
##     Zsdq              0.065
## 
## 
## Group 2 [1]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zsdq ~                                                                
##     sex1    (.p1.)   -0.184    0.023   -7.987    0.000   -0.229   -0.139
##     SESscor (.p2.)   -0.023    0.014   -1.682    0.092   -0.051    0.004
##     Zgcse   (.p3.)   -0.169    0.015  -11.134    0.000   -0.199   -0.139
##     Zhqual  (.p4.)   -0.088    0.014   -6.436    0.000   -0.115   -0.061
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.431    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     Zhqual           -0.021    0.008   -2.595    0.009   -0.036   -0.005
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.434    0.000    0.422    0.473
##     Zhqual            0.342    0.015   22.281    0.000    0.312    0.372
##   Zgcse ~~                                                              
##     Zhqual            0.565    0.018   31.569    0.000    0.530    0.600
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsdq    (.16.)    0.105    0.014    7.229    0.000    0.076    0.133
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscor          -0.034    0.012   -2.929    0.003   -0.057   -0.011
##     Zgcse            -0.000    0.012   -0.000    1.000   -0.024    0.024
##     Zhqual           -0.121    0.016   -7.527    0.000   -0.153   -0.090
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zsdq              0.937    0.022   43.313    0.000    0.894    0.979
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.317    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     Zhqual            1.040    0.024   42.567    0.000    0.992    1.088
## 
## R-Square:
##                    Estimate
##     Zsdq              0.065
lavTestLRT(multi.sdq.free, multi.sdq.cons)
## 
## Chi-Squared Difference Test
## 
##                Df    AIC    BIC  Chisq Chisq diff RMSEA Df diff Pr(>Chisq)
## multi.sdq.free  0 125868 126167 0.0000                                    
## multi.sdq.cons  5 125861 126123 2.6586     2.6586     0       5     0.7524
model3.alc <- 'Zalc ~ sex1 + SESscore + Zgcse + Zhqual'
multi.alc.free <- sem(model3.alc, data = df, group = "random", missing = "fiml", fixed.x = FALSE)
summary(multi.alc.free, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 23 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        40
## 
##   Number of observations per group:                   
##     0                                             6493
##     1                                             6488
##   Number of missing patterns per group:               
##     0                                                8
##     1                                                8
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 0.000
##   Degrees of freedom                                 0
##   Test statistic for each group:
##     0                                            0.000
##     1                                            0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                               170.978
##   Degrees of freedom                                 8
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000
##   Tucker-Lewis Index (TLI)                       1.000
##                                                       
##   Robust Comparative Fit Index (CFI)             1.000
##   Robust Tucker-Lewis Index (TLI)                1.000
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -61304.137
##   Loglikelihood unrestricted model (H1)     -61304.137
##                                                       
##   Akaike (AIC)                              122688.274
##   Bayesian (BIC)                            122987.123
##   Sample-size adjusted Bayesian (SABIC)     122860.007
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: RMSEA <= 0.050                       NA
##   P-value H_0: RMSEA >= 0.080                       NA
##                                                       
##   Robust RMSEA                                   0.000
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.000
##   P-value H_0: Robust RMSEA <= 0.050                NA
##   P-value H_0: Robust RMSEA >= 0.080                NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## 
## Group 1 [0]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zalc ~                                                                
##     sex1              0.256    0.036    7.045    0.000    0.185    0.327
##     SESscore          0.081    0.022    3.667    0.000    0.038    0.125
##     Zgcse             0.024    0.024    0.995    0.320   -0.023    0.072
##     Zhqual            0.057    0.023    2.484    0.013    0.012    0.103
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.015    0.006    2.581    0.010    0.004    0.026
##     Zgcse            -0.031    0.006   -4.947    0.000   -0.043   -0.019
##     Zhqual           -0.023    0.008   -2.908    0.004   -0.038   -0.007
##   SESscore ~~                                                           
##     Zgcse             0.459    0.013   35.252    0.000    0.434    0.485
##     Zhqual            0.353    0.015   23.242    0.000    0.323    0.383
##   Zgcse ~~                                                              
##     Zhqual            0.589    0.018   33.330    0.000    0.554    0.623
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zalc             -0.111    0.023   -4.862    0.000   -0.155   -0.066
##     sex1              0.469    0.006   75.700    0.000    0.457    0.481
##     SESscore         -0.036    0.012   -3.039    0.002   -0.058   -0.013
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
##     Zhqual           -0.126    0.016   -7.946    0.000   -0.157   -0.095
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zalc              0.968    0.024   39.670    0.000    0.921    1.016
##     sex1              0.249    0.004   56.978    0.000    0.240    0.258
##     SESscore          0.874    0.015   56.407    0.000    0.844    0.904
##     Zgcse             1.000    0.018   56.978    0.000    0.965    1.034
##     Zhqual            1.033    0.024   43.190    0.000    0.986    1.080
## 
## R-Square:
##                    Estimate
##     Zalc              0.032
## 
## 
## Group 2 [1]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zalc ~                                                                
##     sex1              0.224    0.036    6.159    0.000    0.153    0.295
##     SESscore          0.109    0.022    5.007    0.000    0.067    0.152
##     Zgcse            -0.033    0.024   -1.386    0.166   -0.080    0.014
##     Zhqual            0.027    0.022    1.206    0.228   -0.017    0.071
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.426    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     Zhqual           -0.021    0.008   -2.597    0.009   -0.036   -0.005
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.438    0.000    0.422    0.473
##     Zhqual            0.342    0.015   22.280    0.000    0.312    0.372
##   Zgcse ~~                                                              
##     Zhqual            0.565    0.018   31.542    0.000    0.530    0.600
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zalc             -0.085    0.023   -3.736    0.000   -0.129   -0.040
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscore         -0.034    0.012   -2.922    0.003   -0.057   -0.011
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
##     Zhqual           -0.121    0.016   -7.507    0.000   -0.152   -0.089
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zalc              0.977    0.025   39.799    0.000    0.929    1.025
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.313    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     Zhqual            1.039    0.024   42.578    0.000    0.991    1.087
## 
## R-Square:
##                    Estimate
##     Zalc              0.023
multi.alc.cons <- sem(model3.alc, data = df, group = "random", group.equal = c("intercepts", "regressions"), missing = "fiml", fixed.x = FALSE)
summary(multi.alc.cons, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 33 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of model parameters                        40
##   Number of equality constraints                     5
## 
##   Number of observations per group:                   
##     0                                             6493
##     1                                             6488
##   Number of missing patterns per group:               
##     0                                                8
##     1                                                8
## 
## Model Test User Model:
##                                                       
##   Test statistic                                 7.234
##   Degrees of freedom                                 5
##   P-value (Chi-square)                           0.204
##   Test statistic for each group:
##     0                                            3.674
##     1                                            3.559
## 
## Model Test Baseline Model:
## 
##   Test statistic                               170.978
##   Degrees of freedom                                 8
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.986
##   Tucker-Lewis Index (TLI)                       0.978
##                                                       
##   Robust Comparative Fit Index (CFI)             0.983
##   Robust Tucker-Lewis Index (TLI)                0.972
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -61307.754
##   Loglikelihood unrestricted model (H1)     -61304.137
##                                                       
##   Akaike (AIC)                              122685.507
##   Bayesian (BIC)                            122947.001
##   Sample-size adjusted Bayesian (SABIC)     122835.774
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.008
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.020
##   P-value H_0: RMSEA <= 0.050                    1.000
##   P-value H_0: RMSEA >= 0.080                    0.000
##                                                       
##   Robust RMSEA                                   0.014
##   90 Percent confidence interval - lower         0.000
##   90 Percent confidence interval - upper         0.032
##   P-value H_0: Robust RMSEA <= 0.050             1.000
##   P-value H_0: Robust RMSEA >= 0.080             0.000
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.009
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Observed
##   Observed information based on                Hessian
## 
## 
## Group 1 [0]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zalc ~                                                                
##     sex1    (.p1.)    0.239    0.026    9.304    0.000    0.189    0.290
##     SESscor (.p2.)    0.096    0.016    6.183    0.000    0.066    0.127
##     Zgcse   (.p3.)   -0.005    0.017   -0.283    0.777   -0.038    0.029
##     Zhqual  (.p4.)    0.042    0.016    2.594    0.009    0.010    0.073
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.015    0.006    2.581    0.010    0.004    0.026
##     Zgcse            -0.031    0.006   -4.947    0.000   -0.043   -0.019
##     Zhqual           -0.023    0.008   -2.911    0.004   -0.038   -0.007
##   SESscore ~~                                                           
##     Zgcse             0.459    0.013   35.253    0.000    0.434    0.485
##     Zhqual            0.353    0.015   23.241    0.000    0.323    0.383
##   Zgcse ~~                                                              
##     Zhqual            0.589    0.018   33.332    0.000    0.554    0.623
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zalc    (.16.)   -0.097    0.016   -6.042    0.000   -0.129   -0.066
##     sex1              0.469    0.006   75.700    0.000    0.457    0.481
##     SESscor          -0.036    0.012   -3.040    0.002   -0.058   -0.013
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
##     Zhqual           -0.126    0.016   -7.949    0.000   -0.157   -0.095
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zalc              0.970    0.024   39.649    0.000    0.922    1.018
##     sex1              0.249    0.004   56.978    0.000    0.240    0.258
##     SESscore          0.874    0.015   56.407    0.000    0.844    0.904
##     Zgcse             1.000    0.018   56.978    0.000    0.965    1.034
##     Zhqual            1.033    0.024   43.187    0.000    0.986    1.080
## 
## R-Square:
##                    Estimate
##     Zalc              0.027
## 
## 
## Group 2 [1]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   Zalc ~                                                                
##     sex1    (.p1.)    0.239    0.026    9.304    0.000    0.189    0.290
##     SESscor (.p2.)    0.096    0.016    6.183    0.000    0.066    0.127
##     Zgcse   (.p3.)   -0.005    0.017   -0.283    0.777   -0.038    0.029
##     Zhqual  (.p4.)    0.042    0.016    2.594    0.009    0.010    0.073
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   sex1 ~~                                                               
##     SESscore          0.014    0.006    2.426    0.015    0.003    0.026
##     Zgcse            -0.026    0.006   -4.232    0.000   -0.038   -0.014
##     Zhqual           -0.021    0.008   -2.594    0.009   -0.036   -0.005
##   SESscore ~~                                                           
##     Zgcse             0.447    0.013   34.437    0.000    0.422    0.473
##     Zhqual            0.342    0.015   22.277    0.000    0.312    0.372
##   Zgcse ~~                                                              
##     Zhqual            0.565    0.018   31.536    0.000    0.529    0.600
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zalc    (.16.)   -0.097    0.016   -6.042    0.000   -0.129   -0.066
##     sex1              0.474    0.006   76.503    0.000    0.462    0.486
##     SESscor          -0.034    0.012   -2.922    0.003   -0.057   -0.011
##     Zgcse             0.000    0.012    0.000    1.000   -0.024    0.024
##     Zhqual           -0.121    0.016   -7.500    0.000   -0.152   -0.089
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .Zalc              0.978    0.025   39.776    0.000    0.930    1.026
##     sex1              0.249    0.004   56.956    0.000    0.241    0.258
##     SESscore          0.875    0.016   56.315    0.000    0.844    0.905
##     Zgcse             1.000    0.018   56.956    0.000    0.965    1.034
##     Zhqual            1.039    0.024   42.584    0.000    0.991    1.087
## 
## R-Square:
##                    Estimate
##     Zalc              0.026
lavTestLRT(multi.alc.free, multi.alc.cons)
## 
## Chi-Squared Difference Test
## 
##                Df    AIC    BIC  Chisq Chisq diff     RMSEA Df diff Pr(>Chisq)
## multi.alc.free  0 122688 122987 0.0000                                        
## multi.alc.cons  5 122686 122947 7.2337     7.2337 0.0082964       5     0.2038

#Logistic and multinomial multi-group regression models

model3.benf <- 'u1cbenf11 ~ sex1 + SESscore + Zgcse + Zhqual'
multi.benf.free <- sem(model3.benf, data = df, group = "random", ordered = c("u1cbenf11"), missing = "listwise")
summary(multi.benf.free, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 41 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                        10
## 
##   Number of observations per group:               Used       Total
##     0                                             3650        6493
##     1                                             3628        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   Test statistic for each group:
##     0                                            0.000       0.000
##     1                                            0.000       0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## 
## Group 1 [0]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   u1cbenf11 ~                                                           
##     sex1             -0.173    0.086   -2.011    0.044   -0.342   -0.004
##     SESscore         -0.152    0.049   -3.086    0.002   -0.248   -0.055
##     Zgcse            -0.151    0.045   -3.329    0.001   -0.240   -0.062
##     Zhqual           -0.142    0.038   -3.771    0.000   -0.216   -0.068
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .u1cbenf11         0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     u1cbenf11|t1      1.747    0.054   32.236    0.000    1.641    1.854
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .u1cbenf11         1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     u1cbenf11         1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     u1cbenf11         0.111
## 
## 
## Group 2 [1]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   u1cbenf11 ~                                                           
##     sex1             -0.178    0.080   -2.235    0.025   -0.335   -0.022
##     SESscore         -0.119    0.044   -2.683    0.007   -0.206   -0.032
##     Zgcse            -0.107    0.048   -2.224    0.026   -0.201   -0.013
##     Zhqual           -0.204    0.037   -5.571    0.000   -0.275   -0.132
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .u1cbenf11         0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     u1cbenf11|t1      1.688    0.050   33.832    0.000    1.590    1.785
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .u1cbenf11         1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     u1cbenf11         1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     u1cbenf11         0.106
multi.benf.cons <- sem(model3.benf, data = df, group = "random", group.equal = c("intercepts", "regressions"), ordered = c("u1cbenf11"), missing = "listwise")
summary(multi.benf.cons, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 29 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                        11
##   Number of equality constraints                     5
## 
##   Number of observations per group:               Used       Total
##     0                                             3650        6493
##     1                                             3628        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 2.202       2.328
##   Degrees of freedom                                 4           4
##   P-value (Chi-square)                           0.699       0.676
##   Scaling correction factor                                  1.072
##   Shift parameter                                            0.274
##     simple second-order correction                                
##   Test statistic for each group:
##     0                                            1.091       1.155
##     1                                            1.111       1.173
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.019       0.019
##   P-value H_0: RMSEA <= 0.050                    1.000       1.000
##   P-value H_0: RMSEA >= 0.080                    0.000       0.000
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## 
## Group 1 [0]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   u1cbenf11 ~                                                           
##     sex1    (.p1.)   -0.179    0.060   -3.004    0.003   -0.295   -0.062
##     SESscor (.p2.)   -0.136    0.034   -4.025    0.000   -0.203   -0.070
##     Zgcse   (.p3.)   -0.132    0.034   -3.940    0.000   -0.198   -0.067
##     Zhqual  (.p4.)   -0.176    0.027   -6.556    0.000   -0.229   -0.123
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .u1cbenf11         0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     u1c11|1 (.p5.)    1.744    0.054   32.390    0.000    1.638    1.849
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .u1cbenf11         1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     u1cbenf11         1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     u1cbenf11         0.112
## 
## 
## Group 2 [1]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   u1cbenf11 ~                                                           
##     sex1    (.p1.)   -0.179    0.060   -3.004    0.003   -0.295   -0.062
##     SESscor (.p2.)   -0.136    0.034   -4.025    0.000   -0.203   -0.070
##     Zgcse   (.p3.)   -0.132    0.034   -3.940    0.000   -0.198   -0.067
##     Zhqual  (.p4.)   -0.176    0.027   -6.556    0.000   -0.229   -0.123
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .u1cbenf11         0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     u1c11|1 (.p5.)    1.744    0.054   32.390    0.000    1.638    1.849
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .u1cbenf11         1.063                               1.063    1.063
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     u1cbenf11         0.970    0.041   23.716    0.000    0.890    1.050
## 
## R-Square:
##                    Estimate
##     u1cbenf11         0.104
lavTestLRT(multi.benf.free, multi.benf.cons)
## 
## Scaled Chi-Squared Difference Test (method = "satorra.2000")
## 
## lavaan NOTE:
##     The "Chisq" column contains standard test statistics, not the
##     robust test that should be reported per model. A robust difference
##     test is a function of two standard (not robust) statistics.
##  
##                 Df AIC BIC Chisq Chisq diff Df diff Pr(>Chisq)
## multi.benf.free  0         0.000                              
## multi.benf.cons  4         2.202     2.3281       4     0.6757
model3.status_bin <- 'status_bin ~ sex1 + SESscore + Zgcse + Zhqual'
multi.status_bin.free <- sem(model3.status_bin, data = df, group = "random", ordered = c("status_bin"), missing = "listwise")
summary(multi.status_bin.free, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 30 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                        10
## 
##   Number of observations per group:               Used       Total
##     0                                             3653        6493
##     1                                             3635        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   Test statistic for each group:
##     0                                            0.000       0.000
##     1                                            0.000       0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## 
## Group 1 [0]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   status_bin ~                                                          
##     sex1             -0.047    0.059   -0.792    0.428   -0.162    0.069
##     SESscore         -0.057    0.035   -1.608    0.108   -0.126    0.012
##     Zgcse            -0.038    0.038   -0.991    0.322   -0.113    0.037
##     Zhqual            0.056    0.033    1.686    0.092   -0.009    0.120
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .status_bin        0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     status_bin|t1    -1.317    0.037  -35.756    0.000   -1.389   -1.245
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .status_bin        1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     status_bin        1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     status_bin        0.005
## 
## 
## Group 2 [1]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   status_bin ~                                                          
##     sex1             -0.008    0.058   -0.142    0.887   -0.122    0.105
##     SESscore         -0.069    0.035   -1.984    0.047   -0.138   -0.001
##     Zgcse            -0.039    0.037   -1.051    0.293   -0.112    0.034
##     Zhqual            0.100    0.033    3.030    0.002    0.035    0.165
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .status_bin        0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     status_bin|t1    -1.284    0.037  -34.269    0.000   -1.357   -1.210
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .status_bin        1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     status_bin        1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     status_bin        0.009
multi.status_bin.cons <- sem(model3.status_bin, data = df, group = "random", group.equal = c("intercepts", "regressions"), ordered = c("status_bin"), missing = "listwise")
summary(multi.status_bin.cons, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 26 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                        11
##   Number of equality constraints                     5
## 
##   Number of observations per group:               Used       Total
##     0                                             3653        6493
##     1                                             3635        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 1.268       1.505
##   Degrees of freedom                                 4           4
##   P-value (Chi-square)                           0.867       0.826
##   Scaling correction factor                                  1.075
##   Shift parameter                                            0.325
##     simple second-order correction                                
##   Test statistic for each group:
##     0                                            0.622       0.741
##     1                                            0.646       0.763
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.013       0.015
##   P-value H_0: RMSEA <= 0.050                    1.000       1.000
##   P-value H_0: RMSEA >= 0.080                    0.000       0.000
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## 
## Group 1 [0]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   status_bin ~                                                          
##     sex1    (.p1.)   -0.028    0.042   -0.663    0.508   -0.109    0.054
##     SESscor (.p2.)   -0.064    0.025   -2.538    0.011   -0.113   -0.015
##     Zgcse   (.p3.)   -0.039    0.027   -1.444    0.149   -0.092    0.014
##     Zhqual  (.p4.)    0.078    0.024    3.327    0.001    0.032    0.125
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .status_bin        0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     stts_|1 (.p5.)   -1.315    0.037  -35.448    0.000   -1.388   -1.243
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .status_bin        1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     status_bin        1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     status_bin        0.007
## 
## 
## Group 2 [1]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   status_bin ~                                                          
##     sex1    (.p1.)   -0.028    0.042   -0.663    0.508   -0.109    0.054
##     SESscor (.p2.)   -0.064    0.025   -2.538    0.011   -0.113   -0.015
##     Zgcse   (.p3.)   -0.039    0.027   -1.444    0.149   -0.092    0.014
##     Zhqual  (.p4.)    0.078    0.024    3.327    0.001    0.032    0.125
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .status_bin        0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     stts_|1 (.p5.)   -1.315    0.037  -35.448    0.000   -1.388   -1.243
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .status_bin        1.047                               1.047    1.047
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     status_bin        0.977    0.040   24.263    0.000    0.898    1.056
## 
## R-Square:
##                    Estimate
##     status_bin        0.007
lavTestLRT(multi.status_bin.free, multi.status_bin.cons)
## 
## Scaled Chi-Squared Difference Test (method = "satorra.2000")
## 
## lavaan NOTE:
##     The "Chisq" column contains standard test statistics, not the
##     robust test that should be reported per model. A robust difference
##     test is a function of two standard (not robust) statistics.
##  
##                       Df AIC BIC  Chisq Chisq diff Df diff Pr(>Chisq)
## multi.status_bin.free  0         0.0000                              
## multi.status_bin.cons  4         1.2684     1.5047       4     0.8258
##first, create dummy variables for status again now in dataset with both twins that is used here for the multi-group analyses

#dummy code status variable
#specify status as factor, create  4 dummy variables for originally 5 categories (unemployed is always set as the reference category), and bind new variables to df
df$status1 = as.factor(df$status1)

st_working <- ifelse(df$status1 == '1', 1, 0)
st_studying <- ifelse(df$status1 == '2', 1, 0)
st_parent <- ifelse(df$status1 == '3', 1, 0)
st_gapyear <- ifelse(df$status1 == '4', 1, 0)

df_dummy = cbind(df, st_working, st_studying, st_parent, st_gapyear)

write.csv(df_dummy, '/Users/cgb538/Library/CloudStorage/GoogleDrive-alexandra.starr@york.ac.uk/My Drive/projects and papers/DevPsych_prediction grades adulthood/data/grades_adulth_prepared_bothtwins_dummy.csv', row.names = F, na = 'NA')



#employment status: working vs. unemployed
model3.st_working <- 'st_working ~ sex1 + SESscore + Zgcse + Zhqual'
multi.st_working.free <- sem(model3.st_working, data = df_dummy, group = "random", ordered = c("st_working"), missing = "listwise")
summary(multi.st_working.free, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 26 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                        10
## 
##   Number of observations per group:               Used       Total
##     0                                             3653        6493
##     1                                             3635        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   Test statistic for each group:
##     0                                            0.000       0.000
##     1                                            0.000       0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## 
## Group 1 [0]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_working ~                                                          
##     sex1             -0.046    0.045   -1.012    0.312   -0.134    0.043
##     SESscore         -0.104    0.027   -3.852    0.000   -0.156   -0.051
##     Zgcse            -0.129    0.029   -4.374    0.000   -0.187   -0.071
##     Zhqual           -0.381    0.025  -15.254    0.000   -0.430   -0.332
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_working        0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_working|t1    -0.132    0.028   -4.743    0.000   -0.186   -0.077
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_working        1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_working        1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_working        0.204
## 
## 
## Group 2 [1]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_working ~                                                          
##     sex1             -0.122    0.045   -2.720    0.007   -0.209   -0.034
##     SESscore         -0.141    0.026   -5.392    0.000   -0.192   -0.090
##     Zgcse            -0.112    0.029   -3.923    0.000   -0.168   -0.056
##     Zhqual           -0.361    0.025  -14.477    0.000   -0.410   -0.312
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_working        0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_working|t1    -0.123    0.028   -4.413    0.000   -0.178   -0.069
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_working        1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_working        1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_working        0.198
multi.st_working.cons <- sem(model3.st_working, data = df_dummy, group = "random", group.equal = c("intercepts", "regressions"), ordered = c("st_working"), missing = "listwise")
summary(multi.st_working.cons, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 28 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                        11
##   Number of equality constraints                     5
## 
##   Number of observations per group:               Used       Total
##     0                                             3653        6493
##     1                                             3635        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 2.880       2.796
##   Degrees of freedom                                 4           4
##   P-value (Chi-square)                           0.578       0.592
##   Scaling correction factor                                  1.189
##   Shift parameter                                            0.373
##     simple second-order correction                                
##   Test statistic for each group:
##     0                                            1.435       1.394
##     1                                            1.445       1.402
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.022       0.021
##   P-value H_0: RMSEA <= 0.050                    1.000       1.000
##   P-value H_0: RMSEA >= 0.080                    0.000       0.000
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## 
## Group 1 [0]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_working ~                                                          
##     sex1    (.p1.)   -0.084    0.032   -2.622    0.009   -0.147   -0.021
##     SESscor (.p2.)   -0.124    0.019   -6.380    0.000   -0.162   -0.086
##     Zgcse   (.p3.)   -0.122    0.021   -5.720    0.000   -0.163   -0.080
##     Zhqual  (.p4.)   -0.375    0.022  -17.050    0.000   -0.418   -0.332
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_working        0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_wr|1 (.p5.)   -0.129    0.020   -6.318    0.000   -0.169   -0.089
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_working        1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_working        1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_working        0.205
## 
## 
## Group 2 [1]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_working ~                                                          
##     sex1    (.p1.)   -0.084    0.032   -2.622    0.009   -0.147   -0.021
##     SESscor (.p2.)   -0.124    0.019   -6.380    0.000   -0.162   -0.086
##     Zgcse   (.p3.)   -0.122    0.021   -5.720    0.000   -0.163   -0.080
##     Zhqual  (.p4.)   -0.375    0.022  -17.050    0.000   -0.418   -0.332
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_working        0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_wr|1 (.p5.)   -0.129    0.020   -6.318    0.000   -0.169   -0.089
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_working        1.041                               1.041    1.041
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_working        0.980    0.068   14.357    0.000    0.846    1.114
## 
## R-Square:
##                    Estimate
##     st_working        0.196
lavTestLRT(multi.st_working.free, multi.st_working.cons)
## 
## Scaled Chi-Squared Difference Test (method = "satorra.2000")
## 
## lavaan NOTE:
##     The "Chisq" column contains standard test statistics, not the
##     robust test that should be reported per model. A robust difference
##     test is a function of two standard (not robust) statistics.
##  
##                       Df AIC BIC  Chisq Chisq diff Df diff Pr(>Chisq)
## multi.st_working.free  0         0.0000                              
## multi.st_working.cons  4         2.8802     2.7962       4     0.5925
#employment status: studying/apprenticeship vs. unemployed
model3.st_studying <- 'st_studying ~ sex1 + SESscore + Zgcse + Zhqual'
multi.st_studying.free <- sem(model3.st_studying, data = df_dummy, group = "random", ordered = c("st_studying"), missing = "listwise")
summary(multi.st_studying.free, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 23 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                        10
## 
##   Number of observations per group:               Used       Total
##     0                                             3653        6493
##     1                                             3635        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   Test statistic for each group:
##     0                                            0.000       0.000
##     1                                            0.000       0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## 
## Group 1 [0]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_studying ~                                                         
##     sex1              0.025    0.046    0.552    0.581   -0.065    0.116
##     SESscore          0.082    0.027    2.997    0.003    0.028    0.135
##     Zgcse             0.116    0.031    3.750    0.000    0.055    0.177
##     Zhqual            0.515    0.028   18.449    0.000    0.461    0.570
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_studying       0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_studying|t1    0.433    0.030   14.628    0.000    0.375    0.491
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_studying       1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_studying       1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_studying       0.274
## 
## 
## Group 2 [1]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_studying ~                                                         
##     sex1              0.137    0.046    2.983    0.003    0.047    0.227
##     SESscore          0.111    0.027    4.177    0.000    0.059    0.163
##     Zgcse             0.101    0.030    3.416    0.001    0.043    0.159
##     Zhqual            0.528    0.028   18.883    0.000    0.473    0.582
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_studying       0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_studying|t1    0.454    0.030   15.102    0.000    0.395    0.513
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_studying       1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_studying       1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_studying       0.286
multi.st_studying.cons <- sem(model3.st_studying, data = df_dummy, group = "random", group.equal = c("intercepts", "regressions"), ordered = c("st_studying"), missing = "listwise")
summary(multi.st_studying.cons, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 26 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                        11
##   Number of equality constraints                     5
## 
##   Number of observations per group:               Used       Total
##     0                                             3653        6493
##     1                                             3635        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 3.476       3.525
##   Degrees of freedom                                 4           4
##   P-value (Chi-square)                           0.482       0.474
##   Scaling correction factor                                  1.119
##   Shift parameter                                            0.419
##     simple second-order correction                                
##   Test statistic for each group:
##     0                                            1.827       1.842
##     1                                            1.649       1.683
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.024       0.024
##   P-value H_0: RMSEA <= 0.050                    1.000       1.000
##   P-value H_0: RMSEA >= 0.080                    0.000       0.000
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## 
## Group 1 [0]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_studying ~                                                         
##     sex1    (.p1.)    0.081    0.032    2.539    0.011    0.018    0.143
##     SESscor (.p2.)    0.095    0.019    5.018    0.000    0.058    0.132
##     Zgcse   (.p3.)    0.106    0.021    4.968    0.000    0.064    0.147
##     Zhqual  (.p4.)    0.510    0.025   20.818    0.000    0.462    0.558
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_studying       0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_st|1 (.p5.)    0.434    0.024   17.960    0.000    0.387    0.482
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_studying       1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_studying       1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_studying       0.271
## 
## 
## Group 2 [1]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_studying ~                                                         
##     sex1    (.p1.)    0.081    0.032    2.539    0.011    0.018    0.143
##     SESscor (.p2.)    0.095    0.019    5.018    0.000    0.058    0.132
##     Zgcse   (.p3.)    0.106    0.021    4.968    0.000    0.064    0.147
##     Zhqual  (.p4.)    0.510    0.025   20.818    0.000    0.462    0.558
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_studying       0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_st|1 (.p5.)    0.434    0.024   17.960    0.000    0.387    0.482
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_studying       0.919                               0.919    0.919
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_studying       1.043    0.060   17.355    0.000    0.925    1.161
## 
## R-Square:
##                    Estimate
##     st_studying       0.287
lavTestLRT(multi.st_studying.free, multi.st_studying.cons)
## 
## Scaled Chi-Squared Difference Test (method = "satorra.2000")
## 
## lavaan NOTE:
##     The "Chisq" column contains standard test statistics, not the
##     robust test that should be reported per model. A robust difference
##     test is a function of two standard (not robust) statistics.
##  
##                        Df AIC BIC Chisq Chisq diff Df diff Pr(>Chisq)
## multi.st_studying.free  0         0.000                              
## multi.st_studying.cons  4         3.476     3.5246       4     0.4741
#employment status: full-time parent vs. unemployed
model3.st_parent <- 'st_parent ~ sex1 + SESscore + Zgcse + Zhqual'
multi.st_parent.free <- sem(model3.st_parent, data = df_dummy, group = "random", ordered = c("st_parent"), missing = "listwise")
summary(multi.st_parent.free, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 57 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                        10
## 
##   Number of observations per group:               Used       Total
##     0                                             3653        6493
##     1                                             3635        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   Test statistic for each group:
##     0                                            0.000       0.000
##     1                                            0.000       0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## 
## Group 1 [0]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_parent ~                                                           
##     sex1             -0.853    0.250   -3.415    0.001   -1.343   -0.364
##     SESscore         -0.250    0.110   -2.275    0.023   -0.465   -0.035
##     Zgcse            -0.206    0.090   -2.282    0.023   -0.383   -0.029
##     Zhqual           -0.297    0.084   -3.547    0.000   -0.461   -0.133
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_parent         0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_parent|t1      2.624    0.171   15.307    0.000    2.288    2.960
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_parent         1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_parent         1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_parent         0.338
## 
## 
## Group 2 [1]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_parent ~                                                           
##     sex1             -0.553    0.302   -1.831    0.067   -1.146    0.039
##     SESscore         -0.312    0.125   -2.494    0.013   -0.556   -0.067
##     Zgcse            -0.080    0.109   -0.728    0.466   -0.294    0.135
##     Zhqual           -0.390    0.132   -2.960    0.003   -0.649   -0.132
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_parent         0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_parent|t1      2.850    0.230   12.403    0.000    2.400    3.300
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_parent         1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_parent         1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_parent         0.310
multi.st_parent.cons <- sem(model3.st_parent, data = df_dummy, group = "random", group.equal = c("intercepts", "regressions"), ordered = c("st_parent"), missing = "listwise")
summary(multi.st_parent.cons, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 43 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                        11
##   Number of equality constraints                     5
## 
##   Number of observations per group:               Used       Total
##     0                                             3653        6493
##     1                                             3635        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 2.018       2.383
##   Degrees of freedom                                 4           4
##   P-value (Chi-square)                           0.732       0.666
##   Scaling correction factor                                  1.133
##   Shift parameter                                            0.601
##     simple second-order correction                                
##   Test statistic for each group:
##     0                                            0.862       1.062
##     1                                            1.157       1.321
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.018       0.020
##   P-value H_0: RMSEA <= 0.050                    1.000       1.000
##   P-value H_0: RMSEA >= 0.080                    0.000       0.000
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## 
## Group 1 [0]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_parent ~                                                           
##     sex1    (.p1.)   -0.705    0.196   -3.593    0.000   -1.090   -0.321
##     SESscor (.p2.)   -0.269    0.083   -3.224    0.001   -0.433   -0.106
##     Zgcse   (.p3.)   -0.148    0.069   -2.157    0.031   -0.283   -0.014
##     Zhqual  (.p4.)   -0.318    0.071   -4.508    0.000   -0.457   -0.180
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_parent         0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_pr|1 (.p5.)    2.639    0.176   14.961    0.000    2.293    2.984
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_parent         1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_parent         1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_parent         0.307
## 
## 
## Group 2 [1]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_parent ~                                                           
##     sex1    (.p1.)   -0.705    0.196   -3.593    0.000   -1.090   -0.321
##     SESscor (.p2.)   -0.269    0.083   -3.224    0.001   -0.433   -0.106
##     Zgcse   (.p3.)   -0.148    0.069   -2.157    0.031   -0.283   -0.014
##     Zhqual  (.p4.)   -0.318    0.071   -4.508    0.000   -0.457   -0.180
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_parent         0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_pr|1 (.p5.)    2.639    0.176   14.961    0.000    2.293    2.984
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_parent         0.872                               0.872    0.872
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_parent         1.071    0.112    9.529    0.000    0.850    1.291
## 
## R-Square:
##                    Estimate
##     st_parent         0.336
lavTestLRT(multi.st_parent.free, multi.st_parent.cons)
## 
## Scaled Chi-Squared Difference Test (method = "satorra.2000")
## 
## lavaan NOTE:
##     The "Chisq" column contains standard test statistics, not the
##     robust test that should be reported per model. A robust difference
##     test is a function of two standard (not robust) statistics.
##  
##                      Df AIC BIC  Chisq Chisq diff Df diff Pr(>Chisq)
## multi.st_parent.free  0         0.0000                              
## multi.st_parent.cons  4         2.0184     2.3825       4     0.6658
#employment status: gap year/travelling vs. unemployed
model3.st_gapyear <- 'st_gapyear ~ sex1 + SESscore + Zgcse + Zhqual'
multi.st_gapyear.free <- sem(model3.st_gapyear, data = df_dummy, group = "random", ordered = c("st_gapyear"), missing = "listwise")
summary(multi.st_gapyear.free, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 33 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                        10
## 
##   Number of observations per group:               Used       Total
##     0                                             3653        6493
##     1                                             3635        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   Test statistic for each group:
##     0                                            0.000       0.000
##     1                                            0.000       0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.000       0.000
##   P-value H_0: RMSEA <= 0.050                       NA          NA
##   P-value H_0: RMSEA >= 0.080                       NA          NA
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## 
## Group 1 [0]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_gapyear ~                                                          
##     sex1              0.037    0.087    0.422    0.673   -0.134    0.208
##     SESscore          0.150    0.052    2.877    0.004    0.048    0.252
##     Zgcse             0.094    0.059    1.602    0.109   -0.021    0.209
##     Zhqual            0.012    0.057    0.213    0.831   -0.100    0.124
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_gapyear        0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_gapyear|t1     1.946    0.056   34.568    0.000    1.836    2.057
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_gapyear        1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_gapyear        1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_gapyear        0.041
## 
## 
## Group 2 [1]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_gapyear ~                                                          
##     sex1             -0.113    0.083   -1.357    0.175   -0.276    0.050
##     SESscore          0.137    0.050    2.741    0.006    0.039    0.235
##     Zgcse             0.056    0.056    1.003    0.316   -0.054    0.167
##     Zhqual           -0.015    0.055   -0.268    0.789   -0.123    0.093
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_gapyear        0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_gapyear|t1     1.805    0.053   33.897    0.000    1.701    1.910
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_gapyear        1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_gapyear        1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_gapyear        0.025
multi.st_gapyear.cons <- sem(model3.st_gapyear, data = df_dummy, group = "random", group.equal = c("intercepts", "regressions"), ordered = c("st_gapyear"), missing = "listwise")
summary(multi.st_gapyear.cons, fit.measures = TRUE, ci = TRUE, rsquare = TRUE)
## lavaan 0.6.15 ended normally after 27 iterations
## 
##   Estimator                                       DWLS
##   Optimization method                           NLMINB
##   Number of model parameters                        11
##   Number of equality constraints                     5
## 
##   Number of observations per group:               Used       Total
##     0                                             3653        6493
##     1                                             3635        6488
## 
## Model Test User Model:
##                                               Standard      Scaled
##   Test Statistic                                 1.878       2.032
##   Degrees of freedom                                 4           4
##   P-value (Chi-square)                           0.758       0.730
##   Scaling correction factor                                  1.072
##   Shift parameter                                            0.280
##     simple second-order correction                                
##   Test statistic for each group:
##     0                                            0.912       0.991
##     1                                            0.966       1.041
## 
## Model Test Baseline Model:
## 
##   Test statistic                                 0.000       0.000
##   Degrees of freedom                                 0           0
##   P-value                                           NA          NA
##   Scaling correction factor                                     NA
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    1.000       1.000
##   Tucker-Lewis Index (TLI)                       1.000       1.000
##                                                                   
##   Robust Comparative Fit Index (CFI)                            NA
##   Robust Tucker-Lewis Index (TLI)                               NA
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.000       0.000
##   90 Percent confidence interval - lower         0.000       0.000
##   90 Percent confidence interval - upper         0.017       0.018
##   P-value H_0: RMSEA <= 0.050                    1.000       1.000
##   P-value H_0: RMSEA >= 0.080                    0.000       0.000
##                                                                   
##   Robust RMSEA                                                  NA
##   90 Percent confidence interval - lower                        NA
##   90 Percent confidence interval - upper                        NA
##   P-value H_0: Robust RMSEA <= 0.050                            NA
##   P-value H_0: Robust RMSEA >= 0.080                            NA
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.000       0.000
## 
## Parameter Estimates:
## 
##   Standard errors                           Robust.sem
##   Information                                 Expected
##   Information saturated (h1) model        Unstructured
## 
## 
## Group 1 [0]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_gapyear ~                                                          
##     sex1    (.p1.)   -0.040    0.063   -0.643    0.520   -0.163    0.083
##     SESscor (.p2.)    0.149    0.038    3.966    0.000    0.075    0.223
##     Zgcse   (.p3.)    0.078    0.042    1.849    0.064   -0.005    0.161
##     Zhqual  (.p4.)   -0.001    0.041   -0.032    0.975   -0.082    0.079
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_gapyear        0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_gp|1 (.p5.)    1.946    0.056   34.569    0.000    1.836    2.057
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_gapyear        1.000                               1.000    1.000
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_gapyear        1.000                               1.000    1.000
## 
## R-Square:
##                    Estimate
##     st_gapyear        0.033
## 
## 
## Group 2 [1]:
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##   st_gapyear ~                                                          
##     sex1    (.p1.)   -0.040    0.063   -0.643    0.520   -0.163    0.083
##     SESscor (.p2.)    0.149    0.038    3.966    0.000    0.075    0.223
##     Zgcse   (.p3.)    0.078    0.042    1.849    0.064   -0.005    0.161
##     Zhqual  (.p4.)   -0.001    0.041   -0.032    0.975   -0.082    0.079
## 
## Intercepts:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_gapyear        0.000                               0.000    0.000
## 
## Thresholds:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_gp|1 (.p5.)    1.946    0.056   34.569    0.000    1.836    2.057
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##    .st_gapyear        1.162                               1.162    1.162
## 
## Scales y*:
##                    Estimate  Std.Err  z-value  P(>|z|) ci.lower ci.upper
##     st_gapyear        0.928    0.038   24.152    0.000    0.852    1.003
## 
## R-Square:
##                    Estimate
##     st_gapyear        0.028
lavTestLRT(multi.st_gapyear.free, multi.st_gapyear.cons)
## 
## Scaled Chi-Squared Difference Test (method = "satorra.2000")
## 
## lavaan NOTE:
##     The "Chisq" column contains standard test statistics, not the
##     robust test that should be reported per model. A robust difference
##     test is a function of two standard (not robust) statistics.
##  
##                       Df AIC BIC  Chisq Chisq diff Df diff Pr(>Chisq)
## multi.st_gapyear.free  0         0.0000                              
## multi.st_gapyear.cons  4         1.8782     2.0323       4     0.7298