1. I have a definite sense of purpose in life.
  2. I have a firm sense of who I am.
  3. I have a set of basic beliefs and values that guide my actions and decisions.
  4. I know what I want out of life.
  5. I have a clear set of personal values or moral standards.
  6. I don’t know where I fit in the world.
  7. I have specific personal goals for the future.
  8. I have a clear sense of who I want to be when I am an adult.
##load packages
library(psych)
library(GPArotation)
library(plyr)
library(dplyr)
## 
## Attaching package: 'dplyr'
## 
## The following objects are masked from 'package:plyr':
## 
##     arrange, count, desc, failwith, id, mutate, rename, summarise,
##     summarize
## 
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## 
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(lavaan)
## This is lavaan 0.5-18
## lavaan is BETA software! Please report any bugs.
library(semPlot)
# data preparation
data <- read.csv("~/Psychometric_study_data/allsurveysYT1.csv")
APSI<-select(data,  APSI_1,  APSI_2,  APSI_3,  APSI_4,  APSI_5,  APSI_6, APSI_7,  APSI_8)
APSI$APSI_6  <-  6- APSI$APSI_6
APSI<- data.frame(apply(APSI,2, as.numeric))
str(APSI)
## 'data.frame':    1160 obs. of  8 variables:
##  $ APSI_1: num  2 4 3 4 3 3 2 3 4 2 ...
##  $ APSI_2: num  4 3 4 4 3 4 2 3 5 2 ...
##  $ APSI_3: num  4 4 4 5 4 4 4 4 5 2 ...
##  $ APSI_4: num  4 5 3 4 3 4 3 3 4 3 ...
##  $ APSI_5: num  4 4 3 5 4 4 4 5 4 5 ...
##  $ APSI_6: num  2 3 3 2 3 4 2 3 4 3 ...
##  $ APSI_7: num  4 4 4 4 2 5 2 3 4 3 ...
##  $ APSI_8: num  4 4 3 3 3 3 2 1 5 4 ...
colnames(APSI) <- c("1","2", "3", "4", "5", "6", "7", "8")
 APSI<- APSI[complete.cases(APSI[,]),]

EFA

number of factors

parallal analysis and scree plot

parallel<-fa.parallel(APSI, fm="ml",fa="fa")

## Parallel analysis suggests that the number of factors =  4  and the number of components =  NA
#one factors are greater than one Eigenvalue scree plot says there are two factors. Paralel analysis suggests 4 factors
#eigenvalues (kaiser)
parallel$fa.values
## [1]  3.71026027  0.31121722  0.17831591  0.06475669 -0.01509740 -0.03752899
## [7] -0.09337925 -0.41215276
#over 1=1, over .7=0

doing aprincipal components analysis to see how many factors there might be using that method

Deal with NA doing principle componant analysis

princomp(na.omit(APSI), cor = TRUE)
## Call:
## princomp(x = na.omit(APSI), cor = TRUE)
## 
## Standard deviations:
##    Comp.1    Comp.2    Comp.3    Comp.4    Comp.5    Comp.6    Comp.7 
## 2.0258496 1.1268011 0.8998140 0.7399972 0.5935047 0.5654095 0.5500070 
##    Comp.8 
## 0.5427228 
## 
##  8  variables and  807 observations.
parallel2<-princomp(na.omit(APSI), cor = TRUE)
summary(parallel2)
## Importance of components:
##                           Comp.1    Comp.2    Comp.3     Comp.4     Comp.5
## Standard deviation     2.0258496 1.1268011 0.8998140 0.73999725 0.59350472
## Proportion of Variance 0.5130083 0.1587101 0.1012082 0.06844949 0.04403098
## Cumulative Proportion  0.5130083 0.6717184 0.7729266 0.84137605 0.88540703
##                            Comp.6     Comp.7    Comp.8
## Standard deviation     0.56540954 0.55000704 0.5427228
## Proportion of Variance 0.03996099 0.03781347 0.0368185
## Cumulative Proportion  0.92536803 0.96318150 1.0000000
plot(parallel2)##results show at least two factors

#simple structure

twofactor<-fa(APSI, nfactors=2, rotate="oblimin", fm="ml")
twofactor#not a good fit
## Factor Analysis using method =  ml
## Call: fa(r = APSI, nfactors = 2, rotate = "oblimin", fm = "ml")
## Standardized loadings (pattern matrix) based upon correlation matrix
##     ML2   ML1    h2    u2 com
## 1  0.83 -0.03 0.686 0.314 1.0
## 2  0.76  0.00 0.580 0.420 1.0
## 3  0.00  1.00 0.995 0.005 1.0
## 4  0.83 -0.03 0.678 0.322 1.0
## 5  0.63  0.18 0.487 0.513 1.2
## 6 -0.15  0.31 0.099 0.901 1.4
## 7  0.77  0.03 0.597 0.403 1.0
## 8  0.82 -0.04 0.664 0.336 1.0
## 
##                        ML2  ML1
## SS loadings           3.65 1.13
## Proportion Var        0.46 0.14
## Cumulative Var        0.46 0.60
## Proportion Explained  0.76 0.24
## Cumulative Proportion 0.76 1.00
## 
##  With factor correlations of 
##      ML2  ML1
## ML2 1.00 0.22
## ML1 0.22 1.00
## 
## Mean item complexity =  1.1
## Test of the hypothesis that 2 factors are sufficient.
## 
## The degrees of freedom for the null model are  28  and the objective function was  3.76 with Chi Square of  3020.93
## The degrees of freedom for the model are 13  and the objective function was  0.19 
## 
## The root mean square of the residuals (RMSR) is  0.04 
## The df corrected root mean square of the residuals is  0.06 
## 
## The harmonic number of observations is  807 with the empirical chi square  82.96  with prob <  3.1e-12 
## The total number of observations was  807  with MLE Chi Square =  151.85  with prob <  8.7e-26 
## 
## Tucker Lewis Index of factoring reliability =  0.9
## RMSEA index =  0.115  and the 90 % confidence intervals are  0.099 0.132
## BIC =  64.83
## Fit based upon off diagonal values = 0.99
## Measures of factor score adequacy             
##                                                 ML2  ML1
## Correlation of scores with factors             0.95 1.00
## Multiple R square of scores with factors       0.91 0.99
## Minimum correlation of possible factor scores  0.82 0.99
1-((twofactor$STATISTIC - twofactor$dof)/(twofactor$null.chisq- twofactor$null.dof))
## [1] 0.9536082
threefactor<-fa(APSI, nfactors=3, rotate="oblimin", fm="ml")
threefactor#Still not a great fit. 1, 2, 4, 7, 8 are one factor 3 and 5 seem to be thir own factors and 6 crossloads on all factors. 
## Factor Analysis using method =  ml
## Call: fa(r = APSI, nfactors = 3, rotate = "oblimin", fm = "ml")
## Standardized loadings (pattern matrix) based upon correlation matrix
##     ML2   ML1   ML3   h2    u2 com
## 1  0.73 -0.03  0.13 0.67 0.330 1.1
## 2  0.61 -0.01  0.21 0.58 0.425 1.2
## 3 -0.01  0.99  0.03 1.00 0.005 1.0
## 4  0.86  0.00 -0.04 0.70 0.299 1.0
## 5  0.08  0.07  0.84 0.84 0.159 1.0
## 6  0.13  0.36 -0.39 0.18 0.822 2.2
## 7  0.80  0.05 -0.04 0.62 0.383 1.0
## 8  0.85 -0.02 -0.03 0.68 0.320 1.0
## 
##                        ML2  ML1  ML3
## SS loadings           3.13 1.11 1.01
## Proportion Var        0.39 0.14 0.13
## Cumulative Var        0.39 0.53 0.66
## Proportion Explained  0.60 0.21 0.19
## Cumulative Proportion 0.60 0.81 1.00
## 
##  With factor correlations of 
##      ML2  ML1  ML3
## ML2 1.00 0.19 0.66
## ML1 0.19 1.00 0.26
## ML3 0.66 0.26 1.00
## 
## Mean item complexity =  1.2
## Test of the hypothesis that 3 factors are sufficient.
## 
## The degrees of freedom for the null model are  28  and the objective function was  3.76 with Chi Square of  3020.93
## The degrees of freedom for the model are 7  and the objective function was  0.08 
## 
## The root mean square of the residuals (RMSR) is  0.02 
## The df corrected root mean square of the residuals is  0.05 
## 
## The harmonic number of observations is  807 with the empirical chi square  23.99  with prob <  0.0011 
## The total number of observations was  807  with MLE Chi Square =  62.73  with prob <  4.3e-11 
## 
## Tucker Lewis Index of factoring reliability =  0.925
## RMSEA index =  0.1  and the 90 % confidence intervals are  0.078 0.123
## BIC =  15.88
## Fit based upon off diagonal values = 1
## Measures of factor score adequacy             
##                                                 ML2  ML1  ML3
## Correlation of scores with factors             0.95 1.00 0.92
## Multiple R square of scores with factors       0.91 0.99 0.85
## Minimum correlation of possible factor scores  0.81 0.99 0.70
1-((threefactor$STATISTIC - threefactor$dof)/(threefactor$null.chisq- threefactor$null.dof))
## [1] 0.9813797
fourfactor<-fa(APSI, nfactors=4, rotate="oblimin", fm="ml")
fourfactor#An over fit
## Factor Analysis using method =  ml
## Call: fa(r = APSI, nfactors = 4, rotate = "oblimin", fm = "ml")
## Standardized loadings (pattern matrix) based upon correlation matrix
##    ML2   ML4   ML1   ML3   h2    u2 com
## 1 0.32  0.57  0.01 -0.03 0.70 0.299 1.6
## 2 0.03  0.81  0.04  0.00 0.70 0.302 1.0
## 3 0.03 -0.01  0.14  0.67 0.51 0.486 1.1
## 4 0.67  0.21  0.04 -0.04 0.69 0.307 1.2
## 5 0.07  0.52 -0.20  0.37 0.63 0.370 2.2
## 6 0.00  0.01  0.99  0.03 1.00 0.005 1.0
## 7 0.90 -0.11 -0.03  0.07 0.71 0.287 1.0
## 8 0.65  0.22  0.00 -0.05 0.67 0.327 1.2
## 
##                        ML2  ML4  ML1  ML3
## SS loadings           2.14 1.75 1.06 0.66
## Proportion Var        0.27 0.22 0.13 0.08
## Cumulative Var        0.27 0.49 0.62 0.70
## Proportion Explained  0.38 0.31 0.19 0.12
## Cumulative Proportion 0.38 0.69 0.88 1.00
## 
##  With factor correlations of 
##       ML2   ML4   ML1  ML3
## ML2  1.00  0.78 -0.08 0.27
## ML4  0.78  1.00 -0.10 0.28
## ML1 -0.08 -0.10  1.00 0.17
## ML3  0.27  0.28  0.17 1.00
## 
## Mean item complexity =  1.3
## Test of the hypothesis that 4 factors are sufficient.
## 
## The degrees of freedom for the null model are  28  and the objective function was  3.76 with Chi Square of  3020.93
## The degrees of freedom for the model are 2  and the objective function was  0 
## 
## The root mean square of the residuals (RMSR) is  0 
## The df corrected root mean square of the residuals is  0.01 
## 
## The harmonic number of observations is  807 with the empirical chi square  0.24  with prob <  0.89 
## The total number of observations was  807  with MLE Chi Square =  1.12  with prob <  0.57 
## 
## Tucker Lewis Index of factoring reliability =  1.004
## RMSEA index =  0  and the 90 % confidence intervals are  NA 0.059
## BIC =  -12.27
## Fit based upon off diagonal values = 1
## Measures of factor score adequacy             
##                                                 ML2  ML4  ML1  ML3
## Correlation of scores with factors             0.94 0.92 1.00 0.77
## Multiple R square of scores with factors       0.88 0.85 0.99 0.60
## Minimum correlation of possible factor scores  0.76 0.71 0.99 0.20
1-((fourfactor$STATISTIC - fourfactor$dof)/(fourfactor$null.chisq- fourfactor$null.dof))
## [1] 1.000295
fa2latex(fa(APSI,2, rotate="oblimin", fm="ml"),heading="Table 2. Factor Loadings for Exploratory Factor Analysis with Oblimin Rotation 
of APSI")
## % Called in the psych package  fa2latex % Called in the psych package  fa(APSI, 2, rotate = "oblimin", fm = "ml") % Called in the psych package  Table 2. Factor Loadings for Exploratory Factor Analysis with Oblimin Rotation 
## of APSI 
## \begin{table}[htdp]\caption{fa2latex}
## \begin{center}
## \begin{scriptsize} 
## \begin{tabular} {l r r r r r }
##  \multicolumn{ 5 }{l}{ Table 2. Factor Loadings for Exploratory Factor Analysis with Oblimin Rotation 
## of APSI } \cr 
##  \hline Variable  &   ML2  &  ML1  &  h2  &  u2  &  com \cr 
##   \hline 
## 1   &  \bf{ 0.83}  &  -0.03  &  0.69  &  0.31  &  1.00 \cr 
##  2   &  \bf{ 0.76}  &   0.00  &  0.58  &  0.42  &  1.00 \cr 
##  3   &   0.00  &  \bf{ 1.00}  &  1.00  &  0.00  &  1.00 \cr 
##  4   &  \bf{ 0.83}  &  -0.03  &  0.68  &  0.32  &  1.00 \cr 
##  5   &  \bf{ 0.63}  &   0.18  &  0.49  &  0.51  &  1.17 \cr 
##  6   &  -0.15  &  \bf{ 0.31}  &  0.10  &  0.90  &  1.43 \cr 
##  7   &  \bf{ 0.77}  &   0.03  &  0.60  &  0.40  &  1.00 \cr 
##  8   &  \bf{ 0.82}  &  -0.04  &  0.66  &  0.34  &  1.01 \cr 
## \hline \cr SS loadings & 3.65 &  1.13 &  \cr  
## \cr 
##             \hline \cr 
## ML2   & 1.00 & 0.22 \cr 
##  ML1   & 0.22 & 1.00 \cr 
##  \hline 
## \end{tabular}
## \end{scriptsize}
## \end{center}
## \label{default}
## \end{table}
fa2latex(fa(APSI,3, rotate="oblimin", fm="ml"),heading="Table 3. Factor Loadings for Exploratory Factor Analysis with Oblimin Rotation 
of APSI")
## % Called in the psych package  fa2latex % Called in the psych package  fa(APSI, 3, rotate = "oblimin", fm = "ml") % Called in the psych package  Table 3. Factor Loadings for Exploratory Factor Analysis with Oblimin Rotation 
## of APSI 
## \begin{table}[htdp]\caption{fa2latex}
## \begin{center}
## \begin{scriptsize} 
## \begin{tabular} {l r r r r r r }
##  \multicolumn{ 6 }{l}{ Table 3. Factor Loadings for Exploratory Factor Analysis with Oblimin Rotation 
## of APSI } \cr 
##  \hline Variable  &   ML2  &  ML1  &  ML3  &  h2  &  u2  &  com \cr 
##   \hline 
## 1   &  \bf{ 0.73}  &  -0.03  &   0.13  &  0.67  &  0.33  &  1.07 \cr 
##  2   &  \bf{ 0.61}  &  -0.01  &   0.21  &  0.58  &  0.42  &  1.23 \cr 
##  3   &  -0.01  &  \bf{ 0.99}  &   0.03  &  1.00  &  0.00  &  1.00 \cr 
##  4   &  \bf{ 0.86}  &   0.00  &  -0.04  &  0.70  &  0.30  &  1.00 \cr 
##  5   &   0.08  &   0.07  &  \bf{ 0.84}  &  0.84  &  0.16  &  1.03 \cr 
##  6   &   0.13  &  \bf{ 0.36}  &  \bf{-0.39}  &  0.18  &  0.82  &  2.21 \cr 
##  7   &  \bf{ 0.80}  &   0.05  &  -0.04  &  0.62  &  0.38  &  1.01 \cr 
##  8   &  \bf{ 0.85}  &  -0.02  &  -0.03  &  0.68  &  0.32  &  1.00 \cr 
## \hline \cr SS loadings & 3.13 &  1.11 &  1.01 &  \cr  
## \cr 
##             \hline \cr 
## ML2   & 1.00 & 0.19 & 0.66 \cr 
##  ML1   & 0.19 & 1.00 & 0.26 \cr 
##  ML3   & 0.66 & 0.26 & 1.00 \cr 
##  \hline 
## \end{tabular}
## \end{scriptsize}
## \end{center}
## \label{default}
## \end{table}
fa2latex(fa(APSI,4, rotate="oblimin", fm="ml"),heading="Table 4. Factor Loadings for Exploratory Factor Analysis with Oblimin Rotation 
of APSI")
## % Called in the psych package  fa2latex % Called in the psych package  fa(APSI, 4, rotate = "oblimin", fm = "ml") % Called in the psych package  Table 4. Factor Loadings for Exploratory Factor Analysis with Oblimin Rotation 
## of APSI 
## \begin{table}[htdp]\caption{fa2latex}
## \begin{center}
## \begin{scriptsize} 
## \begin{tabular} {l r r r r r r r }
##  \multicolumn{ 7 }{l}{ Table 4. Factor Loadings for Exploratory Factor Analysis with Oblimin Rotation 
## of APSI } \cr 
##  \hline Variable  &   ML2  &  ML4  &  ML1  &  ML3  &  h2  &  u2  &  com \cr 
##   \hline 
## 1   &  \bf{0.32}  &  \bf{ 0.57}  &   0.01  &  -0.03  &  0.70  &  0.30  &  1.59 \cr 
##  2   &  0.03  &  \bf{ 0.81}  &   0.04  &   0.00  &  0.70  &  0.30  &  1.01 \cr 
##  3   &  0.03  &  -0.01  &   0.14  &  \bf{ 0.67}  &  0.51  &  0.49  &  1.10 \cr 
##  4   &  \bf{0.67}  &   0.21  &   0.04  &  -0.04  &  0.69  &  0.31  &  1.22 \cr 
##  5   &  0.07  &  \bf{ 0.52}  &  -0.20  &  \bf{ 0.37}  &  0.63  &  0.37  &  2.18 \cr 
##  6   &  0.00  &   0.01  &  \bf{ 0.99}  &   0.03  &  1.00  &  0.00  &  1.00 \cr 
##  7   &  \bf{0.90}  &  -0.11  &  -0.03  &   0.07  &  0.71  &  0.29  &  1.04 \cr 
##  8   &  \bf{0.65}  &   0.22  &   0.00  &  -0.05  &  0.67  &  0.33  &  1.25 \cr 
## \hline \cr SS loadings & 2.14 &  1.75 &  1.06 &  0.66 &  \cr  
## \cr 
##             \hline \cr 
## ML2   &  1.00 &  0.78 & -0.08 &  0.27 \cr 
##  ML4   &  0.78 &  1.00 & -0.10 &  0.28 \cr 
##  ML1   & -0.08 & -0.10 &  1.00 &  0.17 \cr 
##  ML3   &  0.27 &  0.28 &  0.17 &  1.00 \cr 
##  \hline 
## \end{tabular}
## \end{scriptsize}
## \end{center}
## \label{default}
## \end{table}

question 1,4,7,8 seem to talk about purpose. so try as one factr

 APSI12478<-select(APSI, 1, 2, 4,7,8)
 APSI12478<-tbl_df(APSI12478)
  APSI12478
## Source: local data frame [807 x 5]
## 
##    1 2 4 7 8
## 1  2 4 4 4 4
## 2  4 3 5 4 4
## 3  3 4 3 4 3
## 4  4 4 4 4 3
## 5  3 3 3 2 3
## 6  3 4 4 5 3
## 7  2 2 3 2 2
## 8  3 3 3 3 1
## 9  4 5 4 4 5
## 10 2 2 3 3 4
## .. . . . . .
twofactorAPSI12478<-fa(APSI12478, nfactors=1, rotate="varimax", fm="ml")
twofactorAPSI12478#The TLI is good but the RMSEA is a poor fit
## Factor Analysis using method =  ml
## Call: fa(r = APSI12478, nfactors = 1, rotate = "varimax", fm = "ml")
## Standardized loadings (pattern matrix) based upon correlation matrix
##    ML1   h2   u2 com
## 1 0.82 0.67 0.33   1
## 2 0.75 0.56 0.44   1
## 4 0.83 0.69 0.31   1
## 7 0.78 0.61 0.39   1
## 8 0.82 0.68 0.32   1
## 
##                 ML1
## SS loadings    3.20
## Proportion Var 0.64
## 
## Mean item complexity =  1
## Test of the hypothesis that 1 factor is sufficient.
## 
## The degrees of freedom for the null model are  10  and the objective function was  2.92 with Chi Square of  2344.37
## The degrees of freedom for the model are 5  and the objective function was  0.07 
## 
## The root mean square of the residuals (RMSR) is  0.03 
## The df corrected root mean square of the residuals is  0.05 
## 
## The harmonic number of observations is  807 with the empirical chi square  18.3  with prob <  0.0026 
## The total number of observations was  807  with MLE Chi Square =  59.33  with prob <  1.7e-11 
## 
## Tucker Lewis Index of factoring reliability =  0.953
## RMSEA index =  0.116  and the 90 % confidence intervals are  0.091 0.143
## BIC =  25.86
## Fit based upon off diagonal values = 1
## Measures of factor score adequacy             
##                                                 ML1
## Correlation of scores with factors             0.95
## Multiple R square of scores with factors       0.90
## Minimum correlation of possible factor scores  0.80
fa2latex(fa(APSI12478,1, rotate="oblimin", fm="ml"),heading="Table 5. Factor Loadings for Exploratory Factor Analysis with Oblimin Rotation
of APSI")
## % Called in the psych package  fa2latex % Called in the psych package  fa(APSI12478, 1, rotate = "oblimin", fm = "ml") % Called in the psych package  Table 5. Factor Loadings for Exploratory Factor Analysis with Oblimin Rotation
## of APSI 
## \begin{table}[htdp]\caption{fa2latex}
## \begin{center}
## \begin{scriptsize} 
## \begin{tabular} {l r r r r }
##  \multicolumn{ 4 }{l}{ Table 5. Factor Loadings for Exploratory Factor Analysis with Oblimin Rotation
## of APSI } \cr 
##  \hline Variable  &   ML1  &  ML1.1  &  ML1.2  &  com \cr 
##   \hline 
## 1   &  \bf{0.82}  &  0.67  &  0.33  &  1 \cr 
##  2   &  \bf{0.75}  &  0.56  &  0.44  &  1 \cr 
##  4   &  \bf{0.83}  &  0.69  &  0.31  &  1 \cr 
##  7   &  \bf{0.78}  &  0.61  &  0.39  &  1 \cr 
##  8   &  \bf{0.82}  &  0.68  &  0.32  &  1 \cr 
## \hline \cr SS loadings & 3.2 &  \cr  
##  \hline 
## \end{tabular}
## \end{scriptsize}
## \end{center}
## \label{default}
## \end{table}
#CFI
1-((twofactorAPSI12478$STATISTIC - twofactorAPSI12478$dof)/(twofactorAPSI12478$null.chisq- twofactorAPSI12478$null.dof))
## [1] 0.9767281

question 1,4,7,8 seem to talk about purpose. so try as one factr

 APSI124578<-select(APSI, 1, 2, 4,5, 7,8)
APSI124578<-tbl_df(APSI124578)
APSI124578
## Source: local data frame [807 x 6]
## 
##    1 2 4 5 7 8
## 1  2 4 4 4 4 4
## 2  4 3 5 4 4 4
## 3  3 4 3 3 4 3
## 4  4 4 4 5 4 3
## 5  3 3 3 4 2 3
## 6  3 4 4 4 5 3
## 7  2 2 3 4 2 2
## 8  3 3 3 5 3 1
## 9  4 5 4 4 4 5
## 10 2 2 3 5 3 4
## .. . . . . . .
twofactorAPSI124578<-fa(APSI124578, nfactors=1, rotate="varimax", fm="ml")
twofactorAPSI124578#The TLI is good but the RMSEA is a poor fit
## Factor Analysis using method =  ml
## Call: fa(r = APSI124578, nfactors = 1, rotate = "varimax", fm = "ml")
## Standardized loadings (pattern matrix) based upon correlation matrix
##    ML1   h2   u2 com
## 1 0.83 0.69 0.31   1
## 2 0.76 0.58 0.42   1
## 4 0.82 0.68 0.32   1
## 5 0.67 0.45 0.55   1
## 7 0.77 0.60 0.40   1
## 8 0.81 0.66 0.34   1
## 
##                 ML1
## SS loadings    3.65
## Proportion Var 0.61
## 
## Mean item complexity =  1
## Test of the hypothesis that 1 factor is sufficient.
## 
## The degrees of freedom for the null model are  15  and the objective function was  3.46 with Chi Square of  2781.19
## The degrees of freedom for the model are 9  and the objective function was  0.11 
## 
## 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  807 with the empirical chi square  31.55  with prob <  0.00024 
## The total number of observations was  807  with MLE Chi Square =  87.16  with prob <  6e-15 
## 
## Tucker Lewis Index of factoring reliability =  0.953
## RMSEA index =  0.104  and the 90 % confidence intervals are  0.085 0.124
## BIC =  26.92
## Fit based upon off diagonal values = 1
## Measures of factor score adequacy             
##                                                 ML1
## Correlation of scores with factors             0.95
## Multiple R square of scores with factors       0.91
## Minimum correlation of possible factor scores  0.82
fa2latex(fa(APSI124578,1, rotate="oblimin", fm="ml"),heading="Table 5. Factor Loadings for Exploratory Factor Analysis with Oblimin Rotation
of APSI")
## % Called in the psych package  fa2latex % Called in the psych package  fa(APSI124578, 1, rotate = "oblimin", fm = "ml") % Called in the psych package  Table 5. Factor Loadings for Exploratory Factor Analysis with Oblimin Rotation
## of APSI 
## \begin{table}[htdp]\caption{fa2latex}
## \begin{center}
## \begin{scriptsize} 
## \begin{tabular} {l r r r r }
##  \multicolumn{ 4 }{l}{ Table 5. Factor Loadings for Exploratory Factor Analysis with Oblimin Rotation
## of APSI } \cr 
##  \hline Variable  &   ML1  &  ML1.1  &  ML1.2  &  com \cr 
##   \hline 
## 1   &  \bf{0.83}  &  0.69  &  0.31  &  1 \cr 
##  2   &  \bf{0.76}  &  0.58  &  0.42  &  1 \cr 
##  4   &  \bf{0.82}  &  0.68  &  0.32  &  1 \cr 
##  5   &  \bf{0.67}  &  0.45  &  0.55  &  1 \cr 
##  7   &  \bf{0.77}  &  0.60  &  0.40  &  1 \cr 
##  8   &  \bf{0.81}  &  0.66  &  0.34  &  1 \cr 
## \hline \cr SS loadings & 3.65 &  \cr  
##  \hline 
## \end{tabular}
## \end{scriptsize}
## \end{center}
## \label{default}
## \end{table}
#CFI
1-((twofactorAPSI124578$STATISTIC - twofactorAPSI124578$dof)/(twofactorAPSI124578$null.chisq- twofactorAPSI124578$null.dof))
## [1] 0.9717461

drop question 2 and only uuse question 1,4,7,8 seem to talk about purpose. so try as one factr

 APSI1478<-select(APSI, 1, 4,7,8)
 APSI1478<-tbl_df(APSI1478)
  APSI1478
## Source: local data frame [807 x 4]
## 
##    1 4 7 8
## 1  2 4 4 4
## 2  4 5 4 4
## 3  3 3 4 3
## 4  4 4 4 3
## 5  3 3 2 3
## 6  3 4 5 3
## 7  2 3 2 2
## 8  3 3 3 1
## 9  4 4 4 5
## 10 2 3 3 4
## .. . . . .
twofactorAPSI1478<-fa(APSI1478, nfactors=1, rotate="varimax", fm="ml")
fa2latex(fa(APSI1478,1, rotate="oblimin", fm="ml"),heading="Table 6. Factor Loadings for Exploratory Factor Analysis with Oblimin Rotation
of APSI")
## % Called in the psych package  fa2latex % Called in the psych package  fa(APSI1478, 1, rotate = "oblimin", fm = "ml") % Called in the psych package  Table 6. Factor Loadings for Exploratory Factor Analysis with Oblimin Rotation
## of APSI 
## \begin{table}[htdp]\caption{fa2latex}
## \begin{center}
## \begin{scriptsize} 
## \begin{tabular} {l r r r r }
##  \multicolumn{ 4 }{l}{ Table 6. Factor Loadings for Exploratory Factor Analysis with Oblimin Rotation
## of APSI } \cr 
##  \hline Variable  &   ML1  &  ML1.1  &  ML1.2  &  com \cr 
##   \hline 
## 1   &  \bf{0.79}  &  0.62  &  0.38  &  1 \cr 
##  4   &  \bf{0.84}  &  0.71  &  0.29  &  1 \cr 
##  7   &  \bf{0.80}  &  0.64  &  0.36  &  1 \cr 
##  8   &  \bf{0.83}  &  0.68  &  0.32  &  1 \cr 
## \hline \cr SS loadings & 2.65 &  \cr  
##  \hline 
## \end{tabular}
## \end{scriptsize}
## \end{center}
## \label{default}
## \end{table}
twofactorAPSI1478#clearly shows that this is all one factor. Droping 2 makes it a much better fit.
## Factor Analysis using method =  ml
## Call: fa(r = APSI1478, nfactors = 1, rotate = "varimax", fm = "ml")
## Standardized loadings (pattern matrix) based upon correlation matrix
##    ML1   h2   u2 com
## 1 0.79 0.62 0.38   1
## 4 0.84 0.71 0.29   1
## 7 0.80 0.64 0.36   1
## 8 0.83 0.68 0.32   1
## 
##                 ML1
## SS loadings    2.65
## Proportion Var 0.66
## 
## Mean item complexity =  1
## Test of the hypothesis that 1 factor is sufficient.
## 
## The degrees of freedom for the null model are  6  and the objective function was  2.17 with Chi Square of  1748.11
## The degrees of freedom for the model are 2  and the objective function was  0 
## 
## The root mean square of the residuals (RMSR) is  0.01 
## The df corrected root mean square of the residuals is  0.02 
## 
## The harmonic number of observations is  807 with the empirical chi square  0.81  with prob <  0.67 
## The total number of observations was  807  with MLE Chi Square =  3.51  with prob <  0.17 
## 
## Tucker Lewis Index of factoring reliability =  0.997
## RMSEA index =  0.031  and the 90 % confidence intervals are  NA 0.082
## BIC =  -9.88
## Fit based upon off diagonal values = 1
## Measures of factor score adequacy             
##                                                 ML1
## Correlation of scores with factors             0.94
## Multiple R square of scores with factors       0.89
## Minimum correlation of possible factor scores  0.78
#CFI
1-((twofactorAPSI1478$STATISTIC - twofactor$dof)/(twofactor$null.chisq- twofactor$null.dof))
## [1] 1.003171

question 6 is negative but talks about fit in the world, question 2 talks about know “who I am” see if fits into one factor

 APSI26<-select(APSI, 3, 5,6)
 APSI26<-tbl_df(APSI26)
 APSI26
## Source: local data frame [807 x 3]
## 
##    3 5 6
## 1  4 4 2
## 2  4 4 3
## 3  4 3 3
## 4  5 5 2
## 5  4 4 3
## 6  4 4 4
## 7  4 4 2
## 8  4 5 3
## 9  5 4 4
## 10 2 5 3
## .. . . .
twofactorAPSI26<-fa(APSI26, nfactors=3, rotate="varimax", fm="ml")
fa2latex(fa(APSI26,3, rotate="oblimin", fm="ml"),heading="Table 7. Factor Loadings for Exploratory Factor Analysis with Oblimin Rotation
of APSI")
## % Called in the psych package  fa2latex % Called in the psych package  fa(APSI26, 3, rotate = "oblimin", fm = "ml") % Called in the psych package  Table 7. Factor Loadings for Exploratory Factor Analysis with Oblimin Rotation
## of APSI 
## \begin{table}[htdp]\caption{fa2latex}
## \begin{center}
## \begin{scriptsize} 
## \begin{tabular} {l r r r r r r }
##  \multicolumn{ 6 }{l}{ Table 7. Factor Loadings for Exploratory Factor Analysis with Oblimin Rotation
## of APSI } \cr 
##  \hline Variable  &   ML1  &  ML2  &  ML3  &  h2  &  u2  &  com \cr 
##   \hline 
## 3   &  \bf{ 0.44}  &  \bf{ 0.31}  &  0  &  0.34  &  0.66  &  1.79 \cr 
##  5   &  \bf{ 0.54}  &  -0.15  &  0  &  0.29  &  0.71  &  1.15 \cr 
##  6   &  -0.06  &  \bf{ 0.51}  &  0  &  0.26  &  0.74  &  1.02 \cr 
## \hline \cr SS loadings & 0.49 &  0.39 &  0 &  \cr  
## \cr 
##             \hline \cr 
## ML1   & 1.00 & 0.16 & 0.00 \cr 
##  ML2   & 0.16 & 1.00 & 0.00 \cr 
##  ML3   & 0.00 & 0.00 & 1.00 \cr 
##  \hline 
## \end{tabular}
## \end{scriptsize}
## \end{center}
## \label{default}
## \end{table}
twofactorAPSI26#seems to be a good fit
## Factor Analysis using method =  ml
## Call: fa(r = APSI26, nfactors = 3, rotate = "varimax", fm = "ml")
## Standardized loadings (pattern matrix) based upon correlation matrix
##     ML1   ML2 ML3   h2   u2 com
## 3  0.46  0.36   0 0.34 0.66 1.9
## 5  0.53 -0.09   0 0.29 0.71 1.1
## 6 -0.03  0.51   0 0.26 0.74 1.0
## 
##                        ML1  ML2  ML3
## SS loadings           0.49 0.39 0.00
## Proportion Var        0.16 0.13 0.00
## Cumulative Var        0.16 0.29 0.29
## Proportion Explained  0.55 0.45 0.00
## Cumulative Proportion 0.55 1.00 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  3  and the objective function was  0.27 with Chi Square of  220.98
## The degrees of freedom for the model are -3  and the objective function was  0.07 
## 
## The root mean square of the residuals (RMSR) is  0.11 
## The df corrected root mean square of the residuals is  NA 
## 
## The harmonic number of observations is  807 with the empirical chi square  59.48  with prob <  NA 
## The total number of observations was  807  with MLE Chi Square =  57.6  with prob <  NA 
## 
## Tucker Lewis Index of factoring reliability =  1.279
## Fit based upon off diagonal values = 0.82
## Measures of factor score adequacy             
##                                                  ML1   ML2 ML3
## Correlation of scores with factors              0.61  0.56   0
## Multiple R square of scores with factors        0.37  0.32   0
## Minimum correlation of possible factor scores  -0.26 -0.37  -1
#CFI
1-((twofactorAPSI26$STATISTIC - twofactor$dof)/(twofactor$null.chisq- twofactor$null.dof))
## [1] 0.9850978

question three and five talk about morals and values and could be one factor

 APSI35<-select(APSI, 3,5)
 APSI35<-tbl_df(APSI35)
 APSI35
## Source: local data frame [807 x 2]
## 
##    3 5
## 1  4 4
## 2  4 4
## 3  4 3
## 4  5 5
## 5  4 4
## 6  4 4
## 7  4 4
## 8  4 5
## 9  5 4
## 10 2 5
## .. . .
twofactorAPSI35<-fa(APSI35, nfactors=1, rotate="varimax", fm="ml")
fa2latex(fa(APSI35,1, rotate="oblimin", fm="ml"),heading="Table 8. Factor Loadings for Exploratory Factor Analysis with Oblimin Rotation
of APSI")
## % Called in the psych package  fa2latex % Called in the psych package  fa(APSI35, 1, rotate = "oblimin", fm = "ml") % Called in the psych package  Table 8. Factor Loadings for Exploratory Factor Analysis with Oblimin Rotation
## of APSI 
## \begin{table}[htdp]\caption{fa2latex}
## \begin{center}
## \begin{scriptsize} 
## \begin{tabular} {l r r r r }
##  \multicolumn{ 4 }{l}{ Table 8. Factor Loadings for Exploratory Factor Analysis with Oblimin Rotation
## of APSI } \cr 
##  \hline Variable  &   ML1  &  ML1.1  &  ML1.2  &  com \cr 
##   \hline 
## 3   &  \bf{0.57}  &  0.32  &  0.68  &  1 \cr 
##  5   &  \bf{0.57}  &  0.32  &  0.68  &  1 \cr 
## \hline \cr SS loadings & 0.64 &  \cr  
##  \hline 
## \end{tabular}
## \end{scriptsize}
## \end{center}
## \label{default}
## \end{table}
twofactorAPSI35#seems to load well on one factor
## Factor Analysis using method =  ml
## Call: fa(r = APSI35, nfactors = 1, rotate = "varimax", fm = "ml")
## Standardized loadings (pattern matrix) based upon correlation matrix
##    ML1   h2   u2 com
## 3 0.57 0.32 0.68   1
## 5 0.57 0.32 0.68   1
## 
##                 ML1
## SS loadings    0.64
## Proportion Var 0.32
## 
## Mean item complexity =  1
## Test of the hypothesis that 1 factor is sufficient.
## 
## The degrees of freedom for the null model are  1  and the objective function was  0.11 with Chi Square of  88.33
## The degrees of freedom for the model are -1  and the objective function was  0 
## 
## The root mean square of the residuals (RMSR) is  0 
## The df corrected root mean square of the residuals is  NA 
## 
## The harmonic number of observations is  807 with the empirical chi square  0  with prob <  NA 
## The total number of observations was  807  with MLE Chi Square =  0  with prob <  NA 
## 
## Tucker Lewis Index of factoring reliability =  1.011
## Fit based upon off diagonal values = 1
## Measures of factor score adequacy             
##                                                  ML1
## Correlation of scores with factors              0.70
## Multiple R square of scores with factors        0.49
## Minimum correlation of possible factor scores  -0.02
#CFI
1-((twofactorAPSI35$STATISTIC - twofactor$dof)/(twofactor$null.chisq- twofactor$null.dof))
## [1] 1.004344
#What are the factors
#Factor 1 (questions 1, 4, 7, 8) is purpose
#Factor 2 (questions 3,5) is moral values
#Factor 3 (questions 2,6) fit in the world, knowledge of who I am

Finding Alpha

alpha(APSI, na.rm = TRUE, check.keys=TRUE)
## Warning in alpha(APSI, na.rm = TRUE, check.keys = TRUE): Some items were negatively correlated with total scale and were automatically reversed.
##  This is indicated by a negative sign for the variable name.
## 
## Reliability analysis   
## Call: alpha(x = APSI, na.rm = TRUE, check.keys = TRUE)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N   ase mean   sd
##       0.81      0.82    0.86      0.37 4.7 0.016  3.8 0.77
## 
##  lower alpha upper     95% confidence boundaries
## 0.78 0.81 0.85 
## 
##  Reliability if an item is dropped:
##    raw_alpha std.alpha G6(smc) average_r S/N alpha se
## 1       0.76      0.78    0.81      0.33 3.4    0.020
## 2       0.77      0.78    0.82      0.34 3.6    0.019
## 3       0.84      0.85    0.86      0.45 5.8    0.016
## 4       0.76      0.78    0.82      0.33 3.5    0.020
## 5       0.77      0.78    0.82      0.34 3.6    0.019
## 6-      0.87      0.87    0.87      0.49 6.6    0.014
## 7       0.77      0.78    0.82      0.34 3.6    0.019
## 8       0.76      0.78    0.82      0.33 3.5    0.020
## 
##  Item statistics 
##      n raw.r std.r r.cor r.drop mean   sd
## 1  807  0.83  0.82 0.815  0.744  3.8 1.22
## 2  807  0.77  0.78 0.756  0.686  3.9 1.11
## 3  807  0.30  0.35 0.219  0.149  3.9 0.99
## 4  807  0.81  0.81 0.798  0.725  3.9 1.20
## 5  807  0.77  0.78 0.742  0.682  4.2 1.05
## 6- 807  0.26  0.21 0.062  0.033  2.9 1.43
## 7  807  0.79  0.79 0.769  0.704  3.9 1.13
## 8  807  0.81  0.81 0.794  0.727  3.9 1.21

Create dataset for Target rotation

data <- read.csv("~/Psychometric_study_data/allsurveysYT1.csv")
 APSI<-select(data,  APSI_1, APSI_2, APSI_4, APSI_7,  APSI_8,    APSI_5, APSI_3,  APSI_6)
APSI$APSI_6  <-  6- APSI$APSI_6
APSI<- data.frame(apply(APSI,2, as.numeric))

Load packedges

library(GPArotation)
library(psych)
library(dplyr)

colnames(APSI) <- c("1","2", "3", "4", "5", "6", "7", "8")

Trying to see whether we can make this into two factors

Targ_key <- make.keys(8,list(f1=1:5,f2=6:8))
Targ_key <- scrub(Targ_key,isvalue=1)  #fix the 0s, allow the NAs to be estimated
Targ_key <- list(Targ_key)
APSI_cor <- corFiml(APSI)
APSI_cor
##             1           2           3          4           5          6
## 1  1.00000000  0.68164569  0.66995340  0.6155685  0.65556809  0.5764466
## 2  0.68164569  1.00000000  0.60544104  0.5220847  0.60778051  0.5763827
## 3  0.66995340  0.60544104  1.00000000  0.6775965  0.68369538  0.5210318
## 4  0.61556848  0.52208472  0.67759649  1.0000000  0.66846079  0.4982735
## 5  0.65556809  0.60778051  0.68369538  0.6684608  1.00000000  0.5101553
## 6  0.57644659  0.57638272  0.52103176  0.4982735  0.51015532  1.0000000
## 7  0.15126792  0.16953157  0.15462831  0.1983746  0.13825804  0.3224736
## 8 -0.06491616 -0.02498372 -0.02746511 -0.0660619 -0.07102117 -0.1676714
##           7           8
## 1 0.1512679 -0.06491616
## 2 0.1695316 -0.02498372
## 3 0.1546283 -0.02746511
## 4 0.1983746 -0.06606190
## 5 0.1382580 -0.07102117
## 6 0.3224736 -0.16767137
## 7 1.0000000  0.27923838
## 8 0.2792384  1.00000000
out_targetQ <- fa(APSI_cor,2,rotate="TargetQ",n.obs = 807,Target=Targ_key) #TargetT for orthogonal rotation
## Warning in fac(r = r, nfactors = nfactors, n.obs = n.obs, rotate =
## rotate, : A Heywood case was detected. Examine the loadings carefully.
out_targetQ[c("loadings", "score.cor", "TLI", "RMSEA")]
## $loadings
## 
## Loadings:
##   MR1    MR2   
## 1  0.826       
## 2  0.750       
## 3  0.820       
## 4  0.753       
## 5  0.815       
## 6  0.611  0.218
## 7         1.014
## 8 -0.171  0.310
## 
##                  MR1   MR2
## SS loadings    3.557 1.178
## Proportion Var 0.445 0.147
## Cumulative Var 0.445 0.592
## 
## $score.cor
##            [,1]       [,2]
## [1,] 1.00000000 0.09065086
## [2,] 0.09065086 1.00000000
## 
## $TLI
## [1] 0.8999115
## 
## $RMSEA
##      RMSEA      lower      upper confidence 
## 0.11549346 0.09901283 0.13182236 0.10000000
fa2latex(fa(APSI_cor,2,rotate="TargetQ",n.obs = 807,Target=Targ_key), heading="Table 9. Factor Loadings for Confirmatory Factor Analysis with Target Rotation of APSI")
## Warning in fac(r = r, nfactors = nfactors, n.obs = n.obs, rotate =
## rotate, : A Heywood case was detected. Examine the loadings carefully.
## % Called in the psych package  fa2latex % Called in the psych package  fa(APSI_cor, 2, rotate = "TargetQ", n.obs = 807, Target = Targ_key) % Called in the psych package  Table 9. Factor Loadings for Confirmatory Factor Analysis with Target Rotation of APSI 
## \begin{table}[htdp]\caption{fa2latex}
## \begin{center}
## \begin{scriptsize} 
## \begin{tabular} {l r r r r r }
##  \multicolumn{ 5 }{l}{ Table 9. Factor Loadings for Confirmatory Factor Analysis with Target Rotation of APSI } \cr 
##  \hline Variable  &   MR1  &  MR2  &  h2  &  u2  &  com \cr 
##   \hline 
## 1   &  \bf{ 0.83}  &  0.01  &  0.69  &  0.31  &  1.00 \cr 
##  2   &  \bf{ 0.75}  &  0.04  &  0.58  &  0.42  &  1.01 \cr 
##  3   &  \bf{ 0.82}  &  0.01  &  0.68  &  0.32  &  1.00 \cr 
##  4   &  \bf{ 0.75}  &  0.07  &  0.60  &  0.40  &  1.02 \cr 
##  5   &  \bf{ 0.82}  &  0.00  &  0.66  &  0.34  &  1.00 \cr 
##  6   &  \bf{ 0.61}  &  0.22  &  0.49  &  0.51  &  1.25 \cr 
##  7   &  -0.08  &  \bf{1.01}  &  1.00  &  0.00  &  1.01 \cr 
##  8   &  -0.17  &  \bf{0.31}  &  0.10  &  0.90  &  1.56 \cr 
## \hline \cr SS loadings & 3.58 &  1.2 &  \cr  
## \cr 
##             \hline \cr 
## MR1   & 1.00 & 0.25 \cr 
##  MR2   & 0.25 & 1.00 \cr 
##  \hline 
## \end{tabular}
## \end{scriptsize}
## \end{center}
## \label{default}
## \end{table}
out_targetQ#get a heywood case. really poor fit
## Factor Analysis using method =  minres
## Call: fa(r = APSI_cor, nfactors = 2, n.obs = 807, rotate = "TargetQ", 
##     Target = Targ_key)
## 
##  Warning: A Heywood case was detected. 
## Standardized loadings (pattern matrix) based upon correlation matrix
##     MR1  MR2    h2    u2 com
## 1  0.83 0.01 0.686 0.314 1.0
## 2  0.75 0.04 0.580 0.420 1.0
## 3  0.82 0.01 0.678 0.322 1.0
## 4  0.75 0.07 0.597 0.403 1.0
## 5  0.82 0.00 0.664 0.336 1.0
## 6  0.61 0.22 0.487 0.513 1.3
## 7 -0.08 1.01 0.995 0.005 1.0
## 8 -0.17 0.31 0.099 0.901 1.6
## 
##                        MR1  MR2
## SS loadings           3.58 1.20
## Proportion Var        0.45 0.15
## Cumulative Var        0.45 0.60
## Proportion Explained  0.75 0.25
## Cumulative Proportion 0.75 1.00
## 
##  With factor correlations of 
##      MR1  MR2
## MR1 1.00 0.25
## MR2 0.25 1.00
## 
## Mean item complexity =  1.1
## Test of the hypothesis that 2 factors are sufficient.
## 
## The degrees of freedom for the null model are  28  and the objective function was  3.76 with Chi Square of  3020.93
## The degrees of freedom for the model are 13  and the objective function was  0.19 
## 
## The root mean square of the residuals (RMSR) is  0.04 
## The df corrected root mean square of the residuals is  0.06 
## 
## The harmonic number of observations is  807 with the empirical chi square  82.96  with prob <  3.1e-12 
## The total number of observations was  807  with MLE Chi Square =  151.85  with prob <  8.7e-26 
## 
## Tucker Lewis Index of factoring reliability =  0.9
## RMSEA index =  0.115  and the 90 % confidence intervals are  0.099 0.132
## BIC =  64.83
## Fit based upon off diagonal values = 0.99
## Measures of factor score adequacy             
##                                                 MR1  MR2
## Correlation of scores with factors             0.95 1.00
## Multiple R square of scores with factors       0.91 0.99
## Minimum correlation of possible factor scores  0.82 0.99

CFI

1-((out_targetQ$STATISTIC - out_targetQ$dof)/(out_targetQ$null.chisq- out_targetQ$null.dof))
## [1] 0.9536083

Create dataset for Target rotation

data <- read.csv("~/Psychometric_study_data/allsurveysYT1.csv")
APSI<-select(data,  APSI_1, APSI_2, APSI_4, APSI_7,  APSI_8,    APSI_5, APSI_3,  APSI_6)
APSI$APSI_6  <-  6- APSI$APSI_6
APSI<- data.frame(apply(APSI,2, as.numeric))
colnames(APSI) <- c("1","2", "3", "4", "5", "6", "7","8")
#Target rotation: choose "simple structure" a priori and can be applied to oblique and orthogonal rotation based on 
#what paper says facotrs should be MLQ
Targ_key <- make.keys(8,list(f1=1:6,f2=7:8))
Targ_key <- scrub(Targ_key,isvalue=1)  #fix the 0s, allow the NAs to be estimated
Targ_key <- list(Targ_key)
APSI_cor <- corFiml(APSI)
APSI_cor
##             1           2           3          4           5          6
## 1  1.00000000  0.68164569  0.66995340  0.6155685  0.65556809  0.5764466
## 2  0.68164569  1.00000000  0.60544104  0.5220847  0.60778051  0.5763827
## 3  0.66995340  0.60544104  1.00000000  0.6775965  0.68369538  0.5210318
## 4  0.61556848  0.52208472  0.67759649  1.0000000  0.66846079  0.4982735
## 5  0.65556809  0.60778051  0.68369538  0.6684608  1.00000000  0.5101553
## 6  0.57644659  0.57638272  0.52103176  0.4982735  0.51015532  1.0000000
## 7  0.15126792  0.16953157  0.15462831  0.1983746  0.13825804  0.3224736
## 8 -0.06491616 -0.02498372 -0.02746511 -0.0660619 -0.07102117 -0.1676714
##           7           8
## 1 0.1512679 -0.06491616
## 2 0.1695316 -0.02498372
## 3 0.1546283 -0.02746511
## 4 0.1983746 -0.06606190
## 5 0.1382580 -0.07102117
## 6 0.3224736 -0.16767137
## 7 1.0000000  0.27923838
## 8 0.2792384  1.00000000
out_targetQ <- fa(APSI_cor,2,rotate="TargetQ",n.obs = 807,Target=Targ_key) #TargetT for orthogonal rotation
out_targetQ[c("loadings", "score.cor", "TLI", "RMSEA")]#many cross loadings
## $loadings
## 
## Loadings:
##   MR1    MR2   
## 1  0.835       
## 2  0.763       
## 3  0.830       
## 4  0.769       
## 5  0.823       
## 6  0.645  0.172
## 7         0.987
## 8 -0.134  0.311
## 
##                  MR1   MR2
## SS loadings    3.674 1.108
## Proportion Var 0.459 0.138
## Cumulative Var 0.459 0.598
## 
## $score.cor
##            [,1]       [,2]
## [1,] 1.00000000 0.09065086
## [2,] 0.09065086 1.00000000
## 
## $TLI
## [1] 0.8999115
## 
## $RMSEA
##      RMSEA      lower      upper confidence 
## 0.11549346 0.09901283 0.13182236 0.10000000
fa2latex(fa(APSI_cor,2,rotate="TargetQ",n.obs = 807,Target=Targ_key), heading="Table 10. Factor Loadings for Confirmatory Factor Analysis with Target Rotation of APSI")
## % Called in the psych package  fa2latex % Called in the psych package  fa(APSI_cor, 2, rotate = "TargetQ", n.obs = 807, Target = Targ_key) % Called in the psych package  Table 10. Factor Loadings for Confirmatory Factor Analysis with Target Rotation of APSI 
## \begin{table}[htdp]\caption{fa2latex}
## \begin{center}
## \begin{scriptsize} 
## \begin{tabular} {l r r r r r }
##  \multicolumn{ 5 }{l}{ Table 10. Factor Loadings for Confirmatory Factor Analysis with Target Rotation of APSI } \cr 
##  \hline Variable  &   MR1  &  MR2  &  h2  &  u2  &  com \cr 
##   \hline 
## 1   &  \bf{ 0.84}  &  -0.04  &  0.69  &  0.31  &  1.01 \cr 
##  2   &  \bf{ 0.76}  &  -0.01  &  0.58  &  0.42  &  1.00 \cr 
##  3   &  \bf{ 0.83}  &  -0.04  &  0.68  &  0.32  &  1.00 \cr 
##  4   &  \bf{ 0.77}  &   0.02  &  0.60  &  0.40  &  1.00 \cr 
##  5   &  \bf{ 0.82}  &  -0.05  &  0.66  &  0.34  &  1.01 \cr 
##  6   &  \bf{ 0.64}  &   0.17  &  0.49  &  0.51  &  1.14 \cr 
##  7   &   0.05  &  \bf{ 0.99}  &  1.00  &  0.00  &  1.00 \cr 
##  8   &  -0.13  &  \bf{ 0.31}  &  0.10  &  0.90  &  1.36 \cr 
## \hline \cr SS loadings & 3.68 &  1.11 &  \cr  
## \cr 
##             \hline \cr 
## MR1   & 1.00 & 0.19 \cr 
##  MR2   & 0.19 & 1.00 \cr 
##  \hline 
## \end{tabular}
## \end{scriptsize}
## \end{center}
## \label{default}
## \end{table}
out_targetQ#still not a great fit
## Factor Analysis using method =  minres
## Call: fa(r = APSI_cor, nfactors = 2, n.obs = 807, rotate = "TargetQ", 
##     Target = Targ_key)
## Standardized loadings (pattern matrix) based upon correlation matrix
##     MR1   MR2    h2    u2 com
## 1  0.84 -0.04 0.686 0.314 1.0
## 2  0.76 -0.01 0.580 0.420 1.0
## 3  0.83 -0.04 0.678 0.322 1.0
## 4  0.77  0.02 0.597 0.403 1.0
## 5  0.82 -0.05 0.664 0.336 1.0
## 6  0.64  0.17 0.487 0.513 1.1
## 7  0.05  0.99 0.995 0.005 1.0
## 8 -0.13  0.31 0.099 0.901 1.4
## 
##                        MR1  MR2
## SS loadings           3.68 1.11
## Proportion Var        0.46 0.14
## Cumulative Var        0.46 0.60
## Proportion Explained  0.77 0.23
## Cumulative Proportion 0.77 1.00
## 
##  With factor correlations of 
##      MR1  MR2
## MR1 1.00 0.19
## MR2 0.19 1.00
## 
## Mean item complexity =  1.1
## Test of the hypothesis that 2 factors are sufficient.
## 
## The degrees of freedom for the null model are  28  and the objective function was  3.76 with Chi Square of  3020.93
## The degrees of freedom for the model are 13  and the objective function was  0.19 
## 
## The root mean square of the residuals (RMSR) is  0.04 
## The df corrected root mean square of the residuals is  0.06 
## 
## The harmonic number of observations is  807 with the empirical chi square  82.96  with prob <  3.1e-12 
## The total number of observations was  807  with MLE Chi Square =  151.85  with prob <  8.7e-26 
## 
## Tucker Lewis Index of factoring reliability =  0.9
## RMSEA index =  0.115  and the 90 % confidence intervals are  0.099 0.132
## BIC =  64.83
## Fit based upon off diagonal values = 0.99
## Measures of factor score adequacy             
##                                                 MR1  MR2
## Correlation of scores with factors             0.95 1.00
## Multiple R square of scores with factors       0.91 0.99
## Minimum correlation of possible factor scores  0.82 0.99

CFI

1-((out_targetQ$STATISTIC - out_targetQ$dof)/(out_targetQ$null.chisq- out_targetQ$null.dof))
## [1] 0.9536083

Create dataset for Target rotation droping question 3 that talks about having belifes and values and loads on all factors

data <- read.csv("~/Psychometric_study_data/allsurveysYT1.csv")
APSI<-select(data,  APSI_1, APSI_2, APSI_4, APSI_7,  APSI_8,  APSI_5, APSI_3,  APSI_6)
APSI$APSI_6  <-  6- APSI$APSI_6
APSI<- data.frame(apply(APSI,2, as.numeric))
colnames(APSI) <- c("1","2", "3", "4", "5", "6", "7", "8")
#Target rotation: choose "simple structure" a priori and can be applied to oblique and orthogonal rotation based on 
Targ_key <- make.keys(8,list(f1=1:6,f2=7, f3=8))
Targ_key <- scrub(Targ_key,isvalue=1)  #fix the 0s, allow the NAs to be estimated
Targ_key <- list(Targ_key)
APSI_cor <- corFiml(APSI)
out_targetQ <- fa(APSI_cor,3,rotate="TargetQ",n.obs = 807,Target=Targ_key) #TargetT for orthogonal rotation
out_targetQ[c("loadings", "score.cor", "TLI", "RMSEA")]
## $loadings
## 
## Loadings:
##   MR1    MR2    MR3   
## 1  0.824              
## 2  0.754              
## 3  0.836         0.153
## 4  0.775         0.149
## 5  0.826         0.151
## 6  0.692  0.182 -0.604
## 7         0.989  0.111
## 8 -0.127  0.305  0.270
## 
##                  MR1   MR2   MR3
## SS loadings    3.728 1.110 0.522
## Proportion Var 0.466 0.139 0.065
## Cumulative Var 0.466 0.605 0.670
## 
## $score.cor
##            [,1]       [,2]
## [1,] 1.00000000 0.09065086
## [2,] 0.09065086 1.00000000
## 
## $TLI
## [1] 0.9247668
## 
## $RMSEA
##      RMSEA      lower      upper confidence 
## 0.10014544 0.07800577 0.12295076 0.10000000
fa2latex(fa(APSI_cor,3,rotate="TargetQ",n.obs = 807,Target=Targ_key), heading="Table 11. Factor Loadings for Confirmatory Factor Analysis with Target Rotation of APSI")
## % Called in the psych package  fa2latex % Called in the psych package  fa(APSI_cor, 3, rotate = "TargetQ", n.obs = 807, Target = Targ_key) % Called in the psych package  Table 11. Factor Loadings for Confirmatory Factor Analysis with Target Rotation of APSI 
## \begin{table}[htdp]\caption{fa2latex}
## \begin{center}
## \begin{scriptsize} 
## \begin{tabular} {l r r r r r r }
##  \multicolumn{ 6 }{l}{ Table 11. Factor Loadings for Confirmatory Factor Analysis with Target Rotation of APSI } \cr 
##  \hline Variable  &   MR1  &  MR2  &  MR3  &  h2  &  u2  &  com \cr 
##   \hline 
## 1   &  \bf{ 0.82}  &  -0.03  &   0.06  &  0.67  &  0.33  &  1.01 \cr 
##  2   &  \bf{ 0.75}  &   0.00  &   0.00  &  0.57  &  0.43  &  1.00 \cr 
##  3   &  \bf{ 0.84}  &  -0.04  &   0.15  &  0.70  &  0.30  &  1.07 \cr 
##  4   &  \bf{ 0.78}  &   0.02  &   0.15  &  0.61  &  0.39  &  1.08 \cr 
##  5   &  \bf{ 0.83}  &  -0.05  &   0.15  &  0.68  &  0.32  &  1.07 \cr 
##  6   &  \bf{ 0.69}  &   0.18  &  \bf{-0.60}  &  0.99  &  0.01  &  2.11 \cr 
##  7   &   0.06  &  \bf{ 0.99}  &   0.11  &  1.00  &  0.00  &  1.03 \cr 
##  8   &  -0.13  &  \bf{ 0.31}  &   0.27  &  0.16  &  0.84  &  2.33 \cr 
## \hline \cr SS loadings & 3.74 &  1.11 &  0.52 &  \cr  
## \cr 
##             \hline \cr 
## MR1   &  1.00 &  0.17 & -0.06 \cr 
##  MR2   &  0.17 &  1.00 & -0.09 \cr 
##  MR3   & -0.06 & -0.09 &  1.00 \cr 
##  \hline 
## \end{tabular}
## \end{scriptsize}
## \end{center}
## \label{default}
## \end{table}
out_targetQ#its a good fit but the second factor does not load at all. 1, 4, 7, 8 work well as one factor 3, 5 and 6 are problematic. 
## Factor Analysis using method =  minres
## Call: fa(r = APSI_cor, nfactors = 3, n.obs = 807, rotate = "TargetQ", 
##     Target = Targ_key)
## Standardized loadings (pattern matrix) based upon correlation matrix
##     MR1   MR2   MR3   h2     u2 com
## 1  0.82 -0.03  0.06 0.67 0.3319 1.0
## 2  0.75  0.00  0.00 0.57 0.4307 1.0
## 3  0.84 -0.04  0.15 0.70 0.3018 1.1
## 4  0.78  0.02  0.15 0.61 0.3855 1.1
## 5  0.83 -0.05  0.15 0.68 0.3201 1.1
## 6  0.69  0.18 -0.60 0.99 0.0097 2.1
## 7  0.06  0.99  0.11 1.00 0.0050 1.0
## 8 -0.13  0.31  0.27 0.16 0.8414 2.3
## 
##                        MR1  MR2  MR3
## SS loadings           3.74 1.11 0.52
## Proportion Var        0.47 0.14 0.06
## Cumulative Var        0.47 0.61 0.67
## Proportion Explained  0.70 0.21 0.10
## Cumulative Proportion 0.70 0.90 1.00
## 
##  With factor correlations of 
##       MR1   MR2   MR3
## MR1  1.00  0.17 -0.06
## MR2  0.17  1.00 -0.09
## MR3 -0.06 -0.09  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  28  and the objective function was  3.76 with Chi Square of  3020.93
## The degrees of freedom for the model are 7  and the objective function was  0.08 
## 
## The root mean square of the residuals (RMSR) is  0.02 
## The df corrected root mean square of the residuals is  0.05 
## 
## The harmonic number of observations is  807 with the empirical chi square  22.95  with prob <  0.0017 
## The total number of observations was  807  with MLE Chi Square =  63.15  with prob <  3.5e-11 
## 
## Tucker Lewis Index of factoring reliability =  0.925
## RMSEA index =  0.1  and the 90 % confidence intervals are  0.078 0.123
## BIC =  16.3
## Fit based upon off diagonal values = 1
## Measures of factor score adequacy             
##                                                 MR1  MR2  MR3
## Correlation of scores with factors             0.97 1.00 0.95
## Multiple R square of scores with factors       0.93 0.99 0.90
## Minimum correlation of possible factor scores  0.86 0.99 0.81

CFI

1-((out_targetQ$STATISTIC - out_targetQ$dof)/(out_targetQ$null.chisq- out_targetQ$null.dof))
## [1] 0.981239

Create dataset for Target rotation as one factor

data <- read.csv("~/Psychometric_study_data/allsurveysYT1.csv")
APSI<-select(data,  APSI_1, APSI_2, APSI_3, APSI_4, APSI_5, APSI_6, APSI_7, APSI_8)
APSI$APSI_6  <-  6- APSI$APSI_6
APSI<- data.frame(apply(APSI,2, as.numeric))
colnames(APSI) <- c("1","2", "3", "4", "5", "6", "7", "8")
#Target rotation: choose "simple structure" a priori and can be applied to oblique and orthogonal rotation based on 
Targ_key <- make.keys(8,list(f1=1:8))
Targ_key <- scrub(Targ_key,isvalue=1)  #fix the 0s, allow the NAs to be estimated
Targ_key <- list(Targ_key)
APSI_cor <- corFiml(APSI)
out_targetQ <- fa(APSI_cor,1,rotate="TargetQ",n.obs = 807,Target=Targ_key) #TargetT for orthogonal rotation
fa2latex(fa(APSI_cor,1,rotate="TargetQ",n.obs = 807,Target=Targ_key), heading="Table 1. Factor Loadings for Confirmatory Factor Analysis with Target Rotation of APSI")
## % Called in the psych package  fa2latex % Called in the psych package  fa(APSI_cor, 1, rotate = "TargetQ", n.obs = 807, Target = Targ_key) % Called in the psych package  Table 1. Factor Loadings for Confirmatory Factor Analysis with Target Rotation of APSI 
## \begin{table}[htdp]\caption{fa2latex}
## \begin{center}
## \begin{scriptsize} 
## \begin{tabular} {l r r r r }
##  \multicolumn{ 4 }{l}{ Table 1. Factor Loadings for Confirmatory Factor Analysis with Target Rotation of APSI } \cr 
##  \hline Variable  &   MR1  &  MR1.1  &  MR1.2  &  com \cr 
##   \hline 
## 1   &  \bf{ 0.83}  &  0.68  &  0.32  &  1 \cr 
##  2   &  \bf{ 0.76}  &  0.58  &  0.42  &  1 \cr 
##  3   &   0.22  &  0.05  &  0.95  &  1 \cr 
##  4   &  \bf{ 0.82}  &  0.68  &  0.32  &  1 \cr 
##  5   &  \bf{ 0.67}  &  0.45  &  0.55  &  1 \cr 
##  6   &  -0.07  &  0.01  &  0.99  &  1 \cr 
##  7   &  \bf{ 0.77}  &  0.60  &  0.40  &  1 \cr 
##  8   &  \bf{ 0.81}  &  0.66  &  0.34  &  1 \cr 
## \hline \cr SS loadings & 3.71 &  \cr  
##  \hline 
## \end{tabular}
## \end{scriptsize}
## \end{center}
## \label{default}
## \end{table}
out_targetQ[c("loadings", "score.cor", "TLI", "RMSEA")]
## $loadings
## 
## Loadings:
##   MR1   
## 1  0.827
## 2  0.762
## 3  0.221
## 4  0.823
## 5  0.673
## 6       
## 7  0.773
## 8  0.812
## 
##                  MR1
## SS loadings    3.706
## Proportion Var 0.463
## 
## $<NA>
## NULL
## 
## $TLI
## [1] 0.8744374
## 
## $RMSEA
##      RMSEA      lower      upper confidence 
##  0.1293478  0.1159546  0.1423052  0.1000000
out_targetQ#its a good fit but the second factor does not load at all. 1, 4, 7, 8 work well as one factor 3, 5 and 6 are problematic. 
## Factor Analysis using method =  minres
## Call: fa(r = APSI_cor, nfactors = 1, n.obs = 807, rotate = "TargetQ", 
##     Target = Targ_key)
## Standardized loadings (pattern matrix) based upon correlation matrix
##     MR1     h2   u2 com
## 1  0.83 0.6845 0.32   1
## 2  0.76 0.5805 0.42   1
## 3  0.22 0.0487 0.95   1
## 4  0.82 0.6772 0.32   1
## 5  0.67 0.4535 0.55   1
## 6 -0.07 0.0053 0.99   1
## 7  0.77 0.5969 0.40   1
## 8  0.81 0.6597 0.34   1
## 
##                 MR1
## SS loadings    3.71
## Proportion Var 0.46
## 
## Mean item complexity =  1
## Test of the hypothesis that 1 factor is sufficient.
## 
## The degrees of freedom for the null model are  28  and the objective function was  3.76 with Chi Square of  3020.93
## The degrees of freedom for the model are 20  and the objective function was  0.36 
## 
## The root mean square of the residuals (RMSR) is  0.07 
## The df corrected root mean square of the residuals is  0.09 
## 
## The harmonic number of observations is  807 with the empirical chi square  254.18  with prob <  1.6e-42 
## The total number of observations was  807  with MLE Chi Square =  288.2  with prob <  2.1e-49 
## 
## Tucker Lewis Index of factoring reliability =  0.874
## RMSEA index =  0.129  and the 90 % confidence intervals are  0.116 0.142
## BIC =  154.34
## Fit based upon off diagonal values = 0.97
## Measures of factor score adequacy             
##                                                 MR1
## Correlation of scores with factors             0.95
## Multiple R square of scores with factors       0.91
## Minimum correlation of possible factor scores  0.82

CFI

1-((out_targetQ$STATISTIC - out_targetQ$dof)/(out_targetQ$null.chisq- out_targetQ$null.dof))
## [1] 0.9103876

Lavaan for one factor model

create the models

data <- read.csv("~/Psychometric_study_data/allsurveysYT1.csv")
APSI<-select(data,  APSI_1, APSI_2, APSI_3, APSI_4, APSI_5, APSI_6, APSI_7, APSI_8)
one.model= ' Factor1  =~ APSI_1 + APSI_2 + APSI_3 + APSI_4 + APSI_5 + APSI_6 + APSI_7 + APSI_8'
one.fit=cfa(one.model, data=APSI, missing = "fiml")
## Warning in lav_data_full(data = data, group = group, group.label = group.label, : lavaan WARNING: some cases are empty and will be removed:
##   17 22 23 24 28 29 43 45 78 79 80 81 84 85 93 94 95 110 111 112 116 121 122 123 124 125 128 129 130 131 133 135 137 138 140 147 151 152 155 156 162 166 169 170 171 172 173 174 176 177 179 180 183 184 186 187 188 189 192 194 195 197 200 202 203 204 207 208 210 212 214 215 217 220 222 223 224 226 227 228 229 230 234 238 240 243 245 246 247 249 252 255 256 265 266 267 268 270 271 274 275 280 281 282 284 286 287 289 291 292 298 300 304 309 310 311 312 315 316 317 320 322 325 327 330 333 334 336 339 340 344 348 350 351 352 354 355 357 360 361 362 364 365 366 367 368 369 370 371 372 373 374 375 376 377 379 380 381 384 385 386 389 390 397 398 399 400 401 402 403 404 405 406 407 408 410 416 417 418 419 420 421 422 423 424 425 427 428 429 430 431 432 434 436 444 445 446 447 448 452 453 454 455 456 457 459 460 462 463 464 465 467 468 470 472 473 474 475 476 478 481 482 485 486 490 491 493 495 539 540 541 542 543 544 545 546 547 548 549 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 662 679 687 782 783 784 785 809 810 829 903 906 907 909 910 911 1109 1110 1111 1112 1113 1114 1116 1117 1120 1121 1122 1125 1126 1128 1129 1130 1131 1132 1134 1136 1137 1138 1139 1140 1143 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1157 1159 1160
semPaths(one.fit, whatLabels = "std", layout = "tree")

summary(one.fit, standardized = TRUE, rsquare=TRUE)
## lavaan (0.5-18) converged normally after  21 iterations
## 
##                                                   Used       Total
##   Number of observations                           807        1160
## 
##   Number of missing patterns                         1
## 
##   Estimator                                         ML
##   Minimum Function Test Statistic              290.059
##   Degrees of freedom                                20
##   P-value (Chi-square)                           0.000
## 
## Parameter estimates:
## 
##   Information                                 Observed
##   Standard Errors                             Standard
## 
##                    Estimate  Std.err  Z-value  P(>|z|)   Std.lv  Std.all
## Latent variables:
##   Factor1 =~
##     APSI_1            1.000                               1.006    0.827
##     APSI_2            0.838    0.034   24.655    0.000    0.844    0.762
##     APSI_3            0.218    0.036    6.029    0.000    0.219    0.221
##     APSI_4            0.982    0.037   26.777    0.000    0.989    0.823
##     APSI_5            0.701    0.034   20.717    0.000    0.705    0.673
##     APSI_6            0.104    0.053    1.970    0.049    0.104    0.073
##     APSI_7            0.870    0.036   24.409    0.000    0.875    0.773
##     APSI_8            0.976    0.037   26.261    0.000    0.983    0.812
## 
## Intercepts:
##     APSI_1            3.755    0.043   87.636    0.000    3.755    3.085
##     APSI_2            3.941    0.039  101.111    0.000    3.941    3.559
##     APSI_3            3.901    0.035  111.713    0.000    3.901    3.932
##     APSI_4            3.871    0.042   91.543    0.000    3.871    3.222
##     APSI_5            4.191    0.037  113.710    0.000    4.191    4.003
##     APSI_6            2.896    0.050   57.407    0.000    2.896    2.021
##     APSI_7            3.923    0.040   98.399    0.000    3.923    3.464
##     APSI_8            3.874    0.043   90.959    0.000    3.874    3.202
##     Factor1           0.000                               0.000    0.000
## 
## Variances:
##     APSI_1            0.468    0.030                      0.468    0.316
##     APSI_2            0.514    0.030                      0.514    0.419
##     APSI_3            0.936    0.047                      0.936    0.951
##     APSI_4            0.466    0.030                      0.466    0.323
##     APSI_5            0.599    0.033                      0.599    0.547
##     APSI_6            2.043    0.102                      2.043    0.995
##     APSI_7            0.517    0.031                      0.517    0.403
##     APSI_8            0.498    0.031                      0.498    0.340
##     Factor1           1.013    0.073                      1.000    1.000
## 
## R-Square:
## 
##     APSI_1            0.684
##     APSI_2            0.581
##     APSI_3            0.049
##     APSI_4            0.677
##     APSI_5            0.453
##     APSI_6            0.005
##     APSI_7            0.597
##     APSI_8            0.660
correl1 = residuals(one.fit, type="cor")
correl1
## $type
## [1] "cor.bollen"
## 
## $cor
##        APSI_1 APSI_2 APSI_3 APSI_4 APSI_5 APSI_6 APSI_7 APSI_8
## APSI_1  0.000                                                 
## APSI_2  0.051  0.000                                          
## APSI_3 -0.031  0.001  0.000                                   
## APSI_4 -0.011 -0.022 -0.027  0.000                            
## APSI_5  0.020  0.063  0.174 -0.033  0.000                     
## APSI_6  0.005 -0.030 -0.295 -0.032  0.119  0.000              
## APSI_7 -0.024 -0.067  0.028  0.042 -0.022  0.010  0.000       
## APSI_8 -0.016 -0.011 -0.041  0.015 -0.037  0.012  0.041  0.000
## 
## $mean
## APSI_1 APSI_2 APSI_3 APSI_4 APSI_5 APSI_6 APSI_7 APSI_8 
##      0      0      0      0      0      0      0      0
View(correl1$cor)
modindices(one.fit, sort. = TRUE, minimum.value = 3.84)
##       lhs op    rhs     mi    epc sepc.lv sepc.all sepc.nox
## 1  APSI_3 ~~ APSI_6 74.786 -0.422  -0.422   -0.297   -0.297
## 2  APSI_3 ~~ APSI_5 51.532  0.198   0.198    0.191    0.191
## 3  APSI_2 ~~ APSI_7 32.449 -0.127  -0.127   -0.102   -0.102
## 4  APSI_1 ~~ APSI_2 28.283  0.122   0.122    0.090    0.090
## 5  APSI_5 ~~ APSI_6 22.837  0.194   0.194    0.130    0.130
## 6  APSI_4 ~~ APSI_7 19.107  0.101   0.101    0.074    0.074
## 7  APSI_2 ~~ APSI_5 18.807  0.098   0.098    0.085    0.085
## 8  APSI_7 ~~ APSI_8 16.690  0.095   0.095    0.070    0.070
## 9  APSI_5 ~~ APSI_8  8.679 -0.069  -0.069   -0.054   -0.054
## 10 APSI_4 ~~ APSI_5  7.580 -0.063  -0.063   -0.050   -0.050
## 11 APSI_1 ~~ APSI_7  6.327 -0.058  -0.058   -0.042   -0.042
## 12 APSI_3 ~~ APSI_8  5.262 -0.062  -0.062   -0.051   -0.051
## 13 APSI_2 ~~ APSI_4  4.841 -0.050  -0.050   -0.037   -0.037
## 14 APSI_1 ~~ APSI_8  4.016 -0.049  -0.049   -0.033   -0.033
fitmeasures(one.fit) #Models as a single purpose factor
##                npar                fmin               chisq 
##              24.000               0.180             290.059 
##                  df              pvalue      baseline.chisq 
##              20.000               0.000            3037.871 
##         baseline.df     baseline.pvalue                 cfi 
##              28.000               0.000               0.910 
##                 tli                nnfi                 rfi 
##               0.874               0.874               0.866 
##                 nfi                pnfi                 ifi 
##               0.905               0.646               0.911 
##                 rni                logl   unrestricted.logl 
##               0.910           -8750.508           -8605.478 
##                 aic                 bic              ntotal 
##           17549.016           17661.655             807.000 
##                bic2               rmsea      rmsea.ci.lower 
##           17585.442               0.129               0.116 
##      rmsea.ci.upper        rmsea.pvalue                 rmr 
##               0.143               0.000               0.080 
##          rmr_nomean                srmr        srmr_bentler 
##               0.089               0.060               0.060 
## srmr_bentler_nomean         srmr_bollen  srmr_bollen_nomean 
##               0.066               0.060               0.066 
##          srmr_mplus   srmr_mplus_nomean               cn_05 
##               0.060               0.066              88.390 
##               cn_01                 gfi                agfi 
##             105.517               0.992               0.981 
##                pgfi                 mfi                ecvi 
##               0.451               0.846                  NA
data <- read.csv("~/Psychometric_study_data/allsurveysYT1.csv")
APSI<-select(data,  APSI_1, APSI_2, APSI_3, APSI_4, APSI_5, APSI_6, APSI_7, APSI_8)
one.model= ' Factor1  =~ APSI_1 + APSI_2 + APSI_4 + APSI_5 + APSI_7 + APSI_8
Factor 2 =~ APSI_3  
Factor 3 =~ APSI_6'
one.fit=cfa(one.model, data=APSI, missing = "fiml")
## Warning in lav_data_full(data = data, group = group, group.label = group.label, : lavaan WARNING: some cases are empty and will be removed:
##   17 22 23 24 28 29 43 45 78 79 80 81 84 85 93 94 95 110 111 112 116 121 122 123 124 125 128 129 130 131 133 135 137 138 140 147 151 152 155 156 162 166 169 170 171 172 173 174 176 177 179 180 183 184 186 187 188 189 192 194 195 197 200 202 203 204 207 208 210 212 214 215 217 220 222 223 224 226 227 228 229 230 234 238 240 243 245 246 247 249 252 255 256 265 266 267 268 270 271 274 275 280 281 282 284 286 287 289 291 292 298 300 304 309 310 311 312 315 316 317 320 322 325 327 330 333 334 336 339 340 344 348 350 351 352 354 355 357 360 361 362 364 365 366 367 368 369 370 371 372 373 374 375 376 377 379 380 381 384 385 386 389 390 397 398 399 400 401 402 403 404 405 406 407 408 410 416 417 418 419 420 421 422 423 424 425 427 428 429 430 431 432 434 436 444 445 446 447 448 452 453 454 455 456 457 459 460 462 463 464 465 467 468 470 472 473 474 475 476 478 481 482 485 486 490 491 493 495 539 540 541 542 543 544 545 546 547 548 549 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 662 679 687 782 783 784 785 809 810 829 903 906 907 909 910 911 1109 1110 1111 1112 1113 1114 1116 1117 1120 1121 1122 1125 1126 1128 1129 1130 1131 1132 1134 1136 1137 1138 1139 1140 1143 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1157 1159 1160
semPaths(one.fit, whatLabels = "std", layout = "tree")

summary(one.fit, standardized = TRUE, rsquare=TRUE)
## lavaan (0.5-18) converged normally after  40 iterations
## 
##                                                   Used       Total
##   Number of observations                           807        1160
## 
##   Number of missing patterns                         1
## 
##   Estimator                                         ML
##   Minimum Function Test Statistic              211.468
##   Degrees of freedom                                19
##   P-value (Chi-square)                           0.000
## 
## Parameter estimates:
## 
##   Information                                 Observed
##   Standard Errors                             Standard
## 
##                    Estimate  Std.err  Z-value  P(>|z|)   Std.lv  Std.all
## Latent variables:
##   Factor1 =~
##     APSI_1            1.000                               1.006    0.827
##     APSI_2            0.838    0.034   24.633    0.000    0.843    0.762
##     APSI_4            0.981    0.037   26.740    0.000    0.987    0.822
##     APSI_5            0.703    0.034   20.795    0.000    0.708    0.676
##     APSI_7            0.870    0.036   24.411    0.000    0.876    0.773
##     APSI_8            0.976    0.037   26.244    0.000    0.982    0.812
##   Factor2 =~
##     APSI_3            1.000                               0.992    1.000
##   Factor3 =~
##     APSI_6            1.000                               1.433    1.000
## 
## Covariances:
##   Factor1 ~~
##     Factor2           0.223    0.038    5.854    0.000    0.223    0.223
##     Factor3           0.115    0.054    2.152    0.031    0.080    0.080
##   Factor2 ~~
##     Factor3          -0.397    0.052   -7.640    0.000   -0.279   -0.279
## 
## Intercepts:
##     APSI_1            3.755    0.043   87.636    0.000    3.755    3.085
##     APSI_2            3.941    0.039  101.111    0.000    3.941    3.559
##     APSI_4            3.871    0.042   91.543    0.000    3.871    3.222
##     APSI_5            4.191    0.037  113.710    0.000    4.191    4.003
##     APSI_7            3.923    0.040   98.399    0.000    3.923    3.464
##     APSI_8            3.874    0.043   90.959    0.000    3.874    3.202
##     APSI_3            3.901    0.035  111.713    0.000    3.901    3.933
##     APSI_6            2.896    0.050   57.407    0.000    2.896    2.021
##     Factor1           0.000                               0.000    0.000
##     Factor2           0.000                               0.000    0.000
##     Factor3           0.000                               0.000    0.000
## 
## Variances:
##     APSI_1            0.469    0.030                      0.469    0.317
##     APSI_2            0.514    0.030                      0.514    0.420
##     APSI_4            0.468    0.030                      0.468    0.324
##     APSI_5            0.595    0.033                      0.595    0.543
##     APSI_7            0.516    0.031                      0.516    0.402
##     APSI_8            0.499    0.031                      0.499    0.341
##     APSI_3            0.000                               0.000    0.000
##     APSI_6            0.000                               0.000    0.000
##     Factor1           1.012    0.073                      1.000    1.000
##     Factor2           0.984    0.049                      1.000    1.000
##     Factor3           2.054    0.102                      1.000    1.000
## 
## R-Square:
## 
##     APSI_1            0.683
##     APSI_2            0.580
##     APSI_4            0.676
##     APSI_5            0.457
##     APSI_7            0.598
##     APSI_8            0.659
##     APSI_3            1.000
##     APSI_6            1.000
correl1 = residuals(one.fit, type="cor")
correl1
## $type
## [1] "cor.bollen"
## 
## $cor
##        APSI_1 APSI_2 APSI_4 APSI_5 APSI_7 APSI_8 APSI_3 APSI_6
## APSI_1  0.000                                                 
## APSI_2  0.052  0.000                                          
## APSI_4 -0.010 -0.021  0.000                                   
## APSI_5  0.018  0.062 -0.035  0.000                            
## APSI_7 -0.023 -0.067  0.042 -0.024  0.000                     
## APSI_8 -0.016 -0.011  0.016 -0.039  0.041  0.000              
## APSI_3 -0.033  0.000 -0.029  0.172  0.026 -0.043  0.000       
## APSI_6 -0.001 -0.036 -0.038  0.114  0.004  0.006  0.000  0.000
## 
## $mean
## APSI_1 APSI_2 APSI_4 APSI_5 APSI_7 APSI_8 APSI_3 APSI_6 
##      0      0      0      0      0      0      0      0
View(correl1$cor)
correl2 = residuals(one.fit, type="standardized")
correl2$cov
##        APSI_1 APSI_2 APSI_4 APSI_5 APSI_7 APSI_8 APSI_3 APSI_6
## APSI_1  0.000                                                 
## APSI_2  4.273     NA                                          
## APSI_4 -1.368 -2.405  0.000                                   
## APSI_5  1.448  3.740 -3.337     NA                            
## APSI_7 -3.007 -8.236  3.622 -1.841     NA                     
## APSI_8 -2.286 -1.108  1.789 -3.619  3.419  0.000              
## APSI_3 -2.009 -0.024 -1.704  6.627  1.280 -2.467  0.000       
## APSI_6 -0.063 -1.709 -2.166  4.496  0.212  0.337  0.000  0.000
View(correl2$cov)
modindices(one.fit, sort. = TRUE, minimum.value = 3.84)
##        lhs op    rhs     mi    epc sepc.lv sepc.all sepc.nox
## 1   APSI_5 ~~ APSI_3 80.403  0.235   0.235    0.227    0.227
## 2  Factor2 =~ APSI_5 50.662  0.210   0.208    0.199    0.199
## 3   APSI_5 ~~ APSI_6 50.650  0.275   0.275    0.183    0.183
## 4   APSI_2 ~~ APSI_7 32.257 -0.127  -0.127   -0.101   -0.101
## 5   APSI_1 ~~ APSI_2 28.678  0.123   0.123    0.091    0.091
## 6  Factor3 =~ APSI_5 21.147  0.091   0.131    0.125    0.125
## 7   APSI_4 ~~ APSI_7 19.492  0.102   0.102    0.075    0.075
## 8   APSI_2 ~~ APSI_5 17.948  0.096   0.096    0.082    0.082
## 9   APSI_7 ~~ APSI_8 16.768  0.096   0.096    0.070    0.070
## 10  APSI_5 ~~ APSI_8  9.580 -0.072  -0.072   -0.057   -0.057
## 11  APSI_4 ~~ APSI_5  8.244 -0.066  -0.066   -0.052   -0.052
## 12  APSI_4 ~~ APSI_6  7.821 -0.103  -0.103   -0.060   -0.060
## 13  APSI_1 ~~ APSI_7  6.266 -0.058  -0.058   -0.042   -0.042
## 14  APSI_4 ~~ APSI_3  5.998 -0.061  -0.061   -0.052   -0.052
## 15  APSI_8 ~~ APSI_3  5.849 -0.062  -0.062   -0.052   -0.052
## 16 Factor2 =~ APSI_8  5.773 -0.069  -0.069   -0.057   -0.057
## 17 Factor3 =~ APSI_4  4.625 -0.041  -0.059   -0.049   -0.049
## 18  APSI_2 ~~ APSI_4  4.360 -0.047  -0.047   -0.036   -0.036
## 19  APSI_1 ~~ APSI_3  4.321 -0.053  -0.053   -0.043   -0.043
## 20  APSI_4 ~~ APSI_8  3.870  0.047   0.047    0.032    0.032
summary(one.fit)
## lavaan (0.5-18) converged normally after  40 iterations
## 
##                                                   Used       Total
##   Number of observations                           807        1160
## 
##   Number of missing patterns                         1
## 
##   Estimator                                         ML
##   Minimum Function Test Statistic              211.468
##   Degrees of freedom                                19
##   P-value (Chi-square)                           0.000
## 
## Parameter estimates:
## 
##   Information                                 Observed
##   Standard Errors                             Standard
## 
##                    Estimate  Std.err  Z-value  P(>|z|)
## Latent variables:
##   Factor1 =~
##     APSI_1            1.000
##     APSI_2            0.838    0.034   24.633    0.000
##     APSI_4            0.981    0.037   26.740    0.000
##     APSI_5            0.703    0.034   20.795    0.000
##     APSI_7            0.870    0.036   24.411    0.000
##     APSI_8            0.976    0.037   26.244    0.000
##   Factor2 =~
##     APSI_3            1.000
##   Factor3 =~
##     APSI_6            1.000
## 
## Covariances:
##   Factor1 ~~
##     Factor2           0.223    0.038    5.854    0.000
##     Factor3           0.115    0.054    2.152    0.031
##   Factor2 ~~
##     Factor3          -0.397    0.052   -7.640    0.000
## 
## Intercepts:
##     APSI_1            3.755    0.043   87.636    0.000
##     APSI_2            3.941    0.039  101.111    0.000
##     APSI_4            3.871    0.042   91.543    0.000
##     APSI_5            4.191    0.037  113.710    0.000
##     APSI_7            3.923    0.040   98.399    0.000
##     APSI_8            3.874    0.043   90.959    0.000
##     APSI_3            3.901    0.035  111.713    0.000
##     APSI_6            2.896    0.050   57.407    0.000
##     Factor1           0.000
##     Factor2           0.000
##     Factor3           0.000
## 
## Variances:
##     APSI_1            0.469    0.030
##     APSI_2            0.514    0.030
##     APSI_4            0.468    0.030
##     APSI_5            0.595    0.033
##     APSI_7            0.516    0.031
##     APSI_8            0.499    0.031
##     APSI_3            0.000
##     APSI_6            0.000
##     Factor1           1.012    0.073
##     Factor2           0.984    0.049
##     Factor3           2.054    0.102
fitmeasures(one.fit) #Models as a single purpose factor
##                npar                fmin               chisq 
##              25.000               0.131             211.468 
##                  df              pvalue      baseline.chisq 
##              19.000               0.000            3037.871 
##         baseline.df     baseline.pvalue                 cfi 
##              28.000               0.000               0.936 
##                 tli                nnfi                 rfi 
##               0.906               0.906               0.897 
##                 nfi                pnfi                 ifi 
##               0.930               0.631               0.936 
##                 rni                logl   unrestricted.logl 
##               0.936           -8711.213           -8605.478 
##                 aic                 bic              ntotal 
##           17472.425           17589.758             807.000 
##                bic2               rmsea      rmsea.ci.lower 
##           17510.369               0.112               0.099 
##      rmsea.ci.upper        rmsea.pvalue                 rmr 
##               0.126               0.000               0.049 
##          rmr_nomean                srmr        srmr_bentler 
##               0.055               0.040               0.040 
## srmr_bentler_nomean         srmr_bollen  srmr_bollen_nomean 
##               0.044               0.040               0.044 
##          srmr_mplus   srmr_mplus_nomean               cn_05 
##               0.040               0.044             116.033 
##               cn_01                 gfi                agfi 
##             139.111               0.994               0.986 
##                pgfi                 mfi                ecvi 
##               0.429               0.888                  NA
inspect(one.fit,what="std")
## $lambda
##        Factr1 Factr2 Factr3
## APSI_1  0.827      0      0
## APSI_2  0.762      0      0
## APSI_4  0.822      0      0
## APSI_5  0.676      0      0
## APSI_7  0.773      0      0
## APSI_8  0.812      0      0
## APSI_3  0.000      1      0
## APSI_6  0.000      0      1
## 
## $theta
##        APSI_1 APSI_2 APSI_4 APSI_5 APSI_7 APSI_8 APSI_3 APSI_6
## APSI_1 0.317                                                  
## APSI_2 0.000  0.420                                           
## APSI_4 0.000  0.000  0.324                                    
## APSI_5 0.000  0.000  0.000  0.543                             
## APSI_7 0.000  0.000  0.000  0.000  0.402                      
## APSI_8 0.000  0.000  0.000  0.000  0.000  0.341               
## APSI_3 0.000  0.000  0.000  0.000  0.000  0.000  0.000        
## APSI_6 0.000  0.000  0.000  0.000  0.000  0.000  0.000  0.000 
## 
## $psi
##         Factr1 Factr2 Factr3
## Factor1  1.000              
## Factor2  0.223  1.000       
## Factor3  0.080 -0.279  1.000
## 
## $nu
##        intrcp
## APSI_1  3.085
## APSI_2  3.559
## APSI_4  3.222
## APSI_5  4.003
## APSI_7  3.464
## APSI_8  3.202
## APSI_3  3.933
## APSI_6  2.021
## 
## $alpha
##         intrcp
## Factor1      0
## Factor2      0
## Factor3      0
fitted(one.fit)
## $cov
##        APSI_1 APSI_2 APSI_4 APSI_5 APSI_7 APSI_8 APSI_3 APSI_6
## APSI_1  1.481                                                 
## APSI_2  0.849  1.226                                          
## APSI_4  0.993  0.833  1.443                                   
## APSI_5  0.712  0.597  0.699  1.096                            
## APSI_7  0.881  0.738  0.864  0.620  1.283                     
## APSI_8  0.988  0.828  0.970  0.695  0.860  1.464              
## APSI_3  0.223  0.187  0.219  0.157  0.194  0.217  0.984       
## APSI_6  0.115  0.097  0.113  0.081  0.100  0.112 -0.397  2.054
## 
## $mean
## APSI_1 APSI_2 APSI_4 APSI_5 APSI_7 APSI_8 APSI_3 APSI_6 
##  3.755  3.941  3.871  4.191  3.923  3.874  3.901  2.896
cov2cor(inspect(one.fit, "coefficients")$psi) 
##         Factr1 Factr2 Factr3
## Factor1  1.000              
## Factor2  0.223  1.000       
## Factor3  0.080 -0.279  1.000
 #Models two factors:Positive and Negative  

Misc code for exportign tabel

#fa.results(out_targetQ)
#xtable(out_targetQ)

#source("http://bioconductor.org/biocLite.R")
#biocLite(c("graph", "RBGL", "Rgraphviz"))
library(Rgraphviz)
## Loading required package: graph
## 
## Attaching package: 'graph'
## 
## The following object is masked from 'package:plyr':
## 
##     join
## 
## Loading required package: grid
library(schoRsch)
## 
## Attaching package: 'schoRsch'
## 
## The following object is masked from 'package:psych':
## 
##     outlier
library(xtable)
library(knitr)
library(xtable)
library(devtools)
## WARNING: Rtools is required to build R packages, but is not currently installed.
## 
## Please download and install Rtools 3.3 from http://cran.r-project.org/bin/windows/Rtools/ and then run find_rtools().
fa2latex(fa(APSI,1,rotate="oblimin", fm="ml"),heading="Table 1. Factor analysis OF APSI as One Factor")
## % Called in the psych package  fa2latex % Called in the psych package  fa(APSI, 1, rotate = "oblimin", fm = "ml") % Called in the psych package  Table 1. Factor analysis OF APSI as One Factor 
## \begin{table}[htdp]\caption{fa2latex}
## \begin{center}
## \begin{scriptsize} 
## \begin{tabular} {l r r r r }
##  \multicolumn{ 4 }{l}{ Table 1. Factor analysis OF APSI as One Factor } \cr 
##  \hline Variable  &   ML1  &  ML1.1  &  ML1.2  &  com \cr 
##   \hline 
## APSI\_1   &  \bf{0.83}  &  0.68  &  0.32  &  1 \cr 
##  APSI\_2   &  \bf{0.76}  &  0.58  &  0.42  &  1 \cr 
##  APSI\_3   &  0.22  &  0.05  &  0.95  &  1 \cr 
##  APSI\_4   &  \bf{0.82}  &  0.68  &  0.32  &  1 \cr 
##  APSI\_5   &  \bf{0.67}  &  0.45  &  0.55  &  1 \cr 
##  APSI\_6   &  0.07  &  0.01  &  0.99  &  1 \cr 
##  APSI\_7   &  \bf{0.77}  &  0.60  &  0.40  &  1 \cr 
##  APSI\_8   &  \bf{0.81}  &  0.66  &  0.34  &  1 \cr 
## \hline \cr SS loadings & 3.71 &  \cr  
##  \hline 
## \end{tabular}
## \end{scriptsize}
## \end{center}
## \label{default}
## \end{table}