Skip to content

layout_matrix() can make semPaths() fail with non-numeric argument to binary operator #204

@jorgesinval

Description

@jorgesinval

Hi, thanks for semptools.

I ran into an issue when using a layout created by layout_matrix(). After subsetting to latent nodes, passing the same layout to semPaths() throws an error.

# packages
library(lavaan)
library(semPlot)
library(semptools)

model <- "
# measurement model
visual  =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed   =~ x7 + x8 + x9
g       =~ visual + textual + speed

# latent correlations
visual ~~ textual + speed
textual ~~ speed

# latent regressions
visual + textual + speed ~ g
"

# fit the model
fit <- sem(model, data = HolzingerSwineford1939)

# alternative coordinate layout
m2 <- layout_matrix(
  g       = c(3, 1),
  visual  = c(1, 2),
  textual = c(2, 2),
  speed   = c(4, 2)
)

plot_model <- semPlotModel(fit)

plot_model <- keep_nodes(
  object = plot_model,
  nodes = m2[!is.na(m2)])

# draw the diagram
semPaths(object = plot_model,
  layout = m2)

Error

Error in `l[, 1] - min(l[, 1])`:
! non-numeric argument to binary operator

I believe this error is not related to semptools, but rather to semPlot.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions