0

I would like to create a path diagram of a SEM model with a categorical response variable using semPaths(). However I am running into an error:

library(lavaan)
library(semPlot)

table.7.5 <-read.table("http://www.da.ugent.be/datasets/Agresti2002.Table.7.5.dat",header=TRUE)

table.7.5$mental <- ordered(table.7.5$mental,levels = c("well","mild","moderate","impaired"))

model <- "mental ~ ses + life"

fit <- sem(model, data=table.7.5)

semPaths(fit,"std",edge.label.cex = 0.5, curvePivot=TRUE,layout = "tree")

Error is:

Error in colnames<-(*tmp*, value = "mental") : attempt to set 'colnames' on an object with less than two dimensions

Thanks

John Conde
  • 217,595
  • 99
  • 455
  • 496
Filipe Dias
  • 284
  • 1
  • 10

2 Answers2

1

The above solution solves the problem for the current CRAN version of semPlots(). In the meantime this issue has been solved in the development version. To install it run:

library(devtools)
install_github("SachaEpskamp/semPlot")

For more details read this:

https://github.com/SachaEpskamp/semPlot/issues/9

Filipe Dias
  • 284
  • 1
  • 10
0

Someone helped me to solve the problem by replacing the content of cov by res.cov. I don't know why but when it's ordered data, lavaan puts the implied covariance matrix in res.cov instead of cov.

All you have to do is this:

fit@SampleStats@cov<-fit@SampleStats@res.cov

Before calling:

semPaths(fit,"std",edge.label.cex = 0.5, curvePivot=TRUE,layout = "tree")
José
  • 921
  • 14
  • 21