Good CFA Chart Plots

When I do the EFA from the psych package, I can generate some really nice paths with correlations and loads, and like this:

enter image description here

using a function fa.diagram

with the following code:

covariances <- ability.cov$cov
correlations <- cov2cor(covariances)
fa.promax <- fa(correlations, nfactors=2, rotate="promax", fm="pa")
fa.diagram(fa.promax, simple=FALSE)


I tend to use CFA more than EFA and would like to be able to model with correlations in the same way. I am using SEM package. I tried the function pathDiagram

, but it only generates code that can then be inserted into GVedit from Graphviz. I do this and there are no factor correlations or correlations. Also, I don't like cut and paste in another program (although the help file from sem for pathDiagram reads: " To get graphics output directly, the dot program must be in the system search path. "; I don't know what to put on the path. what would happen, and if it even had correlations?)

I would like to be able to make a trajectory diagram similar to what psych's fa.diagram does for EFA. I would like to be able to do this in R rather than cut and paste. I don't care which package you use to do this, but I think most people would agree that the simpler the better, and if it can be done inside R, it will give you more freedom in choosing your graphics device.

Here is some sample code for the CFA model to work with:

dat3 <- read.table(url(""), 
            header=T, strip.white = T,, 
            na.strings= c("999", "NA", " "))

NHSDA.cov <- cov(dat3)

ete.mod <- specifyModel() 
F1 -> item3, lam1, NA 
F1 -> item5, lam2, NA 
F1 -> item9, lam3, NA 
F1 -> item10, lam4, NA 
F2 -> item4, lam5, NA 
F2 -> item13, lam6, NA 
F2 -> item14, lam7, NA 
F2 -> item15, lam8, NA 
F3 -> item1, lam9, NA 
F3 -> item6, lam10, NA 
F3 -> item7, lam11, NA 
F3 -> item11, lam12, NA 
F3 -> item12, lam13, NA 
F4 -> item2, lam14, NA 
F4 -> item8, lam15, NA 
F4 -> item16, lam16, NA 
F4 -> item17, lam17, NA 
item1 <-> item1, e1, NA 
item2 <-> item2, e2, NA 
item3 <-> item3, e3, NA 
item4 <-> item4, e4, NA 
item5 <-> item5, e5, NA 
item6 <-> item6, e6, NA 
item7 <-> item7, e7, NA 
item8 <-> item8, e8, NA 
item9 <-> item9, e9, NA 
item10 <-> item10, e10, NA 
item11 <-> item11, e11, NA 
item12 <-> item12, e12, NA 
item13 <-> item13, e13, NA 
item14 <-> item14, e14, NA 
item15 <-> item15, e15, NA 
item16 <-> item16, e16, NA 
item17 <-> item17, e17, NA 
F1 <-> F1, NA, 1
F2 <-> F2, NA, 1
F3 <-> F3, NA, 1
F4 <-> F4, NA, 1
F2 <-> F1, rF1F2 #1
F3 <-> F1, rF1F3 #2
F4 <-> F1, rF1F4 #3
F3 <-> F2, rF2F3 #4
F4 <-> F2, rF2F4 #5
F4 <-> F3, rF3F4 #6

ete.sem <- sem(ete.mod, NHSDA.cov, nrow(dat3)) 
(ete.SUM <- summary(ete.sem))

pathDiagram(ete.sem) #the attempt thus far


Running R 2.14.2 on Win 7


source to share

2 answers

Try it like this:

            , file="PathDiagram"
            , max.rank=paste("item", 1:17, sep="")
            , ignore.double=FALSE
            , edge.labels="values"
            , size=c(8, 8)
            , node.font=c("Helvetica", 10)
            , edge.font=c("Helvetica", 10)
            , rank.direction="LR"
            , digits=3
            , standardize=TRUE
            , graphics.fmt="pdf"


This will create it PathDiagram.pdf

in your working directory. I don't know anyway to display the graph in R.

enter image description here



I had the same problem. You need to install the Graphviz application , which generates a PDF file from a .dot file. This is also explained in the R package pathDiagram help file.



All Articles