library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.2     ✓ purrr   0.3.4
## ✓ tibble  3.0.4     ✓ dplyr   1.0.2
## ✓ tidyr   1.1.2     ✓ stringr 1.4.0
## ✓ readr   1.4.0     ✓ forcats 0.5.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
require(dplyr)
library(lavaan)
## This is lavaan 0.6-7
## lavaan is BETA software! Please report any bugs.
library(psych)
## 
## Attaching package: 'psych'
## The following object is masked from 'package:lavaan':
## 
##     cor2cov
## The following objects are masked from 'package:ggplot2':
## 
##     %+%, alpha
# reading in the data
df_all <- read_csv("/home/asma/Desktop/CFA_FINAL/Data_new2.csv")
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   .default = col_double(),
##   Majors = col_character(),
##   GPA = col_number(),
##   `sector work` = col_character(),
##   `sector name` = col_character(),
##   current_job = col_character(),
##   Cur_salar = col_character(),
##   Career_day = col_character(),
##   Career_day_help = col_character(),
##   `start studying again KAU` = col_character(),
##   `recommend KAU` = col_character()
## )
## ℹ Use `spec()` for the full column specifications.
# taking a quick look
glimpse(df)
## function (x, df1, df2, ncp, log = FALSE)

In our Analysis we will need the follwoing columns:

#sector_work_class Career_day Career_day_help Relation Cur_salar PA1 PA2 PA3 PA4 PA5 PA6 PA7 PA8 PA9 PA10 PA11 PA12 PA13 PA14 SA1 SA2 SA3 SA4 SA5 SA6 SA7 SA8 SA9 SA10 SA11 SA12 SA13 IS1 IS2 IS3 IS4 IS5 IS6 IS7 IS8 IS9 IS10 IS11 IS12 IS13 IS14 GA1 GA2 GA3 GA4 #Relation is the cuurent job related to your speciality # Let’s change our data to numurical

df_all$sector_work_class<-  as.numeric(as.factor(df_all$sector_work_class)) 
df_all$Career_day<-  as.numeric(as.factor(df_all$Career_day)) 
df_all$Career_day_help<-  as.numeric(as.factor(df_all$Career_day_help)) 
df_all$current_job<-  as.numeric(as.factor(df_all$current_job)) 
df_all$Cur_salar<-  as.numeric(as.factor(df_all$Cur_salar)) 
#Change all the NA values by the median
df_all$sector_work_class[is.na(df_all$sector_work_class)] <- median(df_all$sector_work_class, na.rm=TRUE)
df_all$Career_day[is.na(df_all$Career_day)] <- median(df_all$Career_day, na.rm=TRUE)
df_all$Career_day_help[is.na(df_all$Career_day_help)] <- median(df_all$Career_day_help, na.rm=TRUE)
df_all$current_job[is.na(df_all$current_job)] <- median(df_all$current_job, na.rm=TRUE)
df_all$Cur_salar[is.na(df_all$Cur_salar)] <- median(df_all$Cur_salar, na.rm=TRUE)
df_all
## # A tibble: 336 x 66
##    Gender   Age Nationality Majors `Study program` `year of enroll…
##     <dbl> <dbl>       <dbl> <chr>            <dbl>            <dbl>
##  1      2    25           1 Gener…               1             2013
##  2      2    23           1 Gener…               1             2015
##  3      2    24           1 Gener…               1             2015
##  4      2    23           1 Gener…               1             2016
##  5      2    25           1 Gener…               1             2016
##  6      2    24           1 Gener…               1             2015
##  7      2    22           1 Micro…               1             2016
##  8      2    26           2 Gener…               1             2013
##  9      2    24           2 Gener…               1             2016
## 10      2    22           1 Gener…               1             2016
## # … with 326 more rows, and 60 more variables: `graduation year` <dbl>, `study
## #   years` <dbl>, `graduated before` <dbl>, GPA <dbl>, Num_courses <dbl>,
## #   sector_work_class <dbl>, `sector work` <chr>, `sector name` <chr>,
## #   YearJop <dbl>, current_job <dbl>, Cur_salar <dbl>, Career_day <dbl>,
## #   Career_day_help <dbl>, PA1 <dbl>, PA2 <dbl>, PA3 <dbl>, PA4 <dbl>,
## #   PA5 <dbl>, PA6 <dbl>, PA7 <dbl>, PA8 <dbl>, PA9 <dbl>, PA10 <dbl>,
## #   PA11 <dbl>, PA12 <dbl>, PA13 <dbl>, PA14 <dbl>, SA1 <dbl>, SA2 <dbl>,
## #   SA3 <dbl>, SA4 <dbl>, SA5 <dbl>, SA6 <dbl>, SA7 <dbl>, SA8 <dbl>,
## #   SA9 <dbl>, SA10 <dbl>, SA11 <dbl>, SA12 <dbl>, SA13 <dbl>, IS1 <dbl>,
## #   IS2 <dbl>, IS3 <dbl>, IS4 <dbl>, IS5 <dbl>, IS6 <dbl>, IS7 <dbl>,
## #   IS8 <dbl>, IS9 <dbl>, IS10 <dbl>, IS11 <dbl>, IS12 <dbl>, IS13 <dbl>,
## #   IS14 <dbl>, GA1 <dbl>, GA2 <dbl>, GA3 <dbl>, GA4 <dbl>, `start studying
## #   again KAU` <chr>, `recommend KAU` <chr>

#Now our Data is clean and we have only the items of our CFA in the dataframe.

2. Confirmatory Factor Analysis CFA

Model 0

#Let’s read only the Data that we need for factor analysis

names(df_all)[names(df_all) == "current_job"] <- "Relation"
df<- df_all
###########################################################################
# Experiment with the factors that have the lowest measure of uniqueness
###########################################################################

m1a<- 'Program Quality =~ PA1+PA2+PA3+PA4+PA5+PA6+PA7+PA8+PA9+PA10+PA11+PA12+PA13+PA14+GA1+GA2+GA3+GA4
Faculty Assistance =~ SA1+SA2+SA3+SA4+SA5+SA6+SA7+SA8+SA9+SA10+SA11+SA12+SA13
Student Satisfaction =~ IS1+IS2+IS3+IS4+IS5+IS6+IS7+IS8+IS9+IS10+IS11+IS12
Current Employmentn=~ sector_work_class+Career_day+Career_day_help+Relation+Cur_salar'

fourfac_a<- cfa(m1a, data=df, std.lv=TRUE)
summary(fourfac_a, fit.measures=TRUE)
## lavaan 0.6-7 ended normally after 39 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of free parameters                        102
##                                                       
##                                                   Used       Total
##   Number of observations                           320         336
##                                                                   
## Model Test User Model:
##                                                       
##   Test statistic                              3122.535
##   Degrees of freedom                              1074
##   P-value (Chi-square)                           0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                              9765.482
##   Degrees of freedom                              1128
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.763
##   Tucker-Lewis Index (TLI)                       0.751
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)             -17808.119
##   Loglikelihood unrestricted model (H1)     -16246.852
##                                                       
##   Akaike (AIC)                               35820.238
##   Bayesian (BIC)                             36204.607
##   Sample-size adjusted Bayesian (BIC)        35881.081
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.077
##   90 Percent confidence interval - lower         0.074
##   90 Percent confidence interval - upper         0.080
##   P-value RMSEA <= 0.05                          0.000
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.075
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Latent Variables:
##                          Estimate  Std.Err  z-value  P(>|z|)
##   ProgramQuality =~                                         
##     PA1                     0.702    0.048   14.573    0.000
##     PA2                     0.716    0.047   15.344    0.000
##     PA3                     0.694    0.047   14.647    0.000
##     PA4                     0.684    0.048   14.167    0.000
##     PA5                     0.807    0.053   15.207    0.000
##     PA6                     0.727    0.052   14.096    0.000
##     PA7                     0.755    0.049   15.308    0.000
##     PA8                     0.771    0.059   13.013    0.000
##     PA9                     0.765    0.050   15.158    0.000
##     PA10                    0.808    0.058   13.996    0.000
##     PA11                    0.758    0.053   14.216    0.000
##     PA12                    0.848    0.058   14.551    0.000
##     PA13                    0.722    0.058   12.409    0.000
##     PA14                    0.741    0.078    9.485    0.000
##     GA1                     0.619    0.048   12.934    0.000
##     GA2                     0.630    0.056   11.314    0.000
##     GA3                     0.575    0.051   11.252    0.000
##     GA4                     0.635    0.065    9.788    0.000
##   FacultyAssistance =~                                      
##     SA1                     0.775    0.048   16.256    0.000
##     SA2                     0.810    0.046   17.486    0.000
##     SA3                     0.841    0.047   17.822    0.000
##     SA4                     0.711    0.047   15.225    0.000
##     SA5                     0.723    0.048   15.072    0.000
##     SA6                     0.695    0.047   14.916    0.000
##     SA7                     0.699    0.045   15.607    0.000
##     SA8                     0.744    0.053   14.167    0.000
##     SA9                     0.698    0.049   14.112    0.000
##     SA10                    0.651    0.050   13.068    0.000
##     SA11                    0.663    0.052   12.846    0.000
##     SA12                    0.773    0.053   14.633    0.000
##     SA13                    0.802    0.049   16.430    0.000
##   StudentSatisfaction =~                                    
##     IS1                     0.671    0.064   10.446    0.000
##     IS2                     0.734    0.053   13.898    0.000
##     IS3                     0.792    0.059   13.461    0.000
##     IS4                     0.765    0.059   13.027    0.000
##     IS5                     0.648    0.049   13.110    0.000
##     IS6                     0.589    0.055   10.709    0.000
##     IS7                     0.672    0.051   13.078    0.000
##     IS8                     0.836    0.070   11.920    0.000
##     IS9                     0.428    0.048    8.833    0.000
##     IS10                    0.569    0.061    9.382    0.000
##     IS11                    0.618    0.057   10.876    0.000
##     IS12                    0.683    0.080    8.540    0.000
##   CurrentEmploymentn =~                                     
##     sectr_wrk_clss          0.053    0.027    1.938    0.053
##     Career_day              0.291    0.050    5.841    0.000
##     Career_day_hlp         -0.227    0.043   -5.252    0.000
##     Relation               -0.014    0.028   -0.503    0.615
##     Cur_salar              -0.042    0.029   -1.448    0.148
## 
## Covariances:
##                          Estimate  Std.Err  z-value  P(>|z|)
##   ProgramQuality ~~                                         
##     FacultyAssstnc          0.721    0.030   23.675    0.000
##     StudentStsfctn          0.551    0.044   12.397    0.000
##     CrrntEmplymntn          0.264    0.075    3.504    0.000
##   FacultyAssistance ~~                                      
##     StudentStsfctn          0.664    0.037   17.986    0.000
##     CrrntEmplymntn          0.275    0.075    3.657    0.000
##   StudentSatisfaction ~~                                    
##     CrrntEmplymntn          0.277    0.078    3.573    0.000
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .PA1               0.466    0.039   11.856    0.000
##    .PA2               0.413    0.035   11.718    0.000
##    .PA3               0.448    0.038   11.844    0.000
##    .PA4               0.481    0.040   11.920    0.000
##    .PA5               0.539    0.046   11.744    0.000
##    .PA6               0.552    0.046   11.930    0.000
##    .PA7               0.463    0.039   11.725    0.000
##    .PA8               0.778    0.064   12.076    0.000
##    .PA9               0.490    0.042   11.754    0.000
##    .PA10              0.696    0.058   11.945    0.000
##    .PA11              0.584    0.049   11.912    0.000
##    .PA12              0.683    0.058   11.859    0.000
##    .PA13              0.773    0.064   12.145    0.000
##    .PA14              1.580    0.128   12.389    0.000
##    .GA1               0.509    0.042   12.085    0.000
##    .GA2               0.747    0.061   12.251    0.000
##    .GA3               0.632    0.052   12.257    0.000
##    .GA4               1.080    0.087   12.369    0.000
##    .SA1               0.401    0.035   11.585    0.000
##    .SA2               0.336    0.030   11.260    0.000
##    .SA3               0.336    0.030   11.151    0.000
##    .SA4               0.419    0.035   11.792    0.000
##    .SA5               0.447    0.038   11.819    0.000
##    .SA6               0.427    0.036   11.845    0.000
##    .SA7               0.374    0.032   11.721    0.000
##    .SA8               0.571    0.048   11.961    0.000
##    .SA9               0.508    0.042   11.968    0.000
##    .SA10              0.550    0.045   12.102    0.000
##    .SA11              0.596    0.049   12.127    0.000
##    .SA12              0.560    0.047   11.891    0.000
##    .SA13              0.414    0.036   11.545    0.000
##    .IS1               0.968    0.081   11.934    0.000
##    .IS2               0.543    0.049   11.121    0.000
##    .IS3               0.694    0.062   11.257    0.000
##    .IS4               0.711    0.062   11.380    0.000
##    .IS5               0.500    0.044   11.357    0.000
##    .IS6               0.702    0.059   11.889    0.000
##    .IS7               0.542    0.048   11.366    0.000
##    .IS8               1.076    0.092   11.651    0.000
##    .IS9               0.585    0.048   12.168    0.000
##    .IS10              0.900    0.074   12.096    0.000
##    .IS11              0.744    0.063   11.859    0.000
##    .IS12              1.609    0.132   12.204    0.000
##    .sectr_wrk_clss    0.137    0.011   12.468    0.000
##    .Career_day        0.083    0.027    3.021    0.003
##    .Career_day_hlp    0.157    0.020    7.666    0.000
##    .Relation          0.150    0.012   12.638    0.000
##    .Cur_salar         0.157    0.013   12.552    0.000
##     ProgramQuality    1.000                           
##     FacultyAssstnc    1.000                           
##     StudentStsfctn    1.000                           
##     CrrntEmplymntn    1.000

Model 1 Estimation and results

m1<-  'Program Quality =~ PA2+PA5+PA7+PA12
Faculty Assistance =~ SA1+SA2+SA3+SA13
Student Satisfaction =~ IS2+IS3+IS4
Current Employment =~ Career_day_help+Relation+Cur_salar'

fourfactor<- cfa(m1, data=df, std.lv=TRUE)
summary(fourfactor, fit.measures=TRUE)
## lavaan 0.6-7 ended normally after 35 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of free parameters                         34
##                                                       
##                                                   Used       Total
##   Number of observations                           320         336
##                                                                   
## Model Test User Model:
##                                                       
##   Test statistic                               136.042
##   Degrees of freedom                                71
##   P-value (Chi-square)                           0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                              1782.022
##   Degrees of freedom                                91
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.962
##   Tucker-Lewis Index (TLI)                       0.951
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -4873.445
##   Loglikelihood unrestricted model (H1)      -4805.424
##                                                       
##   Akaike (AIC)                                9814.890
##   Bayesian (BIC)                              9943.013
##   Sample-size adjusted Bayesian (BIC)         9835.171
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.054
##   90 Percent confidence interval - lower         0.040
##   90 Percent confidence interval - upper         0.067
##   P-value RMSEA <= 0.05                          0.321
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.049
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Latent Variables:
##                          Estimate  Std.Err  z-value  P(>|z|)
##   ProgramQuality =~                                         
##     PA2                     0.667    0.050   13.237    0.000
##     PA5                     0.874    0.054   16.070    0.000
##     PA7                     0.790    0.051   15.403    0.000
##     PA12                    0.851    0.061   13.868    0.000
##   FacultyAssistance =~                                      
##     SA1                     0.821    0.048   17.263    0.000
##     SA2                     0.843    0.047   18.122    0.000
##     SA3                     0.860    0.048   17.945    0.000
##     SA13                    0.759    0.051   14.828    0.000
##   StudentSatisfaction =~                                    
##     IS2                     0.792    0.056   14.120    0.000
##     IS3                     0.859    0.062   13.827    0.000
##     IS4                     0.833    0.062   13.486    0.000
##   CurrentEmployment =~                                      
##     Career_day_hlp          0.194    0.086    2.267    0.023
##     Relation                0.073    0.041    1.779    0.075
##     Cur_salar               0.046    0.041    1.129    0.259
## 
## Covariances:
##                          Estimate  Std.Err  z-value  P(>|z|)
##   ProgramQuality ~~                                         
##     FacultyAssstnc          0.614    0.044   13.992    0.000
##     StudentStsfctn          0.359    0.062    5.836    0.000
##     CurrntEmplymnt         -0.301    0.162   -1.863    0.062
##   FacultyAssistance ~~                                      
##     StudentStsfctn          0.520    0.052   10.002    0.000
##     CurrntEmplymnt         -0.393    0.177   -2.219    0.027
##   StudentSatisfaction ~~                                    
##     CurrntEmplymnt         -0.247    0.156   -1.584    0.113
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .PA2               0.480    0.045   10.577    0.000
##    .PA5               0.426    0.050    8.594    0.000
##    .PA7               0.410    0.045    9.198    0.000
##    .PA12              0.678    0.066   10.254    0.000
##    .SA1               0.328    0.034    9.624    0.000
##    .SA2               0.281    0.032    8.902    0.000
##    .SA3               0.305    0.034    9.066    0.000
##    .SA13              0.481    0.044   10.914    0.000
##    .IS2               0.455    0.056    8.103    0.000
##    .IS3               0.583    0.069    8.467    0.000
##    .IS4               0.603    0.068    8.860    0.000
##    .Career_day_hlp    0.171    0.035    4.915    0.000
##    .Relation          0.145    0.012   11.575    0.000
##    .Cur_salar         0.157    0.013   12.262    0.000
##     ProgramQuality    1.000                           
##     FacultyAssstnc    1.000                           
##     StudentStsfctn    1.000                           
##     CurrntEmplymnt    1.000
# Model 2 Estimation and results
m2<-  'Program Quality =~ PA1+PA2+PA3+PA4+PA5+PA6+PA7+PA9+PA11+PA12
Faculty Assistance =~ SA1+SA2+SA3+SA13
Student Satisfaction =~ IS1+IS2++IS4+IS5+IS6
Current Employment =~ Career_day_help+Relation+Cur_salar'

fourfactor_1<- cfa(m2, data=df, std.lv=TRUE)
summary(fourfactor_1, fit.measures=TRUE)
## lavaan 0.6-7 ended normally after 40 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of free parameters                         50
##                                                       
##                                                   Used       Total
##   Number of observations                           320         336
##                                                                   
## Model Test User Model:
##                                                       
##   Test statistic                               555.113
##   Degrees of freedom                               203
##   P-value (Chi-square)                           0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                              3607.040
##   Degrees of freedom                               231
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.896
##   Tucker-Lewis Index (TLI)                       0.881
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -7829.449
##   Loglikelihood unrestricted model (H1)      -7551.893
##                                                       
##   Akaike (AIC)                               15758.899
##   Bayesian (BIC)                             15947.315
##   Sample-size adjusted Bayesian (BIC)        15788.724
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.074
##   90 Percent confidence interval - lower         0.066
##   90 Percent confidence interval - upper         0.081
##   P-value RMSEA <= 0.05                          0.000
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.056
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Latent Variables:
##                          Estimate  Std.Err  z-value  P(>|z|)
##   ProgramQuality =~                                         
##     PA1                     0.717    0.048   14.889    0.000
##     PA2                     0.727    0.047   15.556    0.000
##     PA3                     0.710    0.047   15.004    0.000
##     PA4                     0.720    0.048   15.064    0.000
##     PA5                     0.837    0.053   15.896    0.000
##     PA6                     0.753    0.051   14.665    0.000
##     PA7                     0.787    0.049   16.117    0.000
##     PA9                     0.753    0.051   14.703    0.000
##     PA11                    0.732    0.054   13.479    0.000
##     PA12                    0.841    0.059   14.274    0.000
##   FacultyAssistance =~                                      
##     SA1                     0.821    0.047   17.304    0.000
##     SA2                     0.841    0.047   18.085    0.000
##     SA3                     0.861    0.048   18.011    0.000
##     SA13                    0.758    0.051   14.831    0.000
##   StudentSatisfaction =~                                    
##     IS1                     0.627    0.068    9.269    0.000
##     IS2                     0.637    0.057   11.087    0.000
##     IS4                     0.720    0.062   11.550    0.000
##     IS5                     0.750    0.049   15.170    0.000
##     IS6                     0.719    0.055   13.181    0.000
##   CurrentEmployment =~                                      
##     Career_day_hlp          0.182    0.079    2.312    0.021
##     Relation                0.078    0.042    1.866    0.062
##     Cur_salar               0.049    0.041    1.179    0.238
## 
## Covariances:
##                          Estimate  Std.Err  z-value  P(>|z|)
##   ProgramQuality ~~                                         
##     FacultyAssstnc          0.640    0.039   16.426    0.000
##     StudentStsfctn          0.562    0.047   11.839    0.000
##     CurrntEmplymnt         -0.313    0.158   -1.979    0.048
##   FacultyAssistance ~~                                      
##     StudentStsfctn          0.604    0.046   13.116    0.000
##     CurrntEmplymnt         -0.402    0.176   -2.292    0.022
##   StudentSatisfaction ~~                                    
##     CurrntEmplymnt         -0.242    0.156   -1.552    0.121
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .PA1               0.444    0.039   11.483    0.000
##    .PA2               0.397    0.035   11.308    0.000
##    .PA3               0.425    0.037   11.455    0.000
##    .PA4               0.432    0.038   11.440    0.000
##    .PA5               0.490    0.044   11.208    0.000
##    .PA6               0.514    0.045   11.537    0.000
##    .PA7               0.414    0.037   11.138    0.000
##    .PA9               0.509    0.044   11.528    0.000
##    .PA11              0.622    0.053   11.781    0.000
##    .PA12              0.695    0.060   11.624    0.000
##    .SA1               0.327    0.034    9.658    0.000
##    .SA2               0.284    0.031    9.019    0.000
##    .SA3               0.303    0.033    9.086    0.000
##    .SA13              0.481    0.044   10.944    0.000
##    .IS1               1.025    0.088   11.633    0.000
##    .IS2               0.677    0.061   11.051    0.000
##    .IS4               0.778    0.072   10.864    0.000
##    .IS5               0.358    0.043    8.409    0.000
##    .IS6               0.532    0.053   10.017    0.000
##    .Career_day_hlp    0.175    0.031    5.749    0.000
##    .Relation          0.144    0.013   11.349    0.000
##    .Cur_salar         0.157    0.013   12.193    0.000
##     ProgramQuality    1.000                           
##     FacultyAssstnc    1.000                           
##     StudentStsfctn    1.000                           
##     CurrntEmplymnt    1.000
# Model 3 Estimation and results
m3<-  'Program Quality =~ PA2+PA5+PA7+PA12
Faculty Assistance =~ SA1+SA2+SA3+SA13
Student Satisfaction =~ IS2+IS4
Current Employment =~ Career_day_help+Relation+Cur_salar'

fourfactor_2<- cfa(m3, data=df, std.lv=TRUE)
summary(fourfactor_2, fit.measures=TRUE)
## lavaan 0.6-7 ended normally after 40 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of free parameters                         32
##                                                       
##                                                   Used       Total
##   Number of observations                           320         336
##                                                                   
## Model Test User Model:
##                                                       
##   Test statistic                               100.077
##   Degrees of freedom                                59
##   P-value (Chi-square)                           0.001
## 
## Model Test Baseline Model:
## 
##   Test statistic                              1577.059
##   Degrees of freedom                                78
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.973
##   Tucker-Lewis Index (TLI)                       0.964
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -4459.237
##   Loglikelihood unrestricted model (H1)      -4409.198
##                                                       
##   Akaike (AIC)                                8982.473
##   Bayesian (BIC)                              9103.060
##   Sample-size adjusted Bayesian (BIC)         9001.561
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.047
##   90 Percent confidence interval - lower         0.030
##   90 Percent confidence interval - upper         0.062
##   P-value RMSEA <= 0.05                          0.620
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.042
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Latent Variables:
##                          Estimate  Std.Err  z-value  P(>|z|)
##   ProgramQuality =~                                         
##     PA2                     0.668    0.050   13.249    0.000
##     PA5                     0.875    0.054   16.086    0.000
##     PA7                     0.790    0.051   15.397    0.000
##     PA12                    0.850    0.061   13.849    0.000
##   FacultyAssistance =~                                      
##     SA1                     0.820    0.048   17.253    0.000
##     SA2                     0.843    0.046   18.144    0.000
##     SA3                     0.861    0.048   17.984    0.000
##     SA13                    0.757    0.051   14.787    0.000
##   StudentSatisfaction =~                                    
##     IS2                     0.780    0.068   11.402    0.000
##     IS4                     0.804    0.074   10.915    0.000
##   CurrentEmployment =~                                      
##     Career_day_hlp          0.189    0.081    2.344    0.019
##     Relation                0.072    0.040    1.774    0.076
##     Cur_salar               0.054    0.041    1.314    0.189
## 
## Covariances:
##                          Estimate  Std.Err  z-value  P(>|z|)
##   ProgramQuality ~~                                         
##     FacultyAssstnc          0.614    0.044   13.986    0.000
##     StudentStsfctn          0.407    0.065    6.284    0.000
##     CurrntEmplymnt         -0.309    0.161   -1.918    0.055
##   FacultyAssistance ~~                                      
##     StudentStsfctn          0.579    0.054   10.668    0.000
##     CurrntEmplymnt         -0.394    0.173   -2.272    0.023
##   StudentSatisfaction ~~                                    
##     CurrntEmplymnt         -0.326    0.175   -1.861    0.063
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .PA2               0.479    0.045   10.574    0.000
##    .PA5               0.425    0.050    8.582    0.000
##    .PA7               0.410    0.045    9.207    0.000
##    .PA12              0.680    0.066   10.267    0.000
##    .SA1               0.329    0.034    9.645    0.000
##    .SA2               0.280    0.031    8.900    0.000
##    .SA3               0.303    0.034    9.047    0.000
##    .SA13              0.483    0.044   10.936    0.000
##    .IS2               0.474    0.083    5.712    0.000
##    .IS4               0.649    0.094    6.911    0.000
##    .Career_day_hlp    0.173    0.032    5.389    0.000
##    .Relation          0.145    0.012   11.616    0.000
##    .Cur_salar         0.156    0.013   12.124    0.000
##     ProgramQuality    1.000                           
##     FacultyAssstnc    1.000                           
##     StudentStsfctn    1.000                           
##     CurrntEmplymnt    1.000

Model 4 Estimation and results

m4<-  'Program Quality =~ PA2+PA5+PA7+PA12
Faculty Assistance =~ SA1+SA2+SA3+SA13
Student Satisfaction =~ IS2+IS3+IS4
Current Employment =~ Career_day+Cur_salar'

fourfactor_3<- cfa(m4, data=df, std.lv=TRUE)
summary(fourfactor_3, fit.measures=TRUE)
## lavaan 0.6-7 ended normally after 44 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of free parameters                         32
##                                                       
##                                                   Used       Total
##   Number of observations                           320         336
##                                                                   
## Model Test User Model:
##                                                       
##   Test statistic                               134.045
##   Degrees of freedom                                59
##   P-value (Chi-square)                           0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                              1789.315
##   Degrees of freedom                                78
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.956
##   Tucker-Lewis Index (TLI)                       0.942
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -4683.259
##   Loglikelihood unrestricted model (H1)      -4616.236
##                                                       
##   Akaike (AIC)                                9430.517
##   Bayesian (BIC)                              9551.104
##   Sample-size adjusted Bayesian (BIC)         9449.605
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.063
##   90 Percent confidence interval - lower         0.049
##   90 Percent confidence interval - upper         0.077
##   P-value RMSEA <= 0.05                          0.063
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.052
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Latent Variables:
##                          Estimate  Std.Err  z-value  P(>|z|)
##   ProgramQuality =~                                         
##     PA2                     0.664    0.050   13.166    0.000
##     PA5                     0.877    0.054   16.166    0.000
##     PA7                     0.787    0.051   15.326    0.000
##     PA12                    0.854    0.061   13.932    0.000
##   FacultyAssistance =~                                      
##     SA1                     0.821    0.048   17.253    0.000
##     SA2                     0.841    0.047   18.054    0.000
##     SA3                     0.861    0.048   17.983    0.000
##     SA13                    0.760    0.051   14.862    0.000
##   StudentSatisfaction =~                                    
##     IS2                     0.796    0.056   14.245    0.000
##     IS3                     0.856    0.062   13.793    0.000
##     IS4                     0.832    0.062   13.497    0.000
##   CurrentEmployment =~                                      
##     Career_day              0.217    0.141    1.536    0.125
##     Cur_salar              -0.042    0.035   -1.204    0.229
## 
## Covariances:
##                          Estimate  Std.Err  z-value  P(>|z|)
##   ProgramQuality ~~                                         
##     FacultyAssstnc          0.614    0.044   13.988    0.000
##     StudentStsfctn          0.361    0.061    5.865    0.000
##     CurrntEmplymnt          0.374    0.256    1.464    0.143
##   FacultyAssistance ~~                                      
##     StudentStsfctn          0.520    0.052   10.029    0.000
##     CurrntEmplymnt          0.334    0.232    1.437    0.151
##   StudentSatisfaction ~~                                    
##     CurrntEmplymnt          0.467    0.309    1.512    0.131
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .PA2               0.483    0.046   10.621    0.000
##    .PA5               0.420    0.049    8.521    0.000
##    .PA7               0.415    0.045    9.281    0.000
##    .PA12              0.674    0.066   10.231    0.000
##    .SA1               0.329    0.034    9.617    0.000
##    .SA2               0.284    0.032    8.950    0.000
##    .SA3               0.303    0.034    9.015    0.000
##    .SA13              0.479    0.044   10.893    0.000
##    .IS2               0.449    0.056    8.062    0.000
##    .IS3               0.590    0.069    8.607    0.000
##    .IS4               0.605    0.068    8.936    0.000
##    .Career_day        0.120    0.061    1.965    0.049
##    .Cur_salar         0.157    0.013   12.437    0.000
##     ProgramQuality    1.000                           
##     FacultyAssstnc    1.000                           
##     StudentStsfctn    1.000                           
##     CurrntEmplymnt    1.000

Model 5 Estimation and results

m5<-  'Program Quality =~ PA2+PA5+PA7+PA12
Faculty Assistance =~ SA1+SA2+SA3+SA13
Student Satisfaction =~ IS2+IS3+IS4
Current Employment =~ Relation+Cur_salar'

fourfactor_4<- cfa(m5, data=df, std.lv=TRUE)
summary(fourfactor_4, fit.measures=TRUE)
## lavaan 0.6-7 ended normally after 57 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of free parameters                         32
##                                                       
##                                                   Used       Total
##   Number of observations                           320         336
##                                                                   
## Model Test User Model:
##                                                       
##   Test statistic                               124.278
##   Degrees of freedom                                59
##   P-value (Chi-square)                           0.000
## 
## Model Test Baseline Model:
## 
##   Test statistic                              1762.310
##   Degrees of freedom                                78
##   P-value                                        0.000
## 
## User Model versus Baseline Model:
## 
##   Comparative Fit Index (CFI)                    0.961
##   Tucker-Lewis Index (TLI)                       0.949
## 
## Loglikelihood and Information Criteria:
## 
##   Loglikelihood user model (H0)              -4674.205
##   Loglikelihood unrestricted model (H1)      -4612.066
##                                                       
##   Akaike (AIC)                                9412.409
##   Bayesian (BIC)                              9532.996
##   Sample-size adjusted Bayesian (BIC)         9431.497
## 
## Root Mean Square Error of Approximation:
## 
##   RMSEA                                          0.059
##   90 Percent confidence interval - lower         0.044
##   90 Percent confidence interval - upper         0.073
##   P-value RMSEA <= 0.05                          0.151
## 
## Standardized Root Mean Square Residual:
## 
##   SRMR                                           0.050
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Latent Variables:
##                          Estimate  Std.Err  z-value  P(>|z|)
##   ProgramQuality =~                                         
##     PA2                     0.667    0.050   13.242    0.000
##     PA5                     0.874    0.054   16.085    0.000
##     PA7                     0.791    0.051   15.450    0.000
##     PA12                    0.849    0.061   13.826    0.000
##   FacultyAssistance =~                                      
##     SA1                     0.821    0.048   17.253    0.000
##     SA2                     0.841    0.047   18.042    0.000
##     SA3                     0.861    0.048   17.999    0.000
##     SA13                    0.760    0.051   14.858    0.000
##   StudentSatisfaction =~                                    
##     IS2                     0.791    0.056   14.094    0.000
##     IS3                     0.860    0.062   13.840    0.000
##     IS4                     0.834    0.062   13.498    0.000
##   CurrentEmployment =~                                      
##     Relation                0.116    0.088    1.326    0.185
##     Cur_salar               0.065    0.053    1.240    0.215
## 
## Covariances:
##                          Estimate  Std.Err  z-value  P(>|z|)
##   ProgramQuality ~~                                         
##     FacultyAssstnc          0.614    0.044   13.974    0.000
##     StudentStsfctn          0.358    0.062    5.823    0.000
##     CurrntEmplymnt         -0.385    0.287   -1.341    0.180
##   FacultyAssistance ~~                                      
##     StudentStsfctn          0.519    0.052    9.996    0.000
##     CurrntEmplymnt         -0.173    0.203   -0.855    0.392
##   StudentSatisfaction ~~                                    
##     CurrntEmplymnt         -0.112    0.198   -0.564    0.573
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .PA2               0.480    0.045   10.586    0.000
##    .PA5               0.426    0.049    8.603    0.000
##    .PA7               0.407    0.044    9.179    0.000
##    .PA12              0.682    0.066   10.290    0.000
##    .SA1               0.329    0.034    9.617    0.000
##    .SA2               0.285    0.032    8.960    0.000
##    .SA3               0.302    0.034    8.999    0.000
##    .SA13              0.479    0.044   10.895    0.000
##    .IS2               0.457    0.056    8.132    0.000
##    .IS3               0.582    0.069    8.448    0.000
##    .IS4               0.601    0.068    8.845    0.000
##    .Relation          0.136    0.023    6.039    0.000
##    .Cur_salar         0.155    0.014   11.257    0.000
##     ProgramQuality    1.000                           
##     FacultyAssstnc    1.000                           
##     StudentStsfctn    1.000                           
##     CurrntEmplymnt    1.000

Generate Plot of selected model

#1. Conduct a Path Analysis for all the variables

# create a correlation matrix
#We will use a Factor_Analysis Data with contains only the needed items from our Dataframe
library(semPlot)
## Registered S3 methods overwritten by 'huge':
##   method    from   
##   plot.sim  BDgraph
##   print.sim BDgraph
df <- read_csv("/home/asma/Desktop/CFA_FINAL/Factor_Analysis.csv")
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   .default = col_double()
## )
## ℹ Use `spec()` for the full column specifications.
covariance_matrix <- round(cov(df[,]),2)
model <- 'PA1~ PA2+PA3+PA4+PA5+PA6+PA7+PA8+PA9+PA10+PA11+PA12+PA13+PA14+GA1+GA2+GA3+GA4
    SA1~ SA2+SA3+SA4+SA5+SA6+SA7+SA8+SA9+SA10+SA11+SA12+SA13
IS1~ IS2+IS3+IS4+IS5+IS6+IS7+IS8+IS9+IS10+IS11+IS12
Cur_salar~ sector_work_class+Career_day+Career_day_help+Relation+Cur_salar'
fit <- cfa(model, data=df, std.lv=TRUE)
## 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.
semPaths(fit, intercept = FALSE, whatLabel = "est", residuals = FALSE, exoCov = FALSE, layout = 'tree')

#1. Conduct a Path Analysis for the selected best model

# create a correlation matrix

library(semPlot)
df <- read_csv("/home/asma/Desktop/CFA_FINAL/Factor_Analysis.csv")
## 
## ── Column specification ────────────────────────────────────────────────────────
## cols(
##   .default = col_double()
## )
## ℹ Use `spec()` for the full column specifications.
covariance_matrix <- round(cov(df[,]),2)
model <-'PA1~ PA2+PA5+PA7+PA12
SA1~ SA2+SA3+SA13
IS2~ IS3+IS4
Cur_salar~ Career_day+Cur_salar'
fit <- cfa(model, data=df, std.lv=TRUE)
## 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.
summary(fit)
## lavaan 0.6-7 ended normally after 22 iterations
## 
##   Estimator                                         ML
##   Optimization method                           NLMINB
##   Number of free parameters                         18
##                                                       
##   Number of observations                           336
##                                                       
## Model Test User Model:
##                                                       
##   Test statistic                                74.607
##   Degrees of freedom                                32
##   P-value (Chi-square)                           0.000
## 
## Parameter Estimates:
## 
##   Standard errors                             Standard
##   Information                                 Expected
##   Information saturated (h1) model          Structured
## 
## Regressions:
##                    Estimate  Std.Err  z-value  P(>|z|)
##   PA1 ~                                               
##     PA2               0.239       NA                  
##     PA5               0.057       NA                  
##     PA7               0.359       NA                  
##     PA12              0.101       NA                  
##   SA1 ~                                               
##     SA2               0.318       NA                  
##     SA3               0.290       NA                  
##     SA13              0.233       NA                  
##   IS2 ~                                               
##     IS3               0.368       NA                  
##     IS4               0.267       NA                  
##   Cur_salar ~                                         
##     Career_day        0.261       NA                  
##     Cur_salar         0.962       NA                  
## 
## Covariances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##  .PA1 ~~                                              
##    .SA1               0.047       NA                  
##    .IS2               0.052       NA                  
##  .SA1 ~~                                              
##    .IS2               0.000       NA                  
## 
## Variances:
##                    Estimate  Std.Err  z-value  P(>|z|)
##    .PA1               0.483       NA                  
##    .SA1               0.407       NA                  
##    .IS2               0.623       NA                  
##    .Cur_salar         1.201       NA
semPaths(fit, intercept = FALSE, whatLabel = "est", residuals = FALSE, exoCov = FALSE, layout = 'tree')

#2. Conduct a Structure Equation Analysis for the selected best model

library(semPlot)
library(lavaanPlot)
semPaths(fourfactor_3, 'std', layout = 'tree')