[R] creating a path diagram in sem

John Fox jfox at mcmaster.ca
Wed Apr 11 19:45:28 CEST 2007


Dear Dmitri,

path.diagram() takes a fitted "sem" object as its first argument, not a
model-specification object:

> path.diagram(sem.anxiety1,minrank='a1,a2,a3,d1,d2,d3,f1,f2,f3',
maxrank='ANXIETY,DEPRESS,FEAR')

digraph "sem.anxiety1" {
  rankdir=LR;
  size="8,8";
  node [fontname="Helvetica" fontsize=14 shape=box];
  edge [fontname="Helvetica" fontsize=10];
  center=1;
  "ANXIETY" [shape=ellipse]
  "DEPRESS" [shape=ellipse]
  "FEAR" [shape=ellipse]
  "ANXIETY" -> "a1" [label=""];
  "ANXIETY" -> "a2" [label="lam_anx_2"];
  "ANXIETY" -> "a3" [label="lam_anx_3"];
  "DEPRESS" -> "d1" [label=""];
  "DEPRESS" -> "d2" [label="lam_dep_2"];
  "DEPRESS" -> "d3" [label="lam_dep_3"];
  "FEAR" -> "f1" [label=""];
  "FEAR" -> "f2" [label="lam_fear_2"];
  "FEAR" -> "f3" [label="lam_fear_3"];
}

This isn't terribly useful, by the way, unless you have the graphviz
software (reference on ?path.diagram) to draw the graph.

I hope this helps,
 John


On Wed, 11 Apr 2007 09:52:37 -0700 (PDT)
 John Smith <ld7631 at yahoo.com> wrote:
> Hello,
> I finally run my measurement model in sem - successfully. Now, I am
> trying to print out the path diagram that is based on the results -
> but for some reason it's not working. Below is my script - but the
> problem is probably in my very last line:
> 
> # ANALYSIS OF ANXIETY, DEPRESSION, AND FEAR - LISREL P.31
> library(sem)
> # Creating the ANXIETY, DEPRESSION, AND FEAR intercorrelation matrix
> (KM)
> KM<-matrix(
> c(1,.8,.83,.2,.21,.19,.18,.18,.18,
> 0,1,.81,.22,.24,.18,.19,.19,.21,
> 0,0,1,.22,.19,.2,.2,.2,.22,
> 0,0,0,1,.84,.82,.22,.22,.21,
> 0,0,0,0,1,.84,.19,.18,.19,
> 0,0,0,0,0,1,.18,.18,.18,
> 0,0,0,0,0,0,1,.84,.82,
> 0,0,0,0,0,0,0,1,.81,
> 0,0,0,0,0,0,0,0,1), 9, 9)
> 
> # Creating the ANXIETY, DEPRESSION, AND FEAR SDs vector (SD)
> SD<-c(1.5, 2.4, 3.2, 2.3, 2.3, 2.6, 4.5, 4.7, 5.6)
> 
> # Calculating the Var-Covar matrix based on correlations and SDs
> 
> COVAR<-outer(SD, SD) * KM
> 
> # Providing variable names
>
rownames(COVAR)<-colnames(COVAR)<-c('a1','a2','a3','d1','d2','d3','f1','f2','f3')
>  
> # Specifying the measurement model 1
> model1 <- specify.model()
> ANXIETY -> a1, NA, 1
> ANXIETY -> a2, lam_anx_2, NA 
> ANXIETY -> a3, lam_anx_3, NA
> DEPRESS -> d1, NA, 1
> DEPRESS -> d2, lam_dep_2, NA
> DEPRESS -> d3, lam_dep_3, NA
> FEAR -> f1, NA, 1
> FEAR -> f2, lam_fear_2, NA
> FEAR -> f3, lam_fear_3, NA
> a1 <-> a1, theta_a1, NA
> a2 <-> a2, theta_a2, NA
> a3 <-> a3, theta_a3, NA
> d1 <-> d1, theta_d1, NA
> d2 <-> d2, theta_d2, NA
> d3 <-> d3, theta_d3, NA
> f1 <-> f1, theta_f1, NA
> f2 <-> f2, theta_f2, NA
> f3 <-> f3, theta_f3, NA
> ANXIETY <-> ANXIETY, phi_AA, NA
> DEPRESS <-> DEPRESS, phi_DD, NA
> FEAR <-> FEAR, phi_FF, NA
> ANXIETY <-> FEAR, phi_AF, NA
> ANXIETY <-> DEPRESS, phi_AD, NA
> DEPRESS <-> FEAR, phi_DF, NA
> 
> # Running the estimation using sem:
> sem.anxiety1<-sem(model1, COVAR, N=150, par.size="startvalues")
> 
> # Looking at the results:
> summary(sem.anxiety1)
> 
> # Calling modification indices:
> mod.indices(sem.anxiety1)
> summary(mod.indices(sem.anxiety1))
> 
> # Creating a path diagram
> path.diagram(model1,minrank='a1,a2,a3,d1,d2,d3,f1,f2,f3',
> maxrank='ANXIETY,DEPRESS,FEAR')
> 
> Thank you very much for your help!
> Dimitri
> 
> 
>        
>
____________________________________________________________________________________
> TV dinner still cooling? 
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

--------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
http://socserv.mcmaster.ca/jfox/



More information about the R-help mailing list