## Loading required package: lavaan
## This is lavaan 0.5-19
## lavaan is BETA software! Please report any bugs.
## Loading required package: psych
## Loading required package: polycor
## Loading required package: mvtnorm
## Loading required package: sfsmisc
##
## Attaching package: 'polycor'
##
## The following object is masked from 'package:psych':
##
## polyserial
##
## Loading required package: semPlot
## Loading required package: ztable
## Welcome to package ztable ver 0.1.5
##
## Attaching package: 'ztable'
##
## The following object is masked from 'package:psych':
##
## tr
##
## Loading required package: pander
##
## Attaching package: 'pander'
##
## The following object is masked from 'package:sfsmisc':
##
## repChar
Se parte de la encuesta realizada por TPR y cuyos resultados se recogen en el fichero ~/git/TPR_2015/DATOS_ENCUESTA.csv.
Para comenzar el análisis procedemos a cargar los datos:
setwd("~/git/TPR_2015/")
datos=read.csv(file="DATOS_ENCUESTA.csv",sep=",",header=TRUE,stringsAsFactors=FALSE)
cold_orig=colnames(datos)
colnames(datos) = paste("C",sprintf("%02d",1:ncol(datos)),sep="")
dfn = data.frame(var=cold_orig,pos=colnames(datos),stringsAsFactors = FALSE)
dat=datos
for (j in 1:ncol(datos)) {
dat[,j] = as.factor(datos[,j])
}
etq=c("C03","C04","C05","C09","C24","C25","C26", "C27", "C28", "C29", "C48")
Ahora procedemos a calcular las covarianzas, que al ser variables nominales no podemos aplicar la función cov, sino que tenemos que aplicar el coeficiente V de Cramer (paquete vcd, funcion assocstats) o bien la función hetcor (Correlación heterogenea) del paquete polycor. Usamos esta última.
hcor=function(data) hetcor(data,std.err = FALSE)$correlations
rdat=hcor(dat[,etq])
Una vez definidas las columnas creamos el modelo SEM de interés:
# mod.sem=specifyModel(file="modelo01.sem")
mod.sem='
# Variables latentes
org =~ C09 + C29
pers =~ C24 + C25 + C26
reqf =~ C03 + C04
# org =~ C09 + C29 + C28 + C48
# pers =~ C24 + C25 + C26 + C27
# reqf =~ C03 + C04 + C05
# Regresiones
reqf ~ org + pers
# Covarianza de residuos
C03 ~~ C04
C03 ~~ C05
'
#
dd=dat[,etq]
dd[,etq]=lapply(dat[,etq],ordered)
mod.sem.1=sem(mod.sem,data=dd)
## Warning in pc_cor_TS(fit.y1 = FIT[[i]], fit.y2 = FIT[[j]], method =
## optim.method, : lavaan WARNING: empty cell(s) in bivariate table of C29 x
## C09
## Warning in pc_cor_TS(fit.y1 = FIT[[i]], fit.y2 = FIT[[j]], method =
## optim.method, : lavaan WARNING: empty cell(s) in bivariate table of C04 x
## C09
## Warning in pc_cor_TS(fit.y1 = FIT[[i]], fit.y2 = FIT[[j]], method =
## optim.method, : lavaan WARNING: empty cell(s) in bivariate table of C05 x
## C09
## Warning in pc_cor_TS(fit.y1 = FIT[[i]], fit.y2 = FIT[[j]], method =
## optim.method, : lavaan WARNING: empty cell(s) in bivariate table of C04 x
## C29
## Warning in pc_cor_TS(fit.y1 = FIT[[i]], fit.y2 = FIT[[j]], method =
## optim.method, : lavaan WARNING: empty cell(s) in bivariate table of C05 x
## C29
## Warning in pc_cor_TS(fit.y1 = FIT[[i]], fit.y2 = FIT[[j]], method =
## optim.method, : lavaan WARNING: empty cell(s) in bivariate table of C25 x
## C24
## Warning in pc_cor_TS(fit.y1 = FIT[[i]], fit.y2 = FIT[[j]], method =
## optim.method, : lavaan WARNING: empty cell(s) in bivariate table of C26 x
## C24
## Warning in pc_cor_TS(fit.y1 = FIT[[i]], fit.y2 = FIT[[j]], method =
## optim.method, : lavaan WARNING: empty cell(s) in bivariate table of C04 x
## C24
## Warning in pc_cor_TS(fit.y1 = FIT[[i]], fit.y2 = FIT[[j]], method =
## optim.method, : lavaan WARNING: empty cell(s) in bivariate table of C05 x
## C24
## Warning in pc_cor_TS(fit.y1 = FIT[[i]], fit.y2 = FIT[[j]], method =
## optim.method, : lavaan WARNING: empty cell(s) in bivariate table of C04 x
## C25
## Warning in pc_cor_TS(fit.y1 = FIT[[i]], fit.y2 = FIT[[j]], method =
## optim.method, : lavaan WARNING: empty cell(s) in bivariate table of C05 x
## C25
## Warning in pc_cor_TS(fit.y1 = FIT[[i]], fit.y2 = FIT[[j]], method =
## optim.method, : lavaan WARNING: empty cell(s) in bivariate table of C04 x
## C26
## Warning in pc_cor_TS(fit.y1 = FIT[[i]], fit.y2 = FIT[[j]], method =
## optim.method, : lavaan WARNING: empty cell(s) in bivariate table of C05 x
## C26
## Warning in pc_cor_TS(fit.y1 = FIT[[i]], fit.y2 = FIT[[j]], method =
## optim.method, : lavaan WARNING: empty cell(s) in bivariate table of C04 x
## C03
## Warning in pc_cor_TS(fit.y1 = FIT[[i]], fit.y2 = FIT[[j]], method =
## optim.method, : lavaan WARNING: empty cell(s) in bivariate table of C05 x
## C03
## Warning in pc_cor_TS(fit.y1 = FIT[[i]], fit.y2 = FIT[[j]], method =
## optim.method, : lavaan WARNING: empty cell(s) in bivariate table of C05 x
## C04
## Found more than one class "Model" in cache; using the first, from namespace 'lavaan'
## Warning in lav_model_vcov(lavmodel = lavmodel, lavsamplestats = lavsamplestats, : lavaan WARNING: could not compute standard errors!
## lavaan NOTE: this may be a symptom that the model is not identified.
## Warning in lav_model_test(lavmodel = lavmodel, lavpartable = lavpartable, : lavaan WARNING: could not compute scaled test statistic
semPaths(mod.sem.1)
print <- function(...) UseMethod("pander") # makes sure that everyhing that everyprint will pass through pander
summary(mod.sem.1)
## lavaan (0.5-19) converged normally after 51 iterations
##
## Number of observations 237
##
## Estimator DWLS Robust
## Minimum Function Test Statistic 31.407 NA
## Degrees of freedom 16 16
## P-value (Chi-square) 0.012 NA
## Scaling correction factor NA
## Shift parameter
## for simple second-order correction (Mplus variant)
##
## Parameter Estimates:
##
## Information Expected
## Standard Errors Robust.sem
##
## Latent Variables:
## Estimate Std.Err Z-value P(>|z|)
## org =~
## C09 1.000
## C29 3.935
## pers =~
## C24 1.000
## C25 0.728
## C26 0.626
## reqf =~
## C03 1.000
## C04 0.022
##
## Regressions:
## Estimate Std.Err Z-value P(>|z|)
## reqf ~
## org -0.789
## pers -0.188
##
## Covariances:
## Estimate Std.Err Z-value P(>|z|)
## C03 ~~
## C04 0.097
## C05 0.099
## org ~~
## pers 0.031
##
## Intercepts:
## Estimate Std.Err Z-value P(>|z|)
## C09 0.000
## C29 0.000
## C24 0.000
## C25 0.000
## C26 0.000
## C03 0.000
## C04 0.000
## C05 0.000
## org 0.000
## pers 0.000
## reqf 0.000
##
## Thresholds:
## Estimate Std.Err Z-value P(>|z|)
## C09|t1 0.058
## C09|t2 0.705
## C29|t1 0.229
## C29|t2 0.732
## C29|t3 1.274
## C29|t4 1.888
## C24|t1 0.587
## C24|t2 1.299
## C25|t1 0.101
## C25|t2 0.803
## C26|t1 -1.084
## C26|t2 -0.273
## C26|t3 0.526
## C03|t1 -1.143
## C03|t2 0.111
## C04|t1 -2.389
## C04|t2 -0.746
## C04|t3 0.587
## C05|t1 -2.634
## C05|t2 -0.959
## C05|t3 0.351
##
## Variances:
## Estimate Std.Err Z-value P(>|z|)
## C09 0.983
## C29 0.735
## C24 0.011
## C25 0.476
## C26 0.613
## C03 0.895
## C04 1.000
## C05 1.000
## org 0.017
## pers 0.989
## reqf 0.050
##
## Scales y*:
## Estimate Std.Err Z-value P(>|z|)
## C09 1.000
## C29 1.000
## C24 1.000
## C25 1.000
## C26 1.000
## C03 1.000
## C04 1.000
## C05 1.000