5

I use the following code to do sem analysis and draw path diagram with sem R package.

library(sem)

R.DHP <- readMoments(diag=FALSE, names=c('ROccAsp', 'REdAsp', 'FOccAsp', 
                'FEdAsp', 'RParAsp', 'RIQ', 'RSES', 'FSES', 'FIQ', 'FParAsp'))
    .6247                                                              
    .3269  .3669                                                        
    .4216  .3275  .6404                                      
    .2137  .2742  .1124  .0839                                
    .4105  .4043  .2903  .2598  .1839                          
    .3240  .4047  .3054  .2786  .0489  .2220                    
    .2930  .2407  .4105  .3607  .0186  .1861  .2707              
    .2995  .2863  .5191  .5007  .0782  .3355  .2302  .2950        
    .0760  .0702  .2784  .1988  .1147  .1021  .0931 -.0438  .2087  

model.dhp <- specifyModel()
    RParAsp  -> RGenAsp, gam11,  NA
    RIQ      -> RGenAsp, gam12,  NA
    RSES     -> RGenAsp, gam13,  NA
    FSES     -> RGenAsp, gam14,  NA
    RSES     -> FGenAsp, gam23,  NA
    FSES     -> FGenAsp, gam24,  NA
    FIQ      -> FGenAsp, gam25,  NA
    FParAsp  -> FGenAsp, gam26,  NA
    FGenAsp  -> RGenAsp, beta12, NA
    RGenAsp  -> FGenAsp, beta21, NA
    RGenAsp  -> ROccAsp,  NA,       1
    RGenAsp  -> REdAsp,  lam21,  NA
    FGenAsp  -> FOccAsp,  NA,       1
    FGenAsp  -> FEdAsp,  lam42,  NA
    RGenAsp <-> RGenAsp, ps11,   NA
    FGenAsp <-> FGenAsp, ps22,   NA
    RGenAsp <-> FGenAsp, ps12,   NA
    ROccAsp <-> ROccAsp, theta1, NA
    REdAsp  <-> REdAsp,  theta2, NA
    FOccAsp <-> FOccAsp, theta3, NA
    FEdAsp  <-> FEdAsp,  theta4, NA



sem.dhp <- sem(model.dhp, R.DHP, 329,
    fixed.x=c('RParAsp', 'RIQ', 'RSES', 'FSES', 'FIQ', 'FParAsp'))



pathDiagram(sem.dhp, file="Path", min.rank=c("RIQ", "RSES", "RParAsp", "FParAsp", "FSES, FIQ"), 
            max.rank=c("ROccAsp", "REdAsp", "FEdAsp", "FOccAsp"), same.rank=c("RGenAsp", "FGenAsp"),
            ignore.double=TRUE, edge.labels="values", size=c(8, 8), node.font=c("Helvetica", 10), 
            edge.font=c("Helvetica", 10), rank.direction="LR", digits=3,  stdCoef=TRUE,
            output.type=c("graphics", "dot"), graphics.fmt="pdf")

This code produces the following path diagram:

Path Diagram

with this message:

Running  dot -Tpdf -o Path.pdf  Path.dot

When I try to include the code to draw path diagram in .Rnw file, this extra message cause problem. I wonder how to overcome this problem so that I can use the code to create path diagram in Sweave. Thanks in advance for your help and time.

1
  • One solution from @chl is here
    – MYaseen208
    Dec 25, 2011 at 19:10

1 Answer 1

1
\documentclass{article}
\usepackage{graphicx}
\begin{document}
<<echo=TRUE>>=
library(sem)
R.DHP <- readMoments("sem.cov", diag=FALSE, 
                     names=c('ROccAsp', 'REdAsp', 'FOccAsp', 
                       'FEdAsp', 'RParAsp', 'RIQ', 'RSES',  
                       'FSES', 'FIQ', 'FParAsp'))
model.dhp <- specifyModel(file="sem.mod")
sem.dhp <- sem(model.dhp, R.DHP, 329,
               fixed.x=c('RParAsp', 'RIQ', 'RSES', 'FSES', 'FIQ', 'FParAsp'))            
capture.output(pathDiagram(sem.dhp, min.rank='RIQ, RSES, RParAsp, FParAsp, FSES, FIQ', 
            max.rank='ROccAsp, REdAsp, FEdAsp, FOccAsp'), file="sem.dot")
@
<<echo=FALSE>>=
system("dot -Tpdf -o fig1.pdf  sem.dot")
@

And here is the path diagram.

\begin{center}
\includegraphics{fig1}
\end{center}

\end{document}
1
  • Could you add the compile command? Because it doesn't work for me. I get the following error: ! LaTeX Error: File fig1' not found.`.
    – Bobyandbob
    Dec 2, 2017 at 17:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.