library(foreign)
library(mvtnorm)
library(sfsmisc)
library(polycor)
library(lavaan)
x <- read.spss("U:\\MY DOCUMENTS\\tomeqs10.sav")
x <- data.frame(x)
#cov.mat=cov(x,use='pairwise')

p1 <- x$skycon_s
p2 <- x$score1ts
p3 <- x$creacc1s
p4 <- x$creswt1s
p5 <- x$dualtas1
p6 <- x$map1n_sc
p7 <- x$scrdatt2
p8 <- x$code10_s
p9 <- x$walk1_sc
p10 <- x$optot_sc
p11 <- x$agecode
p12 <- x$ageexact
p13 <- x$sex

x <- data.frame(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10)  
opt <- options(fit.indices = c("GFI", "AGFI", "RMSEA", "NFI", "NNFI", "CFI", "RNI", "IFI", "SRMR", "AIC", "AICc", "BIC", "CAIC"))

config.invar<-'#factor loadings
               eta1 =~ p1+p6
               eta2 =~ p4+p10
               eta3 =~ p2+p5+ p7+p8+p9
              #latent variable variances
                      eta1~~eta1
                      eta2~~eta2
                      eta3~~eta3
              #latent variable covariances
                      eta1~~eta2
                      eta1~~eta3
                      eta2~~eta3
              #unique variances
                      p1~~p1
                      p2~~p2
                      p4~~p4
                      p5~~p5
                      p6~~p6
                      p7~~p7
                      p8~~p8
                      p9~~p9
                    p10~~p10'
cfa.fit1<-cfa(config.invar,
                data = x)
summary(cfa.fit1, standardized=T, fit.measures=TRUE)
