R的`update()`公式不按预期工作

huangapple go评论72阅读模式
英文:

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 &lt;- &#39; visual  =~ x1 + x2 + x3
              textual =~ x4 + x5 + x6
              speed   =~ x7 + x8 + x9
              general =~ visual + textual + speed&#39;

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

<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(&quot;simsem/semTools/semTools&quot;) #version 0.5-6.922
HS.model &lt;- &#39; visual  =~ x1 + x2 + x3
              textual =~ x4 + x5 + x6
              speed   =~ x7 + x8 + x9
              general =~ visual + textual + speed&#39;

library(semTools)
syntax.config &lt;- measEq.syntax(configural.model = HS.model,
                               data = HolzingerSwineford1939,
                               ID.fac = &quot;ul&quot;,
                               group = &quot;school&quot;)
fixMeans.c &lt;- &#39;
textual ~ c(0, 0)*1
speed ~ c(0, 0)*1
general ~ c(0, 0)*1
&#39;
syntax.config &lt;- update(syntax.config, change.syntax = fixMeans.c)

<sup>Created on 2023-07-15 with reprex v2.0.2.9000</sup>

huangapple
  • 本文由 发表于 2023年7月11日 10:34:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76658393.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定