英文:
R `update()` formula not working as expected
问题
我正在尝试更新由semTools
中的measEq.syntax
函数生成的模型公式。我提供了一个基本模型,该模型可以由measEq.syntax
工作。有时候我想在生成的模型语法中更改一些内容,为此我使用了update
函数,但它不像以前那样工作:
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)'
<sup>创建于2023年07月11日,使用reprex v2.0.2</sup>
英文:
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)'
<sup>Created on 2023-07-11 with reprex v2.0.2</sup>
答案1
得分: 0
我向semTools
包的一位开发者报告了这个问题,他们纠正了包中的错误。然后我只安装了最新的GitHub版本(即版本0.5-6.922),问题得以解决。
remotes::install_github("simsem/semTools/semTools") #版本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)
创建于2023年07月15日,使用reprex v2.0.2.9000
英文:
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)
<sup>Created on 2023-07-15 with reprex v2.0.2.9000</sup>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论