qgraph.cfa {qgraph} | R Documentation |
This function performs a simple confirmatory factor analysis using sem (Fox, 2010) or lavaan (Rosseel, 2011).
qgraph.cfa(S, N, groups=NULL, ..., pkg = "sem", labels=NULL, fun = qgraph, opts = list())
S |
A covariance matrix |
N |
The number of observations |
groups |
The groups list, see |
... |
Arguments passed to 'fun' |
pkg |
A string indicating which package should be used for estimating the model. Currently "lavaan" and "sem" (default) are supported |
labels |
A vector indicating the label of each variable |
fun |
A function to which the results are send. Defaults to qgraph, but can be any function that can handle the output (e.g. qgraph.lavaan, qgraph.sem, summary, print). If pkg="sem" then this can also be qgraph.loadings. |
opts |
A list containing arguments that are sent to either |
This function can be used to perform a simple confirmatory factor analasys using regular qgraph input.
The function computes a model and then sends it to sem
(sem; Fox, 2010) or cfa
(lavaan; Rosseel, 2011).
based on the package used either a "sem" object or a "lavaan" object is returned that can be used for manual inspection or to sent to
qgraph.sem
or qgraph.lavaan
.
The model that is estimated is a first order factor model in which each variable loads on one factor and the factors are correlated. This model is specified with the 'groups' argument. This must be a list in which each element represents a factor. Each element of the list must be a vector indicating which variables load on the same factor. The model is identified by fixing the first loading of each factor to 1, which should be an identifying restriction if there are at least 4 variables per factor.
The function also sends its results to another function for visualization. If this is
qgraph
, the default, then a visualization of the standardized coeficients is plotted.
Currently the sem package is better supported in qgraph, but this will change in a future version. Using the lavaan package can greatly reduce computation time.
A "sem" object, see sem
Sacha Epskamp (s.epskamp@uva.nl)
John Fox with contributions from Adam Kramer <jfox@mcmaster.ca> and Michael Friendly (2010). sem: Structural Equation Models. R package version 0.9-21. http://CRAN.R-project.org/package=sem
qgraph
qgraph.sem
qgraph.lavaan
qgraph.loadings
qgraph.semModel
sem
## Not run: # Simulate dataset: set.seed(2) eta<-matrix(rnorm(200*5),ncol=5) lam<-matrix(rnorm(50*5,0,0.15),50,5) lam[apply(diag(5)==1,1,rep,each=10)]<-rnorm(50,0.7,0.3) th<-matrix(rnorm(200*50),ncol=50) Y<-eta%*%t(lam)+th # Create groupslist gr<-list(1:10,11:20,21:30,31:40,41:50) # Using "lavaan" package: res <- qgraph.cfa(cov(Y),N=200,groups=gr,pkg="lavaan",vsize.man=2,vsize.lat=10) qgraph.lavaan(res,filename="lavaan",legend=FALSE,groups=gr,edge.label.cex=0.6) # Using "sem" package: res <- qgraph.cfa(cov(Y),N=200,groups=gr,pkg="sem",vsize.man=2,vsize.lat=10,fun=qgraph.loadings) qgraph.semModel(res,edge.label.cex=0.6) qgraph(res,edge.label.cex=0.6) qgraph.sem(res,filename="sem",legend=FALSE,groups=gr,edge.label.cex=0.6) ### Big 5 dataset ### data(big5) data(big5groups) fit <- qgraph.cfa(cov(big5),nrow(big5),big5groups,pkg="lavaan",opts=list(se="none"), vsize.man=1,vsize.lat=6,edge.label.cex=0.5) print(fit) ## End(Not run)