set working directory

setwd("C:/Users/jacky/Desktop/Study/Statistical Thinking for Data Science/Assign 3")
getwd()
## [1] "C:/Users/jacky/Desktop/Study/Statistical Thinking for Data Science/Assign 3"

Get Data

semdata=read.csv("SEM_data_V8.csv")

Check the data

str(semdata)
## 'data.frame':    2454 obs. of  11 variables:
##  $ Postcode                      : int  2000 2007 2008 2009 2010 2011 2015 2016 2017 2018 ...
##  $ IEO                           : int  1128 1082 1180 1139 1171 1162 1182 1128 1132 852 ...
##  $ AverageIncome                 : num  52595 47486 53977 75281 77911 ...
##  $ pro_Carer.Allowance           : num  0.351 1.025 0.564 1.096 0.867 ...
##  $ pro_Sickness.Allowance        : num  0 0 0 0 0.0291 ...
##  $ pro_Youth.Allowance..other.   : num  0.0413 0.205 0.1162 0.1127 0.189 ...
##  $ pro_Newstart.Allowance        : num  0.0702 0.1435 0.0996 0.1639 0.0775 ...
##  $ pro_Low.Income.Card           : num  1.11 2.09 2.76 1.67 4.59 ...
##  $ pro_Disability.Support.Pension: num  1.34 3.18 1.81 3.01 1.31 ...
##  $ pro_Family.Tax.Benefit.Part.A : num  1.09 2.58 1.58 2.69 1.13 ...
##  $ pro_Family.Tax.Benefit.Part.B : num  2.04 5.76 5.41 2.96 4.86 ...
names(semdata)
##  [1] "Postcode"                       "IEO"                           
##  [3] "AverageIncome"                  "pro_Carer.Allowance"           
##  [5] "pro_Sickness.Allowance"         "pro_Youth.Allowance..other."   
##  [7] "pro_Newstart.Allowance"         "pro_Low.Income.Card"           
##  [9] "pro_Disability.Support.Pension" "pro_Family.Tax.Benefit.Part.A" 
## [11] "pro_Family.Tax.Benefit.Part.B"
summary(semdata)
##     Postcode         IEO         AverageIncome    pro_Carer.Allowance
##  Min.   : 800   Min.   : 683.0   Min.   : 24560   Min.   : 0.000     
##  1st Qu.:2832   1st Qu.: 932.0   1st Qu.: 45217   1st Qu.: 2.721     
##  Median :3863   Median : 982.0   Median : 51335   Median : 4.320     
##  Mean   :4089   Mean   : 990.3   Mean   : 53793   Mean   : 4.904     
##  3rd Qu.:5163   3rd Qu.:1048.0   3rd Qu.: 59632   3rd Qu.: 6.374     
##  Max.   :7470   Max.   :1234.0   Max.   :129467   Max.   :29.200     
##  pro_Sickness.Allowance pro_Youth.Allowance..other. pro_Newstart.Allowance
##  Min.   :0.00000        Min.   : 0.0000             Min.   : 0.0000       
##  1st Qu.:0.00000        1st Qu.: 0.0000             1st Qu.: 0.0000       
##  Median :0.00000        Median : 0.3835             Median : 0.4226       
##  Mean   :0.02026        Mean   : 0.6932             Mean   : 0.6842       
##  3rd Qu.:0.00000        3rd Qu.: 0.9397             3rd Qu.: 0.8935       
##  Max.   :0.76336        Max.   :39.6825             Max.   :31.7460       
##  pro_Low.Income.Card pro_Disability.Support.Pension
##  Min.   :  0.000     Min.   :  0.000               
##  1st Qu.:  3.266     1st Qu.:  8.371               
##  Median :  5.340     Median : 11.806               
##  Mean   :  6.682     Mean   : 12.286               
##  3rd Qu.:  8.110     3rd Qu.: 15.015               
##  Max.   :215.873     Max.   :134.921               
##  pro_Family.Tax.Benefit.Part.A pro_Family.Tax.Benefit.Part.B
##  Min.   :  0.000               Min.   :  0.000              
##  1st Qu.:  6.419               1st Qu.:  7.771              
##  Median :  9.246               Median : 10.782              
##  Mean   :  9.920               Mean   : 12.556              
##  3rd Qu.: 12.068               3rd Qu.: 14.458              
##  Max.   :128.571               Max.   :440.278

Exploratory Factor Analysis

library('psych')
## Warning: package 'psych' was built under R version 3.4.4
library("GPArotation")

Parallel Analysis

parallel <- fa.parallel(semdata, fm = 'minres', fa = 'fa')

## Parallel analysis suggests that the number of factors =  4  and the number of components =  NA

Parallel Analysis Scree plots

locate the point of inflection – the point where the gap between simulated data and actual data tends to be minimum.

plot(parallel)

Factor Analysis

Exploratory Factor Analysis (EFA) is a statistical technique that is used to identify the latent relational structure among a set of variables and narrow down to smaller number of variables. This essentially means that the variance of large number of variables can be described by few summary variables

## 2 Factors analysis

twofactor <- fa(semdata,nfactors = 2,rotate = "oblimin",fm="minres")
print(twofactor)
## Factor Analysis using method =  minres
## Call: fa(r = semdata, nfactors = 2, rotate = "oblimin", fm = "minres")
## Standardized loadings (pattern matrix) based upon correlation matrix
##                                  MR1   MR2    h2    u2 com
## Postcode                       -0.08 -0.17 0.023 0.977 1.4
## IEO                            -0.04  0.76 0.606 0.394 1.0
## AverageIncome                   0.07  0.69 0.438 0.562 1.0
## pro_Carer.Allowance             0.21 -0.57 0.483 0.517 1.3
## pro_Sickness.Allowance          0.19 -0.09 0.060 0.940 1.5
## pro_Youth.Allowance..other.     0.97  0.16 0.813 0.187 1.1
## pro_Newstart.Allowance          0.90  0.11 0.724 0.276 1.0
## pro_Low.Income.Card             0.90 -0.03 0.844 0.156 1.0
## pro_Disability.Support.Pension  0.72 -0.38 0.936 0.064 1.5
## pro_Family.Tax.Benefit.Part.A   0.79 -0.30 0.940 0.060 1.3
## pro_Family.Tax.Benefit.Part.B   0.77  0.02 0.580 0.420 1.0
## 
##                        MR1  MR2
## SS loadings           4.58 1.87
## Proportion Var        0.42 0.17
## Cumulative Var        0.42 0.59
## Proportion Explained  0.71 0.29
## Cumulative Proportion 0.71 1.00
## 
##  With factor correlations of 
##       MR1   MR2
## MR1  1.00 -0.48
## MR2 -0.48  1.00
## 
## Mean item complexity =  1.2
## Test of the hypothesis that 2 factors are sufficient.
## 
## The degrees of freedom for the null model are  55  and the objective function was  10.25 with Chi Square of  25104.97
## The degrees of freedom for the model are 34  and the objective function was  1.62 
## 
## The root mean square of the residuals (RMSR) is  0.04 
## The df corrected root mean square of the residuals is  0.05 
## 
## The harmonic number of observations is  2454 with the empirical chi square  447.56  with prob <  1.3e-73 
## The total number of observations was  2454  with Likelihood Chi Square =  3963.28  with prob <  0 
## 
## Tucker Lewis Index of factoring reliability =  0.746
## RMSEA index =  0.217  and the 90 % confidence intervals are  0.211 0.223
## BIC =  3697.89
## Fit based upon off diagonal values = 0.99
## Measures of factor score adequacy             
##                                                    MR1  MR2
## Correlation of (regression) scores with factors   0.98 0.93
## Multiple R square of scores with factors          0.97 0.86
## Minimum correlation of possible factor scores     0.93 0.71
## Visualise the factor anaysis
fa.diagram(twofactor)

3 Factors analysis

threefactor <- fa(semdata,nfactors = 3,rotate = "oblimin",fm="minres")
print(threefactor)
## Factor Analysis using method =  minres
## Call: fa(r = semdata, nfactors = 3, rotate = "oblimin", fm = "minres")
## Standardized loadings (pattern matrix) based upon correlation matrix
##                                  MR1   MR2   MR3   h2    u2 com
## Postcode                        0.05 -0.22 -0.54 0.31 0.688 1.3
## IEO                            -0.07  0.77  0.12 0.63 0.374 1.1
## AverageIncome                   0.04  0.67  0.06 0.42 0.578 1.0
## pro_Carer.Allowance             0.10 -0.61  0.32 0.62 0.383 1.6
## pro_Sickness.Allowance          0.12 -0.10  0.24 0.11 0.890 1.8
## pro_Youth.Allowance..other.     0.97  0.15 -0.01 0.81 0.186 1.0
## pro_Newstart.Allowance          0.88  0.10  0.07 0.72 0.277 1.0
## pro_Low.Income.Card             0.93 -0.04 -0.09 0.87 0.129 1.0
## pro_Disability.Support.Pension  0.70 -0.38  0.09 0.93 0.067 1.6
## pro_Family.Tax.Benefit.Part.A   0.76 -0.30  0.09 0.94 0.060 1.3
## pro_Family.Tax.Benefit.Part.B   0.79  0.02 -0.05 0.59 0.411 1.0
## 
##                        MR1  MR2  MR3
## SS loadings           4.50 1.93 0.53
## Proportion Var        0.41 0.18 0.05
## Cumulative Var        0.41 0.58 0.63
## Proportion Explained  0.65 0.28 0.08
## Cumulative Proportion 0.65 0.92 1.00
## 
##  With factor correlations of 
##       MR1   MR2   MR3
## MR1  1.00 -0.48  0.24
## MR2 -0.48  1.00 -0.14
## MR3  0.24 -0.14  1.00
## 
## Mean item complexity =  1.3
## Test of the hypothesis that 3 factors are sufficient.
## 
## The degrees of freedom for the null model are  55  and the objective function was  10.25 with Chi Square of  25104.97
## The degrees of freedom for the model are 25  and the objective function was  1.5 
## 
## The root mean square of the residuals (RMSR) is  0.02 
## The df corrected root mean square of the residuals is  0.03 
## 
## The harmonic number of observations is  2454 with the empirical chi square  147.71  with prob <  2.2e-19 
## The total number of observations was  2454  with Likelihood Chi Square =  3667.58  with prob <  0 
## 
## Tucker Lewis Index of factoring reliability =  0.68
## RMSEA index =  0.244  and the 90 % confidence intervals are  0.237 0.25
## BIC =  3472.44
## Fit based upon off diagonal values = 1
## Measures of factor score adequacy             
##                                                    MR1  MR2  MR3
## Correlation of (regression) scores with factors   0.98 0.93 0.73
## Multiple R square of scores with factors          0.97 0.86 0.53
## Minimum correlation of possible factor scores     0.93 0.73 0.05
## Visualise the factor anaysis
fa.diagram(threefactor)

## 4 Factors analysis

fourfactor <- fa(semdata,nfactors = 4,rotate = "oblimin",fm="minres")
## The estimated weights for the factor scores are probably incorrect.  Try a different factor extraction method.
print(fourfactor)
## Factor Analysis using method =  minres
## Call: fa(r = semdata, nfactors = 4, rotate = "oblimin", fm = "minres")
## Standardized loadings (pattern matrix) based upon correlation matrix
##                                  MR1   MR4   MR2   MR3   h2     u2 com
## Postcode                        0.24 -0.15 -0.21 -0.48 0.21 0.7930 2.1
## IEO                             0.00 -0.33 -0.21  0.50 0.61 0.3926 2.2
## AverageIncome                   0.13 -0.33 -0.18  0.42 0.42 0.5809 2.5
## pro_Carer.Allowance             0.05 -0.01  0.99  0.01 1.00 0.0046 1.0
## pro_Sickness.Allowance         -0.18  0.38  0.14  0.18 0.12 0.8849 2.3
## pro_Youth.Allowance..other.     0.82  0.10  0.02  0.10 0.83 0.1742 1.1
## pro_Newstart.Allowance          0.41  0.52 -0.07  0.18 0.73 0.2687 2.2
## pro_Low.Income.Card             0.91  0.01  0.08 -0.09 0.91 0.0895 1.0
## pro_Disability.Support.Pension  0.01  0.96  0.02 -0.05 1.00 0.0014 1.0
## pro_Family.Tax.Benefit.Part.A   0.15  0.84  0.04 -0.01 0.97 0.0262 1.1
## pro_Family.Tax.Benefit.Part.B   0.72  0.05  0.03 -0.03 0.61 0.3923 1.0
## 
##                        MR1  MR4  MR2  MR3
## SS loadings           2.60 2.71 1.29 0.79
## Proportion Var        0.24 0.25 0.12 0.07
## Cumulative Var        0.24 0.48 0.60 0.67
## Proportion Explained  0.35 0.37 0.17 0.11
## Cumulative Proportion 0.35 0.72 0.89 1.00
## 
##  With factor correlations of 
##      MR1   MR4   MR2   MR3
## MR1 1.00  0.81  0.35  0.00
## MR4 0.81  1.00  0.56 -0.20
## MR2 0.35  0.56  1.00 -0.28
## MR3 0.00 -0.20 -0.28  1.00
## 
## Mean item complexity =  1.6
## Test of the hypothesis that 4 factors are sufficient.
## 
## The degrees of freedom for the null model are  55  and the objective function was  10.25 with Chi Square of  25104.97
## The degrees of freedom for the model are 17  and the objective function was  0.33 
## 
## The root mean square of the residuals (RMSR) is  0.02 
## The df corrected root mean square of the residuals is  0.03 
## 
## The harmonic number of observations is  2454 with the empirical chi square  74.36  with prob <  3.8e-09 
## The total number of observations was  2454  with Likelihood Chi Square =  797.81  with prob <  1.3e-158 
## 
## Tucker Lewis Index of factoring reliability =  0.899
## RMSEA index =  0.137  and the 90 % confidence intervals are  0.129 0.145
## BIC =  665.12
## Fit based upon off diagonal values = 1
## Visualise the factor anaysis
fa.diagram(fourfactor)

SEM Modelling

Load lavaan

library(lavaan)
## Warning: package 'lavaan' was built under R version 3.4.4
## This is lavaan 0.6-3
## lavaan is BETA software! Please report any bugs.
## 
## Attaching package: 'lavaan'
## The following object is masked from 'package:psych':
## 
##     cor2cov
library(semPlot)
## Warning: package 'semPlot' was built under R version 3.4.4

build latent variable model

model <- '
# latent variable model
SC =~ IEO + AverageIncome
DIS =~ pro_Youth.Allowance..other. + pro_Low.Income.Card + pro_Newstart.Allowance + pro_Disability.Support.Pension + pro_Family.Tax.Benefit.Part.A + pro_Family.Tax.Benefit.Part.B


# regressions
SC ~ DIS



'

fitting the data to the model

fit <- sem(model, data=semdata)
## Warning in lav_data_full(data = data, group = group, cluster = cluster, :
## lavaan WARNING: some observed variances are (at least) a factor 1000 times
## larger than others; use varTable(fit) to investigate
## Warning in lav_data_full(data = data, group = group, cluster = cluster, : lavaan WARNING: some observed variances are larger than 1000000
##   lavaan NOTE: use varTable(fit) to investigate
## Warning in lav_model_vcov(lavmodel = lavmodel, lavsamplestats = lavsamplestats, : lavaan WARNING:
##     Could not compute standard errors! The information matrix could
##     not be inverted. This may be a symptom that the model is not
##     identified.
## Warning in lav_object_post_check(object): lavaan WARNING: some estimated ov
## variances are negative

evaluation

summary(fit, standardized=TRUE, fit.measures=TRUE)
## lavaan 0.6-3 ended normally after 118 iterations
## 
##   Optimization method                           NLMINB
##   Number of free parameters                         17
## 
##   Number of observations                          2454
## 
##   Estimator                                         ML
##   Model Fit Test Statistic                    3219.343
##   Degrees of freedom                                19
##   P-value (Chi-square)                           0.000
## 
## Model test baseline model:
## 
##   Minimum Function Test Statistic            23001.346
##   Degrees of freedom                                28
##   P-value                                        0.000
## 
## User model versus baseline model:
## 
##   Comparative Fit Index (CFI)                    0.861
##   Tucker-Lewis Index (TLI)                       0.795
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -74438.405
##   Loglikelihood unrestricted model (H1)     -72828.733
## 
##   Number of free parameters                         17
##   Akaike (AIC)                              148910.810
##   Bayesian (BIC)                            149009.503
##   Sample-size adjusted Bayesian (BIC)       148955.490
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.262
##   90 Percent Confidence Interval          0.254  0.270
##   P-value RMSEA <= 0.05                          0.000
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.082
## 
## Parameter Estimates:
## 
##   Information                                 Expected
##   Information saturated (h1) model          Structured
##   Standard Errors                             Standard
## 
## Latent Variables:
##                    Estimate       Std.Err  z-value  P(>|z|)   Std.lv     
##   SC =~                                                                  
##     IEO                    1.000                                   71.088
##     AverageIncome        107.038       NA                        7609.115
##   DIS =~                                                                 
##     pr_Yth.Allw...         1.000                                    1.092
##     pr_Lw.Incm.Crd         5.909       NA                           6.451
##     pr_Nwstrt.Allw         0.978       NA                           1.068
##     pr_Dsblty.Sp.P         6.421       NA                           7.010
##     pr_Fml.T.B.P.A         5.963       NA                           6.510
##     pr_Fml.T.B.P.B         8.314       NA                           9.077
##   Std.all
##          
##     0.832
##     0.603
##          
##     0.776
##     0.849
##     0.783
##     0.986
##     1.001
##     0.669
## 
## Regressions:
##                    Estimate       Std.Err  z-value  P(>|z|)   Std.lv     
##   SC ~                                                                   
##     DIS                  -41.534       NA                          -0.638
##   Std.all
##          
##    -0.638
## 
## Variances:
##                    Estimate       Std.Err  z-value  P(>|z|)   Std.lv     
##    .IEO                 2245.595       NA                        2245.595
##    .AverageIncome  101417086.960       NA                   101417086.960
##    .pr_Yth.Allw...         0.789       NA                           0.789
##    .pr_Lw.Incm.Crd        16.098       NA                          16.098
##    .pr_Nwstrt.Allw         0.721       NA                           0.721
##    .pr_Dsblty.Sp.P         1.408       NA                           1.408
##    .pr_Fml.T.B.P.A        -0.092       NA                          -0.092
##    .pr_Fml.T.B.P.B       101.745       NA                         101.745
##    .SC                  2997.402       NA                           0.593
##     DIS                    1.192       NA                           1.000
##   Std.all
##     0.308
##     0.637
##     0.398
##     0.279
##     0.387
##     0.028
##    -0.002
##     0.553
##     0.593
##     1.000

The lavInspect() and lavTech() functions can be used to inspect/extract information that is stored inside (or can be computed from) a fitted lavaan object. Note: the (older) inspect() function is now simply a shortcut for lavInspect() with default arguments.

lavInspect(fit, what="estimates")
## $lambda
##                                     SC   DIS
## IEO                              1.000 0.000
## AverageIncome                  107.038 0.000
## pro_Youth.Allowance..other.      0.000 1.000
## pro_Low.Income.Card              0.000 5.909
## pro_Newstart.Allowance           0.000 0.978
## pro_Disability.Support.Pension   0.000 6.421
## pro_Family.Tax.Benefit.Part.A    0.000 5.963
## pro_Family.Tax.Benefit.Part.B    0.000 8.314
## 
## $theta
##                                IEO           AvrgIn        p_Y.A.       
## IEO                                 2245.595                            
## AverageIncome                          0.000 101417086.960              
## pro_Youth.Allowance..other.            0.000         0.000         0.789
## pro_Low.Income.Card                    0.000         0.000         0.000
## pro_Newstart.Allowance                 0.000         0.000         0.000
## pro_Disability.Support.Pension         0.000         0.000         0.000
## pro_Family.Tax.Benefit.Part.A          0.000         0.000         0.000
## pro_Family.Tax.Benefit.Part.B          0.000         0.000         0.000
##                                p_L.I.        pr_N.A        p_D.S.       
## IEO                                                                     
## AverageIncome                                                           
## pro_Youth.Allowance..other.                                             
## pro_Low.Income.Card                   16.098                            
## pro_Newstart.Allowance                 0.000         0.721              
## pro_Disability.Support.Pension         0.000         0.000         1.408
## pro_Family.Tax.Benefit.Part.A          0.000         0.000         0.000
## pro_Family.Tax.Benefit.Part.B          0.000         0.000         0.000
##                                p_F.T.B.P.A   p_F.T.B.P.B  
## IEO                                                       
## AverageIncome                                             
## pro_Youth.Allowance..other.                               
## pro_Low.Income.Card                                       
## pro_Newstart.Allowance                                    
## pro_Disability.Support.Pension                            
## pro_Family.Tax.Benefit.Part.A         -0.092              
## pro_Family.Tax.Benefit.Part.B          0.000       101.745
## 
## $psi
##     SC       DIS     
## SC  2997.402         
## DIS    0.000    1.192
## 
## $beta
##     SC     DIS
## SC   0 -41.534
## DIS  0   0.000

visualise the weightings in a diagram

semPaths(fit,  what = "stand", rotation = 4)

##visualise the difference between the implied and observed fits of the correlations in our model vs the data.

semCors(fit)

check where the model is performing well and where it is not performing so well

also can see the relationship betwwen variables

semCors(fit, include="difference")

obtain confidence intervals for the estimated coefficients, which also tell us a little bit more about how well the model is working

parameterEstimates(fit, ci = TRUE, level = 0.95)
##                               lhs op                            rhs
## 1                              SC =~                            IEO
## 2                              SC =~                  AverageIncome
## 3                             DIS =~    pro_Youth.Allowance..other.
## 4                             DIS =~            pro_Low.Income.Card
## 5                             DIS =~         pro_Newstart.Allowance
## 6                             DIS =~ pro_Disability.Support.Pension
## 7                             DIS =~  pro_Family.Tax.Benefit.Part.A
## 8                             DIS =~  pro_Family.Tax.Benefit.Part.B
## 9                              SC  ~                            DIS
## 10                            IEO ~~                            IEO
## 11                  AverageIncome ~~                  AverageIncome
## 12    pro_Youth.Allowance..other. ~~    pro_Youth.Allowance..other.
## 13            pro_Low.Income.Card ~~            pro_Low.Income.Card
## 14         pro_Newstart.Allowance ~~         pro_Newstart.Allowance
## 15 pro_Disability.Support.Pension ~~ pro_Disability.Support.Pension
## 16  pro_Family.Tax.Benefit.Part.A ~~  pro_Family.Tax.Benefit.Part.A
## 17  pro_Family.Tax.Benefit.Part.B ~~  pro_Family.Tax.Benefit.Part.B
## 18                             SC ~~                             SC
## 19                            DIS ~~                            DIS
##              est se  z pvalue ci.lower ci.upper
## 1          1.000  0 NA     NA        1        1
## 2        107.038 NA NA     NA       NA       NA
## 3          1.000  0 NA     NA        1        1
## 4          5.909 NA NA     NA       NA       NA
## 5          0.978 NA NA     NA       NA       NA
## 6          6.421 NA NA     NA       NA       NA
## 7          5.963 NA NA     NA       NA       NA
## 8          8.314 NA NA     NA       NA       NA
## 9        -41.534 NA NA     NA       NA       NA
## 10      2245.595 NA NA     NA       NA       NA
## 11 101417086.960 NA NA     NA       NA       NA
## 12         0.789 NA NA     NA       NA       NA
## 13        16.098 NA NA     NA       NA       NA
## 14         0.721 NA NA     NA       NA       NA
## 15         1.408 NA NA     NA       NA       NA
## 16        -0.092 NA NA     NA       NA       NA
## 17       101.745 NA NA     NA       NA       NA
## 18      2997.402 NA NA     NA       NA       NA
## 19         1.192 NA NA     NA       NA       NA

see how the various factors covary with one another

Extract Model Fitted Values

fitted(fit)
## $cov
##                                IEO           AvrgIn        p_Y.A.       
## IEO                                 7299.128                            
## AverageIncome                     540918.297 159315710.561              
## pro_Youth.Allowance..other.          -49.504     -5298.816         1.981
## pro_Low.Income.Card                 -292.508    -31309.346         7.043
## pro_Newstart.Allowance               -48.418     -5182.525         1.166
## pro_Disability.Support.Pension      -317.850    -34021.927         7.653
## pro_Family.Tax.Benefit.Part.A       -295.186    -31595.966         7.107
## pro_Family.Tax.Benefit.Part.B       -411.583    -44054.876         9.909
##                                p_L.I.        pr_N.A        p_D.S.       
## IEO                                                                     
## AverageIncome                                                           
## pro_Youth.Allowance..other.                                             
## pro_Low.Income.Card                   57.711                            
## pro_Newstart.Allowance                 6.888         1.861              
## pro_Disability.Support.Pension        45.218         7.485        50.544
## pro_Family.Tax.Benefit.Part.A         41.993         6.951        45.632
## pro_Family.Tax.Benefit.Part.B         58.552         9.692        63.625
##                                p_F.T.B.P.A   p_F.T.B.P.B  
## IEO                                                       
## AverageIncome                                             
## pro_Youth.Allowance..other.                               
## pro_Low.Income.Card                                       
## pro_Newstart.Allowance                                    
## pro_Disability.Support.Pension                            
## pro_Family.Tax.Benefit.Part.A         42.286              
## pro_Family.Tax.Benefit.Part.B         59.088       184.133

compare with the covariance of the original dataset

cov(semdata)
##                                     Postcode           IEO AverageIncome
## Postcode                        2.248282e+06 -2.740917e+04 -2.338663e+06
## IEO                            -2.740917e+04  7.302068e+03  5.411360e+05
## AverageIncome                  -2.338663e+06  5.411360e+05  1.593807e+08
## pro_Carer.Allowance            -3.650503e+02 -1.539688e+02 -1.826178e+04
## pro_Sickness.Allowance         -5.589705e+00 -6.284068e-01 -2.699079e+01
## pro_Youth.Allowance..other.     4.686655e+00 -3.619253e+01 -2.426961e+03
## pro_Newstart.Allowance         -5.606835e+01 -3.308921e+01 -2.660158e+03
## pro_Low.Income.Card             9.473737e+02 -2.622096e+02 -2.479028e+04
## pro_Disability.Support.Pension  3.902606e+02 -3.412477e+02 -4.156450e+04
## pro_Family.Tax.Benefit.Part.A   3.534246e+02 -2.960958e+02 -3.198968e+04
## pro_Family.Tax.Benefit.Part.B   2.834043e+02 -3.416264e+02 -4.344709e+04
##                                pro_Carer.Allowance pro_Sickness.Allowance
## Postcode                             -3.650503e+02           -5.589704614
## IEO                                  -1.539688e+02           -0.628406754
## AverageIncome                        -1.826178e+04          -26.990791215
## pro_Carer.Allowance                   1.107488e+01            0.038360526
## pro_Sickness.Allowance                3.836053e-02            0.002278902
## pro_Youth.Allowance..other.           1.695698e+00            0.013291843
## pro_Newstart.Allowance                1.567245e+00            0.014155151
## pro_Low.Income.Card                   1.196870e+01            0.054529667
## pro_Disability.Support.Pension        1.426177e+01            0.085788314
## pro_Family.Tax.Benefit.Part.A         1.278647e+01            0.081320929
## pro_Family.Tax.Benefit.Part.B         1.540276e+01            0.088894282
##                                pro_Youth.Allowance..other.
## Postcode                                      4.686655e+00
## IEO                                          -3.619253e+01
## AverageIncome                                -2.426961e+03
## pro_Carer.Allowance                           1.695698e+00
## pro_Sickness.Allowance                        1.329184e-02
## pro_Youth.Allowance..other.                   1.982144e+00
## pro_Newstart.Allowance                        1.427039e+00
## pro_Low.Income.Card                           8.931736e+00
## pro_Disability.Support.Pension                7.419898e+00
## pro_Family.Tax.Benefit.Part.A                 7.112249e+00
## pro_Family.Tax.Benefit.Part.B                 1.383106e+01
##                                pro_Newstart.Allowance pro_Low.Income.Card
## Postcode                                -5.606835e+01        9.473737e+02
## IEO                                     -3.308921e+01       -2.622096e+02
## AverageIncome                           -2.660158e+03       -2.479028e+04
## pro_Carer.Allowance                      1.567245e+00        1.196870e+01
## pro_Sickness.Allowance                   1.415515e-02        5.452967e-02
## pro_Youth.Allowance..other.              1.427039e+00        8.931736e+00
## pro_Newstart.Allowance                   1.861583e+00        7.958142e+00
## pro_Low.Income.Card                      7.958142e+00        5.773426e+01
## pro_Disability.Support.Pension           7.389479e+00        4.427005e+01
## pro_Family.Tax.Benefit.Part.A            6.958410e+00        4.201902e+01
## pro_Family.Tax.Benefit.Part.B            1.175611e+01        7.602636e+01
##                                pro_Disability.Support.Pension
## Postcode                                         3.902606e+02
## IEO                                             -3.412477e+02
## AverageIncome                                   -4.156450e+04
## pro_Carer.Allowance                              1.426177e+01
## pro_Sickness.Allowance                           8.578831e-02
## pro_Youth.Allowance..other.                      7.419898e+00
## pro_Newstart.Allowance                           7.389479e+00
## pro_Low.Income.Card                              4.427005e+01
## pro_Disability.Support.Pension                   5.056437e+01
## pro_Family.Tax.Benefit.Part.A                    4.564208e+01
## pro_Family.Tax.Benefit.Part.B                    6.314294e+01
##                                pro_Family.Tax.Benefit.Part.A
## Postcode                                        3.534246e+02
## IEO                                            -2.960958e+02
## AverageIncome                                  -3.198968e+04
## pro_Carer.Allowance                             1.278647e+01
## pro_Sickness.Allowance                          8.132093e-02
## pro_Youth.Allowance..other.                     7.112249e+00
## pro_Newstart.Allowance                          6.958410e+00
## pro_Low.Income.Card                             4.201902e+01
## pro_Disability.Support.Pension                  4.564208e+01
## pro_Family.Tax.Benefit.Part.A                   4.230370e+01
## pro_Family.Tax.Benefit.Part.B                   5.928690e+01
##                                pro_Family.Tax.Benefit.Part.B
## Postcode                                        2.834043e+02
## IEO                                            -3.416264e+02
## AverageIncome                                  -4.344709e+04
## pro_Carer.Allowance                             1.540276e+01
## pro_Sickness.Allowance                          8.889428e-02
## pro_Youth.Allowance..other.                     1.383106e+01
## pro_Newstart.Allowance                          1.175611e+01
## pro_Low.Income.Card                             7.602636e+01
## pro_Disability.Support.Pension                  6.314294e+01
## pro_Family.Tax.Benefit.Part.A                   5.928690e+01
## pro_Family.Tax.Benefit.Part.B                   1.842085e+02

Extract Model Residuals

residuals is a generic function which extracts model residuals from objects returned by modeling functions.

resid(fit, type="standardized")
## $type
## [1] "standardized"
## 
## $cov
##                                IEO           AvrgIn        p_Y.A.       
## IEO                              -696299.771                            
## AverageIncome                         -0.001         0.000              
## pro_Youth.Allowance..other.           10.001        12.745         0.000
## pro_Low.Income.Card                    5.108         6.236        22.738
## pro_Newstart.Allowance                11.877        11.776        16.112
## pro_Disability.Support.Pension       -10.905       -15.578       -15.187
## pro_Family.Tax.Benefit.Part.A         -0.742        -0.857         2.064
## pro_Family.Tax.Benefit.Part.B          4.728         0.260        19.840
##                                p_L.I.        pr_N.A        p_D.S.       
## IEO                                                                     
## AverageIncome                                                           
## pro_Youth.Allowance..other.                                             
## pro_Low.Income.Card             87906302.395                            
## pro_Newstart.Allowance                14.677         0.000              
## pro_Disability.Support.Pension       -15.487        -5.777 176181256.646
## pro_Family.Tax.Benefit.Part.A          1.918         3.627       -21.816
## pro_Family.Tax.Benefit.Part.B         19.633        11.636        -2.528
##                                p_F.T.B.P.A   p_F.T.B.P.B  
## IEO                                                       
## AverageIncome                                             
## pro_Youth.Allowance..other.                               
## pro_Low.Income.Card                                       
## pro_Newstart.Allowance                                    
## pro_Disability.Support.Pension                            
## pro_Family.Tax.Benefit.Part.A   72534369.958              
## pro_Family.Tax.Benefit.Part.B         11.889  20640647.400

work out the reliability of the fit using a function from the semTools package

library(semTools)
## Warning: package 'semTools' was built under R version 3.4.4
## 
## ###############################################################################
## This is semTools 0.5-1
## All users of R (or SEM) are invited to submit functions or ideas for functions.
## ###############################################################################
## 
## Attaching package: 'semTools'
## The following object is masked from 'package:psych':
## 
##     skew
reliability(fit)
##                SC       DIS       total
## alpha  0.01348875 0.8450774 0.005613145
## omega  0.36772900 0.8897506 0.366525067
## omega2 0.36772900 0.8897506 0.366525067
## omega3 0.36772885 0.8508721 0.366503060
## avevar 0.36343575 0.6435319 0.363436343