Skip to content

store_boot(type="std.all") / standardizedSolution_boot() can fail with dimnames length mismatch when std_names() drops rows via merge() #34

Description

@dgerdesmann

Hi, thanks for making semboottools. I ran into a bootstrapping failure for standardized coefficients that seems to be caused by std_names(). Calling store_boot(..., type = "std.all") and then standardizedSolution_boot() (or any call path that triggers boot_est_std()) failed in a few (but not all) more complex models with:

Error in dimnames(x) <- dn :
  length of 'dimnames' [2] not equal to array extent
Called from: `colnames<-`(`*tmp*`, value = std_names(object))

The error happens when boot_est_std() builds a bootstrap matrix out_all and then does:

colnames(out_all) <- std_names(object)

So if merge(std, ptable, all.y = FALSE) in std_names() returns a data frame with a different number of rows than std, std_names() returns the wrong-length name vector and the colnames<- assignment errors.

I patched this by avoiding merge and relying on if-else label name/finding, so different lengths can't occur:

std_names_nomerge <- function(object, type = "std.all", ...) {
  std <- lavaan::standardizedSolution(
    object, type = type, se = FALSE, output = "data.frame", ...
  )

  lab <- if ("label" %in% names(std)) std$label else rep("", nrow(std))

  out <- ifelse(
    std$op == ":=",
    std$lhs,
    ifelse(!is.na(lab) & lab != "", lab,
           paste(std$lhs, std$op, std$rhs))
  )

  make.unique(out)
}

assignInNamespace("std_names", std_names_nomerge, ns = "semboottools")

Worked for me, but might not be great as a general approach.

Couldn't figure out a minimal repex, so I just described the issue. Hope this helps.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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