Search code examples
rformula

R `update()` formula not working as expected


I am trying to update a model formula produced by measEq.syntax function from semTools. I provide a base model that is worked by measEq.syntax. Sometimes I want to change some stuff in the resulting model syntax, for that propose I used the update function, but it is not working as previously:

HS.model <- ' visual  =~ x1 + x2 + x3
              textual =~ x4 + x5 + x6
              speed   =~ x7 + x8 + x9
              general =~ visual + textual + speed'

library(semTools)
#> Loading required package: lavaan
#> This is lavaan 0.6-15
#> lavaan is FREE software! Please report any bugs.
#> 
#> ###############################################################################
#> This is semTools 0.5-6
#> All users of R (or SEM) are invited to submit functions or ideas for functions.
#> ###############################################################################
syntax.config <- measEq.syntax(configural.model = HS.model,
                               data = HolzingerSwineford1939,
                               ID.fac = "ul",
                               group = "school")
fixMeans.c <- '
textual ~ c(0, 0)*1
speed ~ c(0, 0)*1
general ~ c(0, 0)*1
'
syntax.config <- update(syntax.config, change.syntax = fixMeans.c)
#> Error in nValues > 1L && nValues != nBlocks: 'length = 3' in coercion to 'logical(1)'

Created on 2023-07-11 with reprex v2.0.2


Solution

  • I reported the problem to one of semTools package developers, which corrected the package error. Then I just installed the latest GitHub version (i.e., version 0.5-6.922) and the problem is solved.

    remotes::install_github("simsem/semTools/semTools") #version 0.5-6.922
    HS.model <- ' visual  =~ x1 + x2 + x3
                  textual =~ x4 + x5 + x6
                  speed   =~ x7 + x8 + x9
                  general =~ visual + textual + speed'
    
    library(semTools)
    syntax.config <- measEq.syntax(configural.model = HS.model,
                                   data = HolzingerSwineford1939,
                                   ID.fac = "ul",
                                   group = "school")
    fixMeans.c <- '
    textual ~ c(0, 0)*1
    speed ~ c(0, 0)*1
    general ~ c(0, 0)*1
    '
    syntax.config <- update(syntax.config, change.syntax = fixMeans.c)
    

    Created on 2023-07-15 with reprex v2.0.2.9000