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

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

R `update()` formula not working as expected

问题

我正在尝试更新由semTools中的measEq.syntax函数生成的模型公式。我提供了一个基本模型,该模型可以由measEq.syntax工作。有时候我想在生成的模型语法中更改一些内容,为此我使用了update函数,但它不像以前那样工作:

  1. HS.model <- ' visual =~ x1 + x2 + x3
  2. textual =~ x4 + x5 + x6
  3. speed =~ x7 + x8 + x9
  4. general =~ visual + textual + speed'
  5. library(semTools)
  6. #> Loading required package: lavaan
  7. #> This is lavaan 0.6-15
  8. #> lavaan is FREE software! Please report any bugs.
  9. #>
  10. #> ###############################################################################
  11. #> This is semTools 0.5-6
  12. #> All users of R (or SEM) are invited to submit functions or ideas for functions.
  13. #> ###############################################################################
  14. syntax.config <- measEq.syntax(configural.model = HS.model,
  15. data = HolzingerSwineford1939,
  16. ID.fac = "ul",
  17. group = "school")
  18. fixMeans.c <- '
  19. textual ~ c(0, 0)*1
  20. speed ~ c(0, 0)*1
  21. general ~ c(0, 0)*1
  22. '
  23. syntax.config <- update(syntax.config, change.syntax = fixMeans.c)
  24. #> 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:

  1. HS.model &lt;- &#39; visual =~ x1 + x2 + x3
  2. textual =~ x4 + x5 + x6
  3. speed =~ x7 + x8 + x9
  4. general =~ visual + textual + speed&#39;
  5. library(semTools)
  6. #&gt; Loading required package: lavaan
  7. #&gt; This is lavaan 0.6-15
  8. #&gt; lavaan is FREE software! Please report any bugs.
  9. #&gt;
  10. #&gt; ###############################################################################
  11. #&gt; This is semTools 0.5-6
  12. #&gt; All users of R (or SEM) are invited to submit functions or ideas for functions.
  13. #&gt; ###############################################################################
  14. syntax.config &lt;- measEq.syntax(configural.model = HS.model,
  15. data = HolzingerSwineford1939,
  16. ID.fac = &quot;ul&quot;,
  17. group = &quot;school&quot;)
  18. fixMeans.c &lt;- &#39;
  19. textual ~ c(0, 0)*1
  20. speed ~ c(0, 0)*1
  21. general ~ c(0, 0)*1
  22. &#39;
  23. syntax.config &lt;- update(syntax.config, change.syntax = fixMeans.c)
  24. #&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),问题得以解决。

  1. remotes::install_github("simsem/semTools/semTools") #版本0.5-6.922
  2. HS.model <- ' visual =~ x1 + x2 + x3
  3. textual =~ x4 + x5 + x6
  4. speed =~ x7 + x8 + x9
  5. general =~ visual + textual + speed';
  6. library(semTools)
  7. syntax.config <- measEq.syntax(configural.model = HS.model,
  8. data = HolzingerSwineford1939,
  9. ID.fac = "ul",
  10. group = "school")
  11. fixMeans.c <- '
  12. textual ~ c(0, 0)*1
  13. speed ~ c(0, 0)*1
  14. general ~ c(0, 0)*1
  15. ';
  16. 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.

  1. remotes::install_github(&quot;simsem/semTools/semTools&quot;) #version 0.5-6.922
  2. HS.model &lt;- &#39; visual =~ x1 + x2 + x3
  3. textual =~ x4 + x5 + x6
  4. speed =~ x7 + x8 + x9
  5. general =~ visual + textual + speed&#39;
  6. library(semTools)
  7. syntax.config &lt;- measEq.syntax(configural.model = HS.model,
  8. data = HolzingerSwineford1939,
  9. ID.fac = &quot;ul&quot;,
  10. group = &quot;school&quot;)
  11. fixMeans.c &lt;- &#39;
  12. textual ~ c(0, 0)*1
  13. speed ~ c(0, 0)*1
  14. general ~ c(0, 0)*1
  15. &#39;
  16. 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:

确定