SEM代码篇----R详细实现

<div id="article_content" class="article_content clearfix">
        <link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/ck_htmledit_views-6e43165c0a.css">
                <div id="content_views" class="markdown_views prism-atom-one-light">
                    <svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
                        <path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></path>
                    </svg>
                    <h1><a name="t0"></a><a id="SEMR_1"></a>SEM代码篇----R详细实现</h1> 
<h2><a name="t1"></a><a id="1_step1_3"></a>1. step1:安装包</h2> 
<pre data-index="0" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;"># install.packages("lavaan")
#install.packages("semPlot")
#install.packages("semTools")
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li></ul></pre> 
<pre data-index="1" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">rm(list=ls()) #清除所有变量
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li></ul></pre> 
<pre data-index="2" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">library(lavaan)
library(semPlot)
library(semTools)
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li></ul></pre> 
<pre data-index="3" class="prettyprint"><code class="has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">This is lavaan 0.6-7

lavaan is BETA software! Please report any bugs.

Warning message:
"package 'semPlot' was built under R version 3.5.3"
 

###############################################################################

This is semTools 0.5-3

All users of R (or SEM) are invited to submit functions or ideas for functions.

###############################################################################
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li></ul></pre> 
<h2><a name="t2"></a><a id="2_lavvan__42"></a>2. lavvan 语法简介</h2> 
<h3><a name="t3"></a><a id="_43"></a>主要公式类型和其他运算符</h3> 
<p><img src="https://img-blog.csdnimg.cn/20201205201729982.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3MxMTY0NTQ4NTE1,size_16,color_FFFFFF,t_70#pic_center" alt="在这里插入图片描述"></p> 
<h3><a name="t4"></a><a id="cfasem_48"></a>cfa()和sem()拟合函数的参数</h3> 
<pre data-index="4" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">sem(model = NULL, data = NULL, meanstructure = "default",
fixed.x = "default", orthogonal = FALSE, std.lv = FALSE,
parameterization = "default", std.ov = FALSE, missing = "default",
ordered = NULL, sample.cov = NULL, sample.cov.rescale = "default",
sample.mean = NULL, sample.nobs = NULL, ridge = 1e-05, group = NULL,
group.label = NULL, group.equal = "", group.partial = "",
group.w.free = FALSE, cluster = NULL, constraints = "",
estimator = "default",
likelihood = "default", link = "default", information = "default",
se = "default", test = "default", bootstrap = 1000L, mimic = "default",
representation = "default", do.fit = TRUE, control = list(),
WLS.V = NULL, NACOV = NULL,
zero.add = "default", zero.keep.margins = "default",
start = "default", verbose = FALSE, warn = TRUE, debug = FALSE)
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li></ul></pre> 
<h3><a name="t5"></a><a id="lavvan_68"></a>lavvan()拟合函数的参数</h3> 
<pre data-index="5" class="set-code-hide prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">lavaan(model = NULL, data = NULL, model.type = "sem",
meanstructure = "default",
int.ov.free = FALSE, int.lv.free = FALSE, fixed.x = "default",
orthogonal = FALSE, std.lv = FALSE, parameterization = "default",
auto.fix.first = FALSE, auto.fix.single = FALSE, auto.var = FALSE,
auto.cov.lv.x = FALSE, auto.cov.y = FALSE, auto.th = FALSE,
auto.delta = FALSE, std.ov = FALSE, missing = "default",
ordered = NULL, sample.cov = NULL, sample.cov.rescale = "default",
sample.mean = NULL, sample.nobs = NULL, ridge = 1e-05, group = NULL,
group.label = NULL, group.equal = "", group.partial = "",
group.w.free = FALSE, cluster = NULL, constraints = "",
estimator = "default",
likelihood = "default", link = "default", information = "default",
se = "default", test = "default", bootstrap = 1000L, mimic = "default",
representation = "default", do.fit = TRUE, control = list(),
WLS.V = NULL, NACOV = NULL,
zero.add = "default", zero.keep.margins = "default",
start = "default", slotOptions = NULL, slotParTable = NULL,
slotSampleStats = NULL, slotData = NULL, slotModel = NULL,
verbose = FALSE, warn = TRUE, debug = FALSE)
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{&quot;spm&quot;:&quot;1001.2101.3001.7365&quot;}"><img class="look-more-preCode contentImg-no-view" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png" alt="" title=""></span></div><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li></ul></pre> 
<h3><a name="t6"></a><a id="_94"></a>提取函数:检查合适的模型</h3> 
<p><img src="https://img-blog.csdnimg.cn/20201205201754393.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3MxMTY0NTQ4NTE1,size_16,color_FFFFFF,t_70#pic_center" alt="在这里插入图片描述"></p> 
<h2><a name="t7"></a><a id="3__SEM_98"></a>3. SEM形式</h2> 
<h3><a name="t8"></a><a id="_100"></a>示例数据生成</h3> 
<p><img src="https://img-blog.csdnimg.cn/20201205201807663.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3MxMTY0NTQ4NTE1,size_16,color_FFFFFF,t_70#pic_center" alt="在这里插入图片描述"></p> 
<pre data-index="6" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">set.seed(1)
n=100
x1 &lt;- rnorm(n) * 10
x2 &lt;- rnorm(n) * 10
x3 &lt;- rnorm(n) * 10
x4 &lt;- rnorm(n) * 10
y &lt;- 100 + 5*x1 + (-2)*x2 + 1*x3 + 0.1*x4 + rnorm(n, sd=40)
y1 &lt;- 100 + 5*x1 + (-2)*x2 + 1*x3 + 0.1*x4 + rnorm(n, sd=40)
y2 &lt;- 10 + 0.5*x1 + (-2.5)*x2 + 0.1*x3 + 1*x4 + rnorm(n, sd=20)
x5 &lt;- rbeta(n,2,5)
x6 &lt;- rchisq(n,5)
x7 &lt;- rnorm(n,5)
myData &lt;- data.frame(y,x1,x2,x3,x4,y1,y2,x5,x6,x7)
# write.csv(myData, file = "semData1.csv")#保存匹配数据
# myData &lt;- read.csv("semData1.csv",header = TRUE)
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li></ul></pre> 
<h3><a name="t9"></a><a id="_124"></a>简单回归示例</h3> 
<p><img src="https://img-blog.csdnimg.cn/20201205201823708.png#pic_center" alt="在这里插入图片描述"></p> 
<p>回归模型:<br> <img src="https://img-blog.csdnimg.cn/20201205201835564.png#pic_center" alt="在这里插入图片描述"></p> 
<pre data-index="7" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">sem_Model1 &lt;- ' y ~ x1+x2+x3+x4 '
#线性回归
fit1_1 &lt;- lm(formula = sem_Model1, data = myData)
summary(fit1_1)
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li></ul></pre> 
<pre data-index="8" class="set-code-hide prettyprint"><code class="has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">Call:
lm(formula = sem_Model1, data = myData)

Residuals:
     Min       1Q   Median       3Q      Max 
-102.372  -29.458   -3.658   27.275  148.404 

Coefficients:
            Estimate Std. Error t value Pr(&gt;|t|)    
(Intercept)  97.7210     4.7200  20.704   &lt;2e-16 ***
x1            5.7733     0.5238  11.022   &lt;2e-16 ***
x2           -1.3214     0.4917  -2.688   0.0085 ** 
x3            1.1350     0.4575   2.481   0.0149 *  
x4            0.2707     0.4779   0.566   0.5724    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 46.74 on 95 degrees of freedom
Multiple R-squared:  0.5911,    Adjusted R-squared:  0.5738 
F-statistic: 34.33 on 4 and 95 DF,  p-value: &lt; 2.2e-16
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{&quot;spm&quot;:&quot;1001.2101.3001.7365&quot;}"><img class="look-more-preCode contentImg-no-view" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png" alt="" title=""></span></div><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li></ul></pre> 
<pre data-index="9" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;"># lavaan
fit1_2 &lt;- sem(model = sem_Model1,data = myData)
summary(fit1_2)
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li></ul></pre> 
<pre data-index="10" class="set-code-hide prettyprint"><code class="has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">lavaan 0.6-7 ended normally after 32 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of free parameters                          5
                                                      
  Number of observations                           100
                                                      
Model Test User Model:
                                                      
  Test statistic                                 0.000
  Degrees of freedom                                 0

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured

Regressions:
                   Estimate  Std.Err  z-value  P(&gt;|z|)
  y ~                                                 
    x1                5.773    0.511   11.309    0.000
    x2               -1.321    0.479   -2.757    0.006
    x3                1.135    0.446    2.545    0.011
    x4                0.271    0.466    0.581    0.561

Variances:
                   Estimate  Std.Err  z-value  P(&gt;|z|)
   .y              2075.100  293.463    7.071    0.000
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{&quot;spm&quot;:&quot;1001.2101.3001.7365&quot;}"><img class="look-more-preCode contentImg-no-view" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png" alt="" title=""></span></div><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li><li style="color: rgb(153, 153, 153);">29</li><li style="color: rgb(153, 153, 153);">30</li></ul></pre> 
<p>注:fit1 和 fit2 Std.err存在微小差异的原因</p> 
<p><img src="https://img-blog.csdnimg.cn/20201205201900339.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3MxMTY0NTQ4NTE1,size_16,color_FFFFFF,t_70#pic_center" alt="在这里插入图片描述"></p> 
<h3><a name="t10"></a><a id="_206"></a>多元因变量回归</h3> 
<p><img src="https://img-blog.csdnimg.cn/20201205201911763.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3MxMTY0NTQ4NTE1,size_16,color_FFFFFF,t_70#pic_center" alt="在这里插入图片描述"></p> 
<pre data-index="11" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">sem_Model2 &lt;- 'y1 ~ x1 + x2 + x3 + x4
y2 ~ x1 + x2 + x3 + x4 '
fit2 &lt;- sem(model = sem_Model2,data = myData)
summary(fit2)
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li></ul></pre> 
<pre data-index="12" class="set-code-hide prettyprint"><code class="has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">lavaan 0.6-7 ended normally after 62 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of free parameters                         11
                                                      
  Number of observations                           100
                                                      
Model Test User Model:
                                                      
  Test statistic                                 0.000
  Degrees of freedom                                 0

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured

Regressions:
                   Estimate  Std.Err  z-value  P(&gt;|z|)
  y1 ~                                                
    x1                4.507    0.426   10.588    0.000
    x2               -2.112    0.400   -5.284    0.000
    x3                0.888    0.372    2.388    0.017
    x4               -0.294    0.388   -0.757    0.449
  y2 ~                                                
    x1                0.693    0.237    2.924    0.003
    x2               -2.721    0.223  -12.230    0.000
    x3                0.043    0.207    0.210    0.834
    x4                0.724    0.216    3.345    0.001

Covariances:
                   Estimate  Std.Err  z-value  P(&gt;|z|)
 .y1 ~~                                               
   .y2                0.906   80.345    0.011    0.991

Variances:
                   Estimate  Std.Err  z-value  P(&gt;|z|)
   .y1             1442.879  204.054    7.071    0.000
   .y2              447.393   63.271    7.071    0.000
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{&quot;spm&quot;:&quot;1001.2101.3001.7365&quot;}"><img class="look-more-preCode contentImg-no-view" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png" alt="" title=""></span></div><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li><li style="color: rgb(153, 153, 153);">29</li><li style="color: rgb(153, 153, 153);">30</li><li style="color: rgb(153, 153, 153);">31</li><li style="color: rgb(153, 153, 153);">32</li><li style="color: rgb(153, 153, 153);">33</li><li style="color: rgb(153, 153, 153);">34</li><li style="color: rgb(153, 153, 153);">35</li><li style="color: rgb(153, 153, 153);">36</li><li style="color: rgb(153, 153, 153);">37</li><li style="color: rgb(153, 153, 153);">38</li><li style="color: rgb(153, 153, 153);">39</li><li style="color: rgb(153, 153, 153);">40</li><li style="color: rgb(153, 153, 153);">41</li></ul></pre> 
<h3><a name="t11"></a><a id="_262"></a>递归路径分析</h3> 
<p><img src="https://img-blog.csdnimg.cn/20201205201923787.jpg#pic_center" alt="在这里插入图片描述"></p> 
<pre data-index="13" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">sem_Model3 &lt;- 'x5 ~ x1 + x2 + x3
x6 ~ x4 + x5
x7 ~ x6'
fit3 &lt;- sem(model = sem_Model3,data = myData)
summary(fit3)
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li></ul></pre> 
<pre data-index="14" class="set-code-hide prettyprint"><code class="has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">lavaan 0.6-7 ended normally after 47 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of free parameters                          9
                                                      
  Number of observations                           100
                                                      
Model Test User Model:
                                                      
  Test statistic                                 7.447
  Degrees of freedom                                 9
  P-value (Chi-square)                           0.591

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured

Regressions:
                   Estimate  Std.Err  z-value  P(&gt;|z|)
  x5 ~                                                
    x1               -0.001    0.002   -0.269    0.788
    x2               -0.001    0.002   -0.295    0.768
    x3               -0.001    0.002   -0.445    0.657
  x6 ~                                                
    x4               -0.006    0.033   -0.174    0.862
    x5                0.217    1.789    0.121    0.903
  x7 ~                                                
    x6               -0.014    0.034   -0.399    0.690

Variances:
                   Estimate  Std.Err  z-value  P(&gt;|z|)
   .x5                0.033    0.005    7.071    0.000
   .x6               10.714    1.515    7.071    0.000
   .x7                1.242    0.176    7.071    0.000
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{&quot;spm&quot;:&quot;1001.2101.3001.7365&quot;}"><img class="look-more-preCode contentImg-no-view" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png" alt="" title=""></span></div><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li><li style="color: rgb(153, 153, 153);">29</li><li style="color: rgb(153, 153, 153);">30</li><li style="color: rgb(153, 153, 153);">31</li><li style="color: rgb(153, 153, 153);">32</li><li style="color: rgb(153, 153, 153);">33</li><li style="color: rgb(153, 153, 153);">34</li><li style="color: rgb(153, 153, 153);">35</li><li style="color: rgb(153, 153, 153);">36</li><li style="color: rgb(153, 153, 153);">37</li></ul></pre> 
<h3><a name="t12"></a><a id="_315"></a>中介分析</h3> 
<p><img src="https://img-blog.csdnimg.cn/202012052019384.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3MxMTY0NTQ4NTE1,size_16,color_FFFFFF,t_70#pic_center" alt="在这里插入图片描述"></p> 
<pre data-index="15" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">sem_Model4 &lt;- '
y ~ b*y1 + c*y2
y1 ~ a*y2
indirect := a*b
total  := c + (a*b)
'
fit4 &lt;- sem(model = sem_Model4,data  = myData,se  = "bootstrap")
summary(fit4)
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li></ul></pre> 
<pre data-index="16" class="set-code-hide prettyprint"><code class="has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">lavaan 0.6-7 ended normally after 18 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of free parameters                          5
                                                      
  Number of observations                           100
                                                      
Model Test User Model:
                                                      
  Test statistic                                 0.000
  Degrees of freedom                                 0

Parameter Estimates:

  Standard errors                            Bootstrap
  Number of requested bootstrap draws             1000
  Number of successful bootstrap draws            1000

Regressions:
                   Estimate  Std.Err  z-value  P(&gt;|z|)
  y ~                                                 
    y1         (b)    0.602    0.104    5.788    0.000
    y2         (c)    0.240    0.167    1.435    0.151
  y1 ~                                                
    y2         (a)    0.625    0.166    3.759    0.000

Variances:
                   Estimate  Std.Err  z-value  P(&gt;|z|)
   .y              3477.433  629.078    5.528    0.000
   .y1             3114.961  406.549    7.662    0.000

Defined Parameters:
                   Estimate  Std.Err  z-value  P(&gt;|z|)
    indirect          0.376    0.111    3.405    0.001
    total             0.617    0.171    3.608    0.000
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{&quot;spm&quot;:&quot;1001.2101.3001.7365&quot;}"><img class="look-more-preCode contentImg-no-view" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png" alt="" title=""></span></div><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li><li style="color: rgb(153, 153, 153);">29</li><li style="color: rgb(153, 153, 153);">30</li><li style="color: rgb(153, 153, 153);">31</li><li style="color: rgb(153, 153, 153);">32</li><li style="color: rgb(153, 153, 153);">33</li><li style="color: rgb(153, 153, 153);">34</li><li style="color: rgb(153, 153, 153);">35</li><li style="color: rgb(153, 153, 153);">36</li></ul></pre> 
<h3><a name="t13"></a><a id="_370"></a>路径图绘制</h3> 
<pre data-index="17" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">pdf("./img/SEM形式.pdf")
p = semPaths(fit1_2)
p1=semPaths(object = fit1_2,whatLabels = "std", edge.label.cex = 1)
p2 = semPaths(fit2)
p3 = semPaths(fit3)
p4 = semPaths(fit4)
dev.off()
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li></ul></pre> 
<p><strong>png:</strong> 2</p> 
<h2><a name="t14"></a><a id="4_1_387"></a>4. 实例分析1</h2> 
<p><img src="https://img-blog.csdnimg.cn/20201205201951282.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3MxMTY0NTQ4NTE1,size_16,color_FFFFFF,t_70#pic_center" alt="在这里插入图片描述"></p> 
<h3><a name="t15"></a><a id="_391"></a>读取数据</h3> 
<p>该示例数据为lavvan包自带</p> 
<p>数据集HolzingerSwineford1939,该数据集内嵌在lavaan包中</p> 
<h3><a name="t16"></a><a id="_396"></a>构建模型</h3> 
<h4><a id="CFA_397"></a>使用CFA</h4> 
<pre data-index="18" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">HSmodel_1 &lt;- 'visual  =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed  =~ x7 + x8 + x9
'
fit5_1 &lt;- cfa(model = HSmodel_1,data  = HolzingerSwineford1939)
summary(fit5_1, fit.measures = TRUE,standardized = TRUE)
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li></ul></pre> 
<pre data-index="19" class="set-code-hide prettyprint"><code class="has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">lavaan 0.6-7 ended normally after 35 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of free parameters                         21
                                                      
  Number of observations                           301
                                                      
Model Test User Model:
                                                      
  Test statistic                                85.306
  Degrees of freedom                                24
  P-value (Chi-square)                           0.000

Model Test Baseline Model:

  Test statistic                               918.852
  Degrees of freedom                                36
  P-value                                        0.000

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    0.931
  Tucker-Lewis Index (TLI)                       0.896

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)              -3737.745
  Loglikelihood unrestricted model (H1)      -3695.092
                                                      
  Akaike (AIC)                                7517.490
  Bayesian (BIC)                              7595.339
  Sample-size adjusted Bayesian (BIC)         7528.739

Root Mean Square Error of Approximation:

  RMSEA                                          0.092
  90 Percent confidence interval - lower         0.071
  90 Percent confidence interval - upper         0.114
  P-value RMSEA &lt;= 0.05                          0.001

Standardized Root Mean Square Residual:

  SRMR                                           0.065

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured

Latent Variables:
                   Estimate  Std.Err  z-value  P(&gt;|z|)   Std.lv  Std.all
  visual =~                                                             
    x1                1.000                               0.900    0.772
    x2                0.554    0.100    5.554    0.000    0.498    0.424
    x3                0.729    0.109    6.685    0.000    0.656    0.581
  textual =~                                                            
    x4                1.000                               0.990    0.852
    x5                1.113    0.065   17.014    0.000    1.102    0.855
    x6                0.926    0.055   16.703    0.000    0.917    0.838
  speed =~                                                              
    x7                1.000                               0.619    0.570
    x8                1.180    0.165    7.152    0.000    0.731    0.723
    x9                1.082    0.151    7.155    0.000    0.670    0.665

Covariances:
                   Estimate  Std.Err  z-value  P(&gt;|z|)   Std.lv  Std.all
  visual ~~                                                             
    textual           0.408    0.074    5.552    0.000    0.459    0.459
    speed             0.262    0.056    4.660    0.000    0.471    0.471
  textual ~~                                                            
    speed             0.173    0.049    3.518    0.000    0.283    0.283

Variances:
                   Estimate  Std.Err  z-value  P(&gt;|z|)   Std.lv  Std.all
   .x1                0.549    0.114    4.833    0.000    0.549    0.404
   .x2                1.134    0.102   11.146    0.000    1.134    0.821
   .x3                0.844    0.091    9.317    0.000    0.844    0.662
   .x4                0.371    0.048    7.779    0.000    0.371    0.275
   .x5                0.446    0.058    7.642    0.000    0.446    0.269
   .x6                0.356    0.043    8.277    0.000    0.356    0.298
   .x7                0.799    0.081    9.823    0.000    0.799    0.676
   .x8                0.488    0.074    6.573    0.000    0.488    0.477
   .x9                0.566    0.071    8.003    0.000    0.566    0.558
    visual            0.809    0.145    5.564    0.000    1.000    1.000
    textual           0.979    0.112    8.737    0.000    1.000    1.000
    speed             0.384    0.086    4.451    0.000    1.000    1.000
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{&quot;spm&quot;:&quot;1001.2101.3001.7365&quot;}"><img class="look-more-preCode contentImg-no-view" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png" alt="" title=""></span></div><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li><li style="color: rgb(153, 153, 153);">29</li><li style="color: rgb(153, 153, 153);">30</li><li style="color: rgb(153, 153, 153);">31</li><li style="color: rgb(153, 153, 153);">32</li><li style="color: rgb(153, 153, 153);">33</li><li style="color: rgb(153, 153, 153);">34</li><li style="color: rgb(153, 153, 153);">35</li><li style="color: rgb(153, 153, 153);">36</li><li style="color: rgb(153, 153, 153);">37</li><li style="color: rgb(153, 153, 153);">38</li><li style="color: rgb(153, 153, 153);">39</li><li style="color: rgb(153, 153, 153);">40</li><li style="color: rgb(153, 153, 153);">41</li><li style="color: rgb(153, 153, 153);">42</li><li style="color: rgb(153, 153, 153);">43</li><li style="color: rgb(153, 153, 153);">44</li><li style="color: rgb(153, 153, 153);">45</li><li style="color: rgb(153, 153, 153);">46</li><li style="color: rgb(153, 153, 153);">47</li><li style="color: rgb(153, 153, 153);">48</li><li style="color: rgb(153, 153, 153);">49</li><li style="color: rgb(153, 153, 153);">50</li><li style="color: rgb(153, 153, 153);">51</li><li style="color: rgb(153, 153, 153);">52</li><li style="color: rgb(153, 153, 153);">53</li><li style="color: rgb(153, 153, 153);">54</li><li style="color: rgb(153, 153, 153);">55</li><li style="color: rgb(153, 153, 153);">56</li><li style="color: rgb(153, 153, 153);">57</li><li style="color: rgb(153, 153, 153);">58</li><li style="color: rgb(153, 153, 153);">59</li><li style="color: rgb(153, 153, 153);">60</li><li style="color: rgb(153, 153, 153);">61</li><li style="color: rgb(153, 153, 153);">62</li><li style="color: rgb(153, 153, 153);">63</li><li style="color: rgb(153, 153, 153);">64</li><li style="color: rgb(153, 153, 153);">65</li><li style="color: rgb(153, 153, 153);">66</li><li style="color: rgb(153, 153, 153);">67</li><li style="color: rgb(153, 153, 153);">68</li><li style="color: rgb(153, 153, 153);">69</li><li style="color: rgb(153, 153, 153);">70</li><li style="color: rgb(153, 153, 153);">71</li><li style="color: rgb(153, 153, 153);">72</li><li style="color: rgb(153, 153, 153);">73</li><li style="color: rgb(153, 153, 153);">74</li><li style="color: rgb(153, 153, 153);">75</li><li style="color: rgb(153, 153, 153);">76</li><li style="color: rgb(153, 153, 153);">77</li><li style="color: rgb(153, 153, 153);">78</li><li style="color: rgb(153, 153, 153);">79</li><li style="color: rgb(153, 153, 153);">80</li><li style="color: rgb(153, 153, 153);">81</li><li style="color: rgb(153, 153, 153);">82</li><li style="color: rgb(153, 153, 153);">83</li><li style="color: rgb(153, 153, 153);">84</li><li style="color: rgb(153, 153, 153);">85</li><li style="color: rgb(153, 153, 153);">86</li><li style="color: rgb(153, 153, 153);">87</li><li style="color: rgb(153, 153, 153);">88</li></ul></pre> 
<pre data-index="20" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">#当均值结构参数设置为真时meanstructure=TRUE,均值结构被添加到模型中
fit5_11 &lt;- cfa(model = HSmodel_1, data=HolzingerSwineford1939, meanstructure=TRUE)
summary(fit5_11)
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li></ul></pre> 
<pre data-index="21" class="set-code-hide prettyprint"><code class="has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">lavaan 0.6-5 ended normally after 35 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of free parameters                         30
                                                      
  Number of observations                           301
                                                      
Model Test User Model:
                                                      
  Test statistic                                85.306
  Degrees of freedom                                24
  P-value (Chi-square)                           0.000

Parameter Estimates:

  Information                                 Expected
  Information saturated (h1) model          Structured
  Standard errors                             Standard

Latent Variables:
                   Estimate  Std.Err  z-value  P(&gt;|z|)
  visual =~                                           
    x1                1.000                           
    x2                0.554    0.100    5.554    0.000
    x3                0.729    0.109    6.685    0.000
  textual =~                                          
    x4                1.000                           
    x5                1.113    0.065   17.014    0.000
    x6                0.926    0.055   16.703    0.000
  speed =~                                            
    x7                1.000                           
    x8                1.180    0.165    7.152    0.000
    x9                1.082    0.151    7.155    0.000

Covariances:
                   Estimate  Std.Err  z-value  P(&gt;|z|)
  visual ~~                                           
    textual           0.408    0.074    5.552    0.000
    speed             0.262    0.056    4.660    0.000
  textual ~~                                          
    speed             0.173    0.049    3.518    0.000

Intercepts:
                   Estimate  Std.Err  z-value  P(&gt;|z|)
   .x1                4.936    0.067   73.473    0.000
   .x2                6.088    0.068   89.855    0.000
   .x3                2.250    0.065   34.579    0.000
   .x4                3.061    0.067   45.694    0.000
   .x5                4.341    0.074   58.452    0.000
   .x6                2.186    0.063   34.667    0.000
   .x7                4.186    0.063   66.766    0.000
   .x8                5.527    0.058   94.854    0.000
   .x9                5.374    0.058   92.546    0.000
    visual            0.000                           
    textual           0.000                           
    speed             0.000                           

Variances:
                   Estimate  Std.Err  z-value  P(&gt;|z|)
   .x1                0.549    0.114    4.833    0.000
   .x2                1.134    0.102   11.146    0.000
   .x3                0.844    0.091    9.317    0.000
   .x4                0.371    0.048    7.779    0.000
   .x5                0.446    0.058    7.642    0.000
   .x6                0.356    0.043    8.277    0.000
   .x7                0.799    0.081    9.823    0.000
   .x8                0.488    0.074    6.573    0.000
   .x9                0.566    0.071    8.003    0.000
    visual            0.809    0.145    5.564    0.000
    textual           0.979    0.112    8.737    0.000
    speed             0.384    0.086    4.451    0.000
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{&quot;spm&quot;:&quot;1001.2101.3001.7365&quot;}"><img class="look-more-preCode contentImg-no-view" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png" alt="" title=""></span></div><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li><li style="color: rgb(153, 153, 153);">29</li><li style="color: rgb(153, 153, 153);">30</li><li style="color: rgb(153, 153, 153);">31</li><li style="color: rgb(153, 153, 153);">32</li><li style="color: rgb(153, 153, 153);">33</li><li style="color: rgb(153, 153, 153);">34</li><li style="color: rgb(153, 153, 153);">35</li><li style="color: rgb(153, 153, 153);">36</li><li style="color: rgb(153, 153, 153);">37</li><li style="color: rgb(153, 153, 153);">38</li><li style="color: rgb(153, 153, 153);">39</li><li style="color: rgb(153, 153, 153);">40</li><li style="color: rgb(153, 153, 153);">41</li><li style="color: rgb(153, 153, 153);">42</li><li style="color: rgb(153, 153, 153);">43</li><li style="color: rgb(153, 153, 153);">44</li><li style="color: rgb(153, 153, 153);">45</li><li style="color: rgb(153, 153, 153);">46</li><li style="color: rgb(153, 153, 153);">47</li><li style="color: rgb(153, 153, 153);">48</li><li style="color: rgb(153, 153, 153);">49</li><li style="color: rgb(153, 153, 153);">50</li><li style="color: rgb(153, 153, 153);">51</li><li style="color: rgb(153, 153, 153);">52</li><li style="color: rgb(153, 153, 153);">53</li><li style="color: rgb(153, 153, 153);">54</li><li style="color: rgb(153, 153, 153);">55</li><li style="color: rgb(153, 153, 153);">56</li><li style="color: rgb(153, 153, 153);">57</li><li style="color: rgb(153, 153, 153);">58</li><li style="color: rgb(153, 153, 153);">59</li><li style="color: rgb(153, 153, 153);">60</li><li style="color: rgb(153, 153, 153);">61</li><li style="color: rgb(153, 153, 153);">62</li><li style="color: rgb(153, 153, 153);">63</li><li style="color: rgb(153, 153, 153);">64</li><li style="color: rgb(153, 153, 153);">65</li><li style="color: rgb(153, 153, 153);">66</li><li style="color: rgb(153, 153, 153);">67</li><li style="color: rgb(153, 153, 153);">68</li><li style="color: rgb(153, 153, 153);">69</li><li style="color: rgb(153, 153, 153);">70</li><li style="color: rgb(153, 153, 153);">71</li><li style="color: rgb(153, 153, 153);">72</li></ul></pre> 
<h4><a id="SEM_582"></a>使用SEM</h4> 
<pre data-index="22" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">fit5_2 &lt;- cfa(model = HSmodel_1,data  = HolzingerSwineford1939)
summary(fit5_2, fit.measures = TRUE,standardized = TRUE)
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li></ul></pre> 
<pre data-index="23" class="set-code-hide prettyprint"><code class="has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">lavaan 0.6-7 ended normally after 35 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of free parameters                         21
                                                      
  Number of observations                           301
                                                      
Model Test User Model:
                                                      
  Test statistic                                85.306
  Degrees of freedom                                24
  P-value (Chi-square)                           0.000

Model Test Baseline Model:

  Test statistic                               918.852
  Degrees of freedom                                36
  P-value                                        0.000

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    0.931
  Tucker-Lewis Index (TLI)                       0.896

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)              -3737.745
  Loglikelihood unrestricted model (H1)      -3695.092
                                                      
  Akaike (AIC)                                7517.490
  Bayesian (BIC)                              7595.339
  Sample-size adjusted Bayesian (BIC)         7528.739

Root Mean Square Error of Approximation:

  RMSEA                                          0.092
  90 Percent confidence interval - lower         0.071
  90 Percent confidence interval - upper         0.114
  P-value RMSEA &lt;= 0.05                          0.001

Standardized Root Mean Square Residual:

  SRMR                                           0.065

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured

Latent Variables:
                   Estimate  Std.Err  z-value  P(&gt;|z|)   Std.lv  Std.all
  visual =~                                                             
    x1                1.000                               0.900    0.772
    x2                0.554    0.100    5.554    0.000    0.498    0.424
    x3                0.729    0.109    6.685    0.000    0.656    0.581
  textual =~                                                            
    x4                1.000                               0.990    0.852
    x5                1.113    0.065   17.014    0.000    1.102    0.855
    x6                0.926    0.055   16.703    0.000    0.917    0.838
  speed =~                                                              
    x7                1.000                               0.619    0.570
    x8                1.180    0.165    7.152    0.000    0.731    0.723
    x9                1.082    0.151    7.155    0.000    0.670    0.665

Covariances:
                   Estimate  Std.Err  z-value  P(&gt;|z|)   Std.lv  Std.all
  visual ~~                                                             
    textual           0.408    0.074    5.552    0.000    0.459    0.459
    speed             0.262    0.056    4.660    0.000    0.471    0.471
  textual ~~                                                            
    speed             0.173    0.049    3.518    0.000    0.283    0.283

Variances:
                   Estimate  Std.Err  z-value  P(&gt;|z|)   Std.lv  Std.all
   .x1                0.549    0.114    4.833    0.000    0.549    0.404
   .x2                1.134    0.102   11.146    0.000    1.134    0.821
   .x3                0.844    0.091    9.317    0.000    0.844    0.662
   .x4                0.371    0.048    7.779    0.000    0.371    0.275
   .x5                0.446    0.058    7.642    0.000    0.446    0.269
   .x6                0.356    0.043    8.277    0.000    0.356    0.298
   .x7                0.799    0.081    9.823    0.000    0.799    0.676
   .x8                0.488    0.074    6.573    0.000    0.488    0.477
   .x9                0.566    0.071    8.003    0.000    0.566    0.558
    visual            0.809    0.145    5.564    0.000    1.000    1.000
    textual           0.979    0.112    8.737    0.000    1.000    1.000
    speed             0.384    0.086    4.451    0.000    1.000    1.000
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{&quot;spm&quot;:&quot;1001.2101.3001.7365&quot;}"><img class="look-more-preCode contentImg-no-view" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png" alt="" title=""></span></div><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li><li style="color: rgb(153, 153, 153);">29</li><li style="color: rgb(153, 153, 153);">30</li><li style="color: rgb(153, 153, 153);">31</li><li style="color: rgb(153, 153, 153);">32</li><li style="color: rgb(153, 153, 153);">33</li><li style="color: rgb(153, 153, 153);">34</li><li style="color: rgb(153, 153, 153);">35</li><li style="color: rgb(153, 153, 153);">36</li><li style="color: rgb(153, 153, 153);">37</li><li style="color: rgb(153, 153, 153);">38</li><li style="color: rgb(153, 153, 153);">39</li><li style="color: rgb(153, 153, 153);">40</li><li style="color: rgb(153, 153, 153);">41</li><li style="color: rgb(153, 153, 153);">42</li><li style="color: rgb(153, 153, 153);">43</li><li style="color: rgb(153, 153, 153);">44</li><li style="color: rgb(153, 153, 153);">45</li><li style="color: rgb(153, 153, 153);">46</li><li style="color: rgb(153, 153, 153);">47</li><li style="color: rgb(153, 153, 153);">48</li><li style="color: rgb(153, 153, 153);">49</li><li style="color: rgb(153, 153, 153);">50</li><li style="color: rgb(153, 153, 153);">51</li><li style="color: rgb(153, 153, 153);">52</li><li style="color: rgb(153, 153, 153);">53</li><li style="color: rgb(153, 153, 153);">54</li><li style="color: rgb(153, 153, 153);">55</li><li style="color: rgb(153, 153, 153);">56</li><li style="color: rgb(153, 153, 153);">57</li><li style="color: rgb(153, 153, 153);">58</li><li style="color: rgb(153, 153, 153);">59</li><li style="color: rgb(153, 153, 153);">60</li><li style="color: rgb(153, 153, 153);">61</li><li style="color: rgb(153, 153, 153);">62</li><li style="color: rgb(153, 153, 153);">63</li><li style="color: rgb(153, 153, 153);">64</li><li style="color: rgb(153, 153, 153);">65</li><li style="color: rgb(153, 153, 153);">66</li><li style="color: rgb(153, 153, 153);">67</li><li style="color: rgb(153, 153, 153);">68</li><li style="color: rgb(153, 153, 153);">69</li><li style="color: rgb(153, 153, 153);">70</li><li style="color: rgb(153, 153, 153);">71</li><li style="color: rgb(153, 153, 153);">72</li><li style="color: rgb(153, 153, 153);">73</li><li style="color: rgb(153, 153, 153);">74</li><li style="color: rgb(153, 153, 153);">75</li><li style="color: rgb(153, 153, 153);">76</li><li style="color: rgb(153, 153, 153);">77</li><li style="color: rgb(153, 153, 153);">78</li><li style="color: rgb(153, 153, 153);">79</li><li style="color: rgb(153, 153, 153);">80</li><li style="color: rgb(153, 153, 153);">81</li><li style="color: rgb(153, 153, 153);">82</li><li style="color: rgb(153, 153, 153);">83</li><li style="color: rgb(153, 153, 153);">84</li><li style="color: rgb(153, 153, 153);">85</li><li style="color: rgb(153, 153, 153);">86</li><li style="color: rgb(153, 153, 153);">87</li><li style="color: rgb(153, 153, 153);">88</li></ul></pre> 
<h4><a id="lavvan_681"></a>使用lavvan</h4> 
<pre data-index="24" class="set-code-hide prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">HSmodel_3 &lt;- '
# latent variables
visual  =~ 1*x1 + x2 + x3
textual =~ 1*x4 + x5 + x6
speed  =~ 1*x7 + x8 + x9
# factor (co)variances
visual  ~~ visual; visual  ~~ textual; visual  ~~ speed
textual ~~ textual; textual ~~ speed
speed  ~~ speed
# residual variances
x1 ~~ x1; x2 ~~ x2; x3 ~~ x3
x4 ~~ x4; x5 ~~ x5; x6 ~~ x6
x7 ~~ x7; x8 ~~ x8; x9 ~~ x9
'

fit5_3 &lt;- lavaan(model = HSmodel_3, data  = HolzingerSwineford1939)
summary(fit5_3, fit.measures=TRUE,standardized=TRUE)
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{&quot;spm&quot;:&quot;1001.2101.3001.7365&quot;}"><img class="look-more-preCode contentImg-no-view" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png" alt="" title=""></span></div><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li></ul></pre> 
<pre data-index="25" class="set-code-hide prettyprint"><code class="has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">lavaan 0.6-7 ended normally after 35 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of free parameters                         21
                                                      
  Number of observations                           301
                                                      
Model Test User Model:
                                                      
  Test statistic                                85.306
  Degrees of freedom                                24
  P-value (Chi-square)                           0.000

Model Test Baseline Model:

  Test statistic                               918.852
  Degrees of freedom                                36
  P-value                                        0.000

User Model versus Baseline Model:

  Comparative Fit Index (CFI)                    0.931
  Tucker-Lewis Index (TLI)                       0.896

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)              -3737.745
  Loglikelihood unrestricted model (H1)      -3695.092
                                                      
  Akaike (AIC)                                7517.490
  Bayesian (BIC)                              7595.339
  Sample-size adjusted Bayesian (BIC)         7528.739

Root Mean Square Error of Approximation:

  RMSEA                                          0.092
  90 Percent confidence interval - lower         0.071
  90 Percent confidence interval - upper         0.114
  P-value RMSEA &lt;= 0.05                          0.001

Standardized Root Mean Square Residual:

  SRMR                                           0.065

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured

Latent Variables:
                   Estimate  Std.Err  z-value  P(&gt;|z|)   Std.lv  Std.all
  visual =~                                                             
    x1                1.000                               0.900    0.772
    x2                0.554    0.100    5.554    0.000    0.498    0.424
    x3                0.729    0.109    6.685    0.000    0.656    0.581
  textual =~                                                            
    x4                1.000                               0.990    0.852
    x5                1.113    0.065   17.014    0.000    1.102    0.855
    x6                0.926    0.055   16.703    0.000    0.917    0.838
  speed =~                                                              
    x7                1.000                               0.619    0.570
    x8                1.180    0.165    7.152    0.000    0.731    0.723
    x9                1.082    0.151    7.155    0.000    0.670    0.665

Covariances:
                   Estimate  Std.Err  z-value  P(&gt;|z|)   Std.lv  Std.all
  visual ~~                                                             
    textual           0.408    0.074    5.552    0.000    0.459    0.459
    speed             0.262    0.056    4.660    0.000    0.471    0.471
  textual ~~                                                            
    speed             0.173    0.049    3.518    0.000    0.283    0.283

Variances:
                   Estimate  Std.Err  z-value  P(&gt;|z|)   Std.lv  Std.all
    visual            0.809    0.145    5.564    0.000    1.000    1.000
    textual           0.979    0.112    8.737    0.000    1.000    1.000
    speed             0.384    0.086    4.451    0.000    1.000    1.000
   .x1                0.549    0.114    4.833    0.000    0.549    0.404
   .x2                1.134    0.102   11.146    0.000    1.134    0.821
   .x3                0.844    0.091    9.317    0.000    0.844    0.662
   .x4                0.371    0.048    7.779    0.000    0.371    0.275
   .x5                0.446    0.058    7.642    0.000    0.446    0.269
   .x6                0.356    0.043    8.277    0.000    0.356    0.298
   .x7                0.799    0.081    9.823    0.000    0.799    0.676
   .x8                0.488    0.074    6.573    0.000    0.488    0.477
   .x9                0.566    0.071    8.003    0.000    0.566    0.558
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{&quot;spm&quot;:&quot;1001.2101.3001.7365&quot;}"><img class="look-more-preCode contentImg-no-view" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png" alt="" title=""></span></div><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li><li style="color: rgb(153, 153, 153);">29</li><li style="color: rgb(153, 153, 153);">30</li><li style="color: rgb(153, 153, 153);">31</li><li style="color: rgb(153, 153, 153);">32</li><li style="color: rgb(153, 153, 153);">33</li><li style="color: rgb(153, 153, 153);">34</li><li style="color: rgb(153, 153, 153);">35</li><li style="color: rgb(153, 153, 153);">36</li><li style="color: rgb(153, 153, 153);">37</li><li style="color: rgb(153, 153, 153);">38</li><li style="color: rgb(153, 153, 153);">39</li><li style="color: rgb(153, 153, 153);">40</li><li style="color: rgb(153, 153, 153);">41</li><li style="color: rgb(153, 153, 153);">42</li><li style="color: rgb(153, 153, 153);">43</li><li style="color: rgb(153, 153, 153);">44</li><li style="color: rgb(153, 153, 153);">45</li><li style="color: rgb(153, 153, 153);">46</li><li style="color: rgb(153, 153, 153);">47</li><li style="color: rgb(153, 153, 153);">48</li><li style="color: rgb(153, 153, 153);">49</li><li style="color: rgb(153, 153, 153);">50</li><li style="color: rgb(153, 153, 153);">51</li><li style="color: rgb(153, 153, 153);">52</li><li style="color: rgb(153, 153, 153);">53</li><li style="color: rgb(153, 153, 153);">54</li><li style="color: rgb(153, 153, 153);">55</li><li style="color: rgb(153, 153, 153);">56</li><li style="color: rgb(153, 153, 153);">57</li><li style="color: rgb(153, 153, 153);">58</li><li style="color: rgb(153, 153, 153);">59</li><li style="color: rgb(153, 153, 153);">60</li><li style="color: rgb(153, 153, 153);">61</li><li style="color: rgb(153, 153, 153);">62</li><li style="color: rgb(153, 153, 153);">63</li><li style="color: rgb(153, 153, 153);">64</li><li style="color: rgb(153, 153, 153);">65</li><li style="color: rgb(153, 153, 153);">66</li><li style="color: rgb(153, 153, 153);">67</li><li style="color: rgb(153, 153, 153);">68</li><li style="color: rgb(153, 153, 153);">69</li><li style="color: rgb(153, 153, 153);">70</li><li style="color: rgb(153, 153, 153);">71</li><li style="color: rgb(153, 153, 153);">72</li><li style="color: rgb(153, 153, 153);">73</li><li style="color: rgb(153, 153, 153);">74</li><li style="color: rgb(153, 153, 153);">75</li><li style="color: rgb(153, 153, 153);">76</li><li style="color: rgb(153, 153, 153);">77</li><li style="color: rgb(153, 153, 153);">78</li><li style="color: rgb(153, 153, 153);">79</li><li style="color: rgb(153, 153, 153);">80</li><li style="color: rgb(153, 153, 153);">81</li><li style="color: rgb(153, 153, 153);">82</li><li style="color: rgb(153, 153, 153);">83</li><li style="color: rgb(153, 153, 153);">84</li><li style="color: rgb(153, 153, 153);">85</li><li style="color: rgb(153, 153, 153);">86</li><li style="color: rgb(153, 153, 153);">87</li><li style="color: rgb(153, 153, 153);">88</li></ul></pre> 
<h3><a name="t17"></a><a id="_795"></a>多组别分析</h3> 
<p><img src="https://img-blog.csdnimg.cn/20201205202025213.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3MxMTY0NTQ4NTE1,size_16,color_FFFFFF,t_70#pic_center" alt="在这里插入图片描述"></p> 
<pre data-index="26" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;"># model 1: configural invariance
fit5_41 &lt;- cfa(HSmodel_1, data=HolzingerSwineford1939, group="school")
# model 2: weak invariance
fit5_42 &lt;- cfa(HSmodel_1, data=HolzingerSwineford1939, group="school",group.equal="loadings")
# model 3: strong invariance
fit5_43 &lt;- cfa(HSmodel_1, data=HolzingerSwineford1939, group="school",group.equal=c("loadings", "intercepts"))
# model 4: equal loadings + intercepts + means
fit5_44 &lt;- cfa(HSmodel_1, data=HolzingerSwineford1939, group="school",group.equal=c("loadings", "intercepts", "means"))
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li></ul></pre> 
<h3><a name="t18"></a><a id="anova_810"></a>两模型比较(anova)</h3> 
<pre data-index="27" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">anova(fit5_41, fit5_42)
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li></ul></pre> 
<div class="table-box"><table><caption>
  A anova: 2 × 7
 </caption><thead><tr><th></th><th>Df</th><th>AIC</th><th>BIC</th><th>Chisq</th><th>Chisq diff</th><th>Df diff</th><th>Pr(&gt;Chisq)</th></tr><tr><th></th><th>&lt;int&gt;</th><th>&lt;dbl&gt;</th><th>&lt;dbl&gt;</th><th>&lt;dbl&gt;</th><th>&lt;dbl&gt;</th><th>&lt;int&gt;</th><th>&lt;dbl&gt;</th></tr></thead><tbody><tr><th>fit5_41</th><td>48</td><td>7484.395</td><td>7706.822</td><td>115.8513</td><td> NA</td><td>NA</td><td> NA</td></tr><tr><th>fit5_42</th><td>54</td><td>7480.587</td><td>7680.771</td><td>124.0435</td><td>8.1922</td><td> 6</td><td>0.2243577</td></tr></tbody></table></div> 
<h3><a name="t19"></a><a id="semTools__measurementInvariance_832"></a>测量不变性检验(semTools -&gt; measurementInvariance)</h3> 
<p>两两比较</p> 
<pre data-index="28" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">measurementInvariance(HSmodel_1, data=HolzingerSwineford1939,group="school", strict=FALSE)
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li></ul></pre> 
<p>结果略</p> 
<h3><a name="t20"></a><a id="___FIML__full_informationmaximum_likelihood__estimation_844"></a>缺失数据处理 FIML ( full informationmaximum likelihood ) estimation</h3> 
<p>1) 随机缺失(lavvan中可解决)</p> 
<p>MCAR (missing completely at random):数据缺失完全随机,估计结果无偏</p> 
<p>MAR (missing at random):缺失数据不依赖于缺失数据本身,可能与未缺失数据有关</p> 
<p>2)非随机缺失</p> 
<p>NMAR(not missing at random): 一般来说,几乎所有的标准统计方法都不再有效。我们只能试着了解其缺失机制,并在建模数据时考虑到这一点。</p> 
<pre data-index="29" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">fit5_5 &lt;- cfa(HSmodel_1, data = HSmissing,missing = "ml")  # or missing = "fiml"
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li></ul></pre> 
<h3><a name="t21"></a><a id="_861"></a>绘制路径图</h3> 
<pre data-index="30" class="set-code-hide prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">dev.new()
pdf("./img/实例分析1.pdf")
#初始图
fitname = fit5_3
p = semPaths(fitname)
#含系数的图
p1=semPaths(object = fitname,whatLabels = "std", edge.label.cex = 1)
#不同形状的图
p2=semPaths(object = fitname,layout = "circle")
p3=semPaths(object = fitname,layout = "tree2")
p4=semPaths(object = fitname,layout = "circle2")
p5=semPaths(object = fitname,layout = "spring")
#旋转图
p6 = semPaths(fitname,rotation=2)
#线条颜色设置
p7 = semPaths(fitname,rotation=2,edge.color = "blue")
#变量颜色设置
p8 = semPaths(fitname,rotation=2,edge.color = "blue",color = "lightblue",whatLabels = "std", edge.label.cex = 1)
#分组

p9 = semPaths(fit5_41,rotation=2,edge.color = "blue",color = "lightblue",whatLabels = "std", edge.label.cex = 1 )

p10 = semPaths(fit5_41,rotation=2,whatLabels = "std", edge.label.cex = 1,groups="latents" )

dev.off()
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{&quot;spm&quot;:&quot;1001.2101.3001.7365&quot;}"><img class="look-more-preCode contentImg-no-view" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png" alt="" title=""></span></div><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li></ul></pre> 
<p><strong>png:</strong> 2</p> 
<h2><a name="t22"></a><a id="5_2SEM_896"></a>5. 实例分析2(带约束的SEM)</h2> 
<p><img src="https://img-blog.csdnimg.cn/20201205202048599.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3MxMTY0NTQ4NTE1,size_16,color_FFFFFF,t_70#pic_center" alt="在这里插入图片描述"></p> 
<h3><a name="t23"></a><a id="_900"></a>模型构建</h3> 
<pre data-index="31" class="set-code-hide prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">PDmodel &lt;- '
# latent variable definitions
ind60 =~ x1 + x2 + x3
dem60 =~ y1 + a*y2 + b*y3 + c*y4
dem65 =~ y5 + a*y6 + b*y7 + c*y8
# regressions
dem60 ~ ind60
dem65 ~ ind60 + dem60
# residual covariances
y1 ~~ y5
y2 ~~ y4 + y6
y3 ~~ y7
y4 ~~ y8
y6 ~~ y8
'

<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{&quot;spm&quot;:&quot;1001.2101.3001.7365&quot;}"><img class="look-more-preCode contentImg-no-view" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png" alt="" title=""></span></div><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li></ul></pre> 
<h3><a name="t24"></a><a id="_922"></a>结果输出</h3> 
<pre data-index="32" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">fit6 &lt;- sem(PDmodel, data=PoliticalDemocracy)
summary(fit6, standardized=TRUE)
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li></ul></pre> 
<pre data-index="33" class="set-code-hide prettyprint"><code class="has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">lavaan 0.6-7 ended normally after 66 iterations

  Estimator                                         ML
  Optimization method                           NLMINB
  Number of free parameters                         31
  Number of equality constraints                     3
                                                      
  Number of observations                            75
                                                      
Model Test User Model:
                                                      
  Test statistic                                40.179
  Degrees of freedom                                38
  P-value (Chi-square)                           0.374

Parameter Estimates:

  Standard errors                             Standard
  Information                                 Expected
  Information saturated (h1) model          Structured

Latent Variables:
                   Estimate  Std.Err  z-value  P(&gt;|z|)   Std.lv  Std.all
  ind60 =~                                                              
    x1                1.000                               0.670    0.920
    x2                2.180    0.138   15.751    0.000    1.460    0.973
    x3                1.818    0.152   11.971    0.000    1.218    0.872
  dem60 =~                                                              
    y1                1.000                               2.201    0.850
    y2         (a)    1.191    0.139    8.551    0.000    2.621    0.690
    y3         (b)    1.175    0.120    9.755    0.000    2.586    0.758
    y4         (c)    1.251    0.117   10.712    0.000    2.754    0.838
  dem65 =~                                                              
    y5                1.000                               2.154    0.817
    y6         (a)    1.191    0.139    8.551    0.000    2.565    0.755
    y7         (b)    1.175    0.120    9.755    0.000    2.530    0.802
    y8         (c)    1.251    0.117   10.712    0.000    2.694    0.829

Regressions:
                   Estimate  Std.Err  z-value  P(&gt;|z|)   Std.lv  Std.all
  dem60 ~                                                               
    ind60             1.471    0.392    3.750    0.000    0.448    0.448
  dem65 ~                                                               
    ind60             0.600    0.226    2.661    0.008    0.187    0.187
    dem60             0.865    0.075   11.554    0.000    0.884    0.884

Covariances:
                   Estimate  Std.Err  z-value  P(&gt;|z|)   Std.lv  Std.all
 .y1 ~~                                                                 
   .y5                0.583    0.356    1.637    0.102    0.583    0.281
 .y2 ~~                                                                 
   .y4                1.440    0.689    2.092    0.036    1.440    0.291
   .y6                2.183    0.737    2.960    0.003    2.183    0.356
 .y3 ~~                                                                 
   .y7                0.712    0.611    1.165    0.244    0.712    0.169
 .y4 ~~                                                                 
   .y8                0.363    0.444    0.817    0.414    0.363    0.111
 .y6 ~~                                                                 
   .y8                1.372    0.577    2.378    0.017    1.372    0.338

Variances:
                   Estimate  Std.Err  z-value  P(&gt;|z|)   Std.lv  Std.all
   .x1                0.081    0.019    4.182    0.000    0.081    0.154
   .x2                0.120    0.070    1.729    0.084    0.120    0.053
   .x3                0.467    0.090    5.177    0.000    0.467    0.239
   .y1                1.855    0.433    4.279    0.000    1.855    0.277
   .y2                7.581    1.366    5.549    0.000    7.581    0.525
   .y3                4.956    0.956    5.182    0.000    4.956    0.426
   .y4                3.225    0.723    4.458    0.000    3.225    0.298
   .y5                2.313    0.479    4.831    0.000    2.313    0.333
   .y6                4.968    0.921    5.393    0.000    4.968    0.430
   .y7                3.560    0.710    5.018    0.000    3.560    0.357
   .y8                3.308    0.704    4.701    0.000    3.308    0.313
    ind60             0.449    0.087    5.175    0.000    1.000    1.000
   .dem60             3.875    0.866    4.477    0.000    0.800    0.800
   .dem65             0.164    0.227    0.725    0.469    0.035    0.035
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{&quot;spm&quot;:&quot;1001.2101.3001.7365&quot;}"><img class="look-more-preCode contentImg-no-view" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png" alt="" title=""></span></div><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li><li style="color: rgb(153, 153, 153);">29</li><li style="color: rgb(153, 153, 153);">30</li><li style="color: rgb(153, 153, 153);">31</li><li style="color: rgb(153, 153, 153);">32</li><li style="color: rgb(153, 153, 153);">33</li><li style="color: rgb(153, 153, 153);">34</li><li style="color: rgb(153, 153, 153);">35</li><li style="color: rgb(153, 153, 153);">36</li><li style="color: rgb(153, 153, 153);">37</li><li style="color: rgb(153, 153, 153);">38</li><li style="color: rgb(153, 153, 153);">39</li><li style="color: rgb(153, 153, 153);">40</li><li style="color: rgb(153, 153, 153);">41</li><li style="color: rgb(153, 153, 153);">42</li><li style="color: rgb(153, 153, 153);">43</li><li style="color: rgb(153, 153, 153);">44</li><li style="color: rgb(153, 153, 153);">45</li><li style="color: rgb(153, 153, 153);">46</li><li style="color: rgb(153, 153, 153);">47</li><li style="color: rgb(153, 153, 153);">48</li><li style="color: rgb(153, 153, 153);">49</li><li style="color: rgb(153, 153, 153);">50</li><li style="color: rgb(153, 153, 153);">51</li><li style="color: rgb(153, 153, 153);">52</li><li style="color: rgb(153, 153, 153);">53</li><li style="color: rgb(153, 153, 153);">54</li><li style="color: rgb(153, 153, 153);">55</li><li style="color: rgb(153, 153, 153);">56</li><li style="color: rgb(153, 153, 153);">57</li><li style="color: rgb(153, 153, 153);">58</li><li style="color: rgb(153, 153, 153);">59</li><li style="color: rgb(153, 153, 153);">60</li><li style="color: rgb(153, 153, 153);">61</li><li style="color: rgb(153, 153, 153);">62</li><li style="color: rgb(153, 153, 153);">63</li><li style="color: rgb(153, 153, 153);">64</li><li style="color: rgb(153, 153, 153);">65</li><li style="color: rgb(153, 153, 153);">66</li><li style="color: rgb(153, 153, 153);">67</li><li style="color: rgb(153, 153, 153);">68</li><li style="color: rgb(153, 153, 153);">69</li><li style="color: rgb(153, 153, 153);">70</li><li style="color: rgb(153, 153, 153);">71</li><li style="color: rgb(153, 153, 153);">72</li><li style="color: rgb(153, 153, 153);">73</li><li style="color: rgb(153, 153, 153);">74</li><li style="color: rgb(153, 153, 153);">75</li><li style="color: rgb(153, 153, 153);">76</li></ul></pre> 
<h3><a name="t25"></a><a id="_1009"></a>绘制路径图</h3> 
<pre data-index="34" class="set-code-hide prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">dev.new()
pdf("./img/实例分析2.pdf")
#初始图
p = semPaths(fit6)
#含系数的图
p1=semPaths(object = fit6,whatLabels = "std", edge.label.cex = 1)
#不同形状的图
p2=semPaths(object = fit6,layout = "circle")
p3=semPaths(object = fit6,layout = "tree2")
p4=semPaths(object = fit6,layout = "circle2")
p5=semPaths(object = fit6,layout = "spring")
#旋转图
p6 = semPaths(fit6,rotation=2)
#线条颜色设置
p7 = semPaths(fit6,rotation=2,edge.color = "blue")
#变量颜色设置
p8 = semPaths(fit6,rotation=2,edge.color = "blue",color = "lightblue",whatLabels = "std", edge.label.cex = 1)
dev.off()


# dev.new()
# pdf("./img/实例分析2.pdf")
# #初始图
# title("Regression of MPG on Weight")
# p = semPaths(fit6,title=TRUE,"图1 实例分析2(初始tree)", title.color = "black")
# #含系数的图
# p1=semPaths(object = fit6,title="图2 实例分析2路径系数", title.color = "black",whatLabels = "std", edge.label.cex = 1)
# #不同形状的图
# p2=semPaths(object = fit6,title="图3 实例分析2(初始circle)", title.color = "black",layout = "circle")
# spring;tree2;circle2
# p3=semPaths(object = fit6,title="图4 实例分析2(初始tree2)", title.color = "black",layout = "tree2")
# p4=semPaths(object = fit6,title="图5 实例分析2(初始circle2)",title.color = "black",layout = "circle2")
# p5=semPaths(object = fit6,title="图6 实例分析2(初始spring)", title.color = "black",layout = "spring")
# #旋转图
# p6 = semPaths(fit6,title="图7 实例分析2(初始tree旋转)", title.color = "black",rotation=2)
# #线条颜色设置
# p7 = semPaths(fit6,title="图8 实例分析2(初始tree旋转蓝线条)", title.color = "black",rotation=2,edge.color = "blue")
# #变量颜色设置
# p8 = semPaths(fit6,title="图9 实例分析2(初始tree旋转蓝)", title.color = "black",rotation=2,edge.color = "blue",color = "blue")
# dev.off()
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{&quot;spm&quot;:&quot;1001.2101.3001.7365&quot;}"><img class="look-more-preCode contentImg-no-view" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png" alt="" title=""></span></div><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li><li style="color: rgb(153, 153, 153);">29</li><li style="color: rgb(153, 153, 153);">30</li><li style="color: rgb(153, 153, 153);">31</li><li style="color: rgb(153, 153, 153);">32</li><li style="color: rgb(153, 153, 153);">33</li><li style="color: rgb(153, 153, 153);">34</li><li style="color: rgb(153, 153, 153);">35</li><li style="color: rgb(153, 153, 153);">36</li><li style="color: rgb(153, 153, 153);">37</li><li style="color: rgb(153, 153, 153);">38</li><li style="color: rgb(153, 153, 153);">39</li><li style="color: rgb(153, 153, 153);">40</li></ul></pre> 
<p><strong>png:</strong> 2</p> 
<h2><a name="t26"></a><a id="6__1059"></a>6. 连续非正态数据和替代估计量</h2> 
<p>连续非正态数据:左偏、右偏、尖峰、厚尾等</p> 
<p>常见三种处理方法:</p> 
<ol><li>ADF(asymptotically distribution-free) estimation</li></ol> 
<p>2)ML(maximum likelihood)</p> 
<p>3)bootstrapping</p> 
<h3><a name="t27"></a><a id="1ADF_1072"></a>方法1:ADF</h3> 
<p>ADF估计量(Browne, 1984)无正态性假设,称为加权最小二乘(WLS)估计</p> 
<p>研究表明,只有样本量很大(例如,N &gt; 5000)时效果较好,否则ADF方法会失败</p> 
<pre data-index="35" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">fit5_6 &lt;- cfa(HSmodel_1, data = HolzingerSwineford1939,estimator = "WLS")
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li></ul></pre> 
<h3><a name="t28"></a><a id="2ML_1083"></a>方法2:ML</h3> 
<pre data-index="36" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;"># robust standard errors
fit5_71 &lt;- cfa(HSmodel_1, data = HolzingerSwineford1939,,se = "robust")
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li></ul></pre> 
<pre data-index="37" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">#Satorra-Bentler scaled test statistic
fit5_72 &lt;- cfa(HSmodel_1, data = HolzingerSwineford1939,test = "Satorra-Bentler")
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li></ul></pre> 
<pre data-index="38" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;"># Robust standard errors + scaled test statistic
fit5_73 &lt;- cfa(HSmodel_1, data = HolzingerSwineford1939,se = "robust", test = "Satorra-Bentler")
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li></ul></pre> 
<pre data-index="39" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;"># estimator MLM = robust standard errors + scaled test statistic
fit5_74 &lt;- cfa(HSmodel_1, data = HolzingerSwineford1939,estimator = "MLM")
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li></ul></pre> 
<pre data-index="40" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;"># alternative: estimator MLR (同时含缺失数据)
fit5_75 &lt;- cfa(HSmodel_1, data = HolzingerSwineford1939,estimator = "MLR", missing = "ml")
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li></ul></pre> 
<h3><a name="t29"></a><a id="3bootstrapping_1115"></a>方法3:bootstrapping</h3> 
<pre data-index="41" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;"># bootstrapping standard errors:(可输出置信区间)
fit5_81 &lt;- cfa(HSmodel_1, data = HolzingerSwineford1939,se = "bootstrap", verbose = TRUE, bootstrap = 1000)
# bootstrapping the test statistic
fit5_82 &lt;- cfa(HSmodel_1, data = HolzingerSwineford1939,test = "bootstrap", verbose = TRUE, bootstrap = 1000)
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li></ul></pre> 
<pre data-index="42" class="set-code-hide prettyprint"><code class="has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">Quasi-Newton steps using NLMINB:
Objective function  = 2.0640106626333683
Objective function  = 0.5481724334022804
Objective function  = 0.4744000434739597
Objective function  = 0.3116651572650557
Objective function  = 0.2935347771542274
Objective function  = 0.2091927643393836
Objective function  = 0.1986590305865628
Objective function  = 0.1549912702721032
Objective function  = 0.1519382593582579
Objective function  = 0.1472224332311631
。。。。。。。部分结果略。。。。。。
  ... bootstrap draw number:  999   OK -- niter =   26  fx =    0.158705135 
  ... bootstrap draw number: 1000   OK -- niter =   26  fx =    0.244148094 
Number of successful bootstrap draws: 1000 
 done.
Computing TEST for test(s) = standard ... done.
Fitting baseline model ...  done.
Quasi-Newton steps using NLMINB:
Objective function  = 2.0640106626333683
Objective function  = 0.5481724334022804
Objective function  = 0.4744000434739597
Objective function  = 0.3116651572650557
Objective function  = 0.2935347771542274
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><div class="hide-preCode-box"><span class="hide-preCode-bt" data-report-view="{&quot;spm&quot;:&quot;1001.2101.3001.7365&quot;}"><img class="look-more-preCode contentImg-no-view" src="https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png" alt="" title=""></span></div><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li></ul></pre> 
<p>。。。。。。。部分结果略。。。。。。<br> … bootstrap draw number: 999 OK – niter = 25 fx = 0.041584423<br> … bootstrap draw number: 1000 OK – niter = 27 fx = 0.045263513<br> Number of successful bootstrap draws: 1000<br> done.<br> Fitting baseline <a href="https://so.csdn.net/so/search?q=model&amp;spm=1001.2101.3001.7020" target="_blank" class="hl hl-1" data-report-view="{&quot;spm&quot;:&quot;1001.2101.3001.7020&quot;,&quot;dest&quot;:&quot;https://so.csdn.net/so/search?q=model&amp;spm=1001.2101.3001.7020&quot;,&quot;extra&quot;:&quot;{\&quot;searchword\&quot;:\&quot;model\&quot;}&quot;}" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.7020&quot;,&quot;dest&quot;:&quot;https://so.csdn.net/so/search?q=model&amp;spm=1001.2101.3001.7020&quot;,&quot;extra&quot;:&quot;{\&quot;searchword\&quot;:\&quot;model\&quot;}&quot;}" data-tit="model" data-pretit="model">model</a> … done.</p> 
<pre data-index="43" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;"># 使用bootstrapLavaan()计算Bolen-Stine p值(可配置)
fit5_83 &lt;- cfa(HSmodel_1, data=HolzingerSwineford1939, se="none")

T.orig &lt;- fitMeasures(fit5_83, "chisq")

T.boot &lt;- bootstrapLavaan(fit5_83,R = 10,type = "bollen.stine",FUN = fitMeasures,fit5_83.measures = "chisq")

pvalue.boot &lt;- length(which(T.boot &gt; T.orig))/length(T.boot)
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li></ul></pre> 
<h2><a name="t30"></a><a id="7__1169"></a>7. 分类内生变量</h2> 
<p>二分类数据、多分类数据、定序数据、计数数据、生存数据</p> 
<p>常见三种处理方法:</p> 
<p>WLSMV , logit/probit</p> 
<h3><a name="t31"></a><a id="1_1177"></a>方法1:阈值法连续化</h3> 
<p>观察到的变量y通常可以看作是对潜在的连续响应y*的部分观察。</p> 
<p>例如:K =4 的有序响应变量类别:<br> <img src="https://img-blog.csdnimg.cn/20201205202112319.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3MxMTY0NTQ4NTE1,size_16,color_FFFFFF,t_70#pic_center" alt="在这里插入图片描述"></p> 
<pre data-index="44" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;"># generate ‘ordered’ data with 4 categories
y_ord4 &lt;- sample(1:4, size = 100, replace = TRUE)
prop &lt;- table(Y)/sum(table(Y))
cprop &lt;- c(0, cumsum(prop))
th &lt;- qnorm(cprop)
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li></ul></pre> 
<h3><a name="t32"></a><a id="2_probit_1194"></a>方法2 :probit</h3> 
<p>存在外生协变量时,可直接利用probit回归</p> 
<p>– tetrachoric (binary – binary)</p> 
<p>– polychoric (ordered – ordered)</p> 
<p>– polyserial (ordered – numeric)</p> 
<p>– biserial (binary – numeric)</p> 
<p>– pearson (numeric – numeric)</p> 
<p>ordered=c(“item1”,“item2”,“item3”,“item4”)可将多个变量有序化</p> 
<pre data-index="45" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">library(MASS)
X1 &lt;- rnorm(100)
X2 &lt;- rnorm(100)
X3 &lt;- rnorm(100)
fit7_1 &lt;- polr(ordered(y_ord4) ˜ X1 + X2 + X3, method = "probit")
fit7_1$zeta
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li></ul></pre> 
<h3><a name="t33"></a><a id="1_1221"></a>示例:实例1数据</h3> 
<pre data-index="46" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">HS9 &lt;- HolzingerSwineford1939[,c("x1","x2","x3","x4","x5","x6","x7","x8","x9")]
HSbinary &lt;- as.data.frame( lapply(HS9, cut, 2, labels=FALSE) )
# binary CFA
fit7_2 &lt;- cfa(HSmodel_1, data=HSbinary, ordered=names(HSbinary))
summary(fit7_2,fit7_2.measures=TRUE)

<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li></ul></pre> 
<pre data-index="47" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">inspect(fit7_2, "sampstat")
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li></ul></pre> 
<h2><a name="t34"></a><a id="8__1238"></a>8. 提取函数应用示例</h2> 
<pre data-index="48" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">#见实例分析1
HSmodel_1 &lt;- 'visual  =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed  =~ x7 + x8 + x9
'
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li></ul></pre> 
<pre data-index="49" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">fit8 &lt;- cfa(HSmodel_1, data=HolzingerSwineford1939)
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li></ul></pre> 
<pre data-index="50" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">fitted(fit8)
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li></ul></pre> 
<p><strong>$cov</strong> =</p> 
<div class="table-box"><table><caption>
  A lavaan.matrix.symmetric: 9 × 9 of type dbl
 </caption><thead><tr><th></th><th>x1</th><th>x2</th><th>x3</th><th>x4</th><th>x5</th><th>x6</th><th>x7</th><th>x8</th><th>x9</th></tr></thead><tbody><tr><th>x1</th><td>1.3583700</td><td>0.4479566</td><td>0.5902910</td><td>0.4082324</td><td>0.4543940</td><td>0.3780829</td><td>0.2622246</td><td>0.3094121</td><td>0.2836038</td></tr><tr><th>x2</th><td>0.4479566</td><td>1.3817831</td><td>0.3267262</td><td>0.2259568</td><td>0.2515072</td><td>0.2092690</td><td>0.1451414</td><td>0.1712597</td><td>0.1569748</td></tr><tr><th>x3</th><td>0.5902910</td><td>0.3267262</td><td>1.2748647</td><td>0.2977526</td><td>0.3314214</td><td>0.2757624</td><td>0.1912588</td><td>0.2256760</td><td>0.2068522</td></tr><tr><th>x4</th><td>0.4082324</td><td>0.2259568</td><td>0.2977526</td><td>1.3506644</td><td>1.0902489</td><td>0.9071522</td><td>0.1734947</td><td>0.2047152</td><td>0.1876397</td></tr><tr><th>x5</th><td>0.4543940</td><td>0.2515072</td><td>0.3314214</td><td>1.0902489</td><td>1.6597856</td><td>1.0097299</td><td>0.1931129</td><td>0.2278637</td><td>0.2088574</td></tr><tr><th>x6</th><td>0.3780829</td><td>0.2092690</td><td>0.2757624</td><td>0.9071522</td><td>1.0097299</td><td>1.1963583</td><td>0.1606814</td><td>0.1895962</td><td>0.1737818</td></tr><tr><th>x7</th><td>0.2622246</td><td>0.1451414</td><td>0.1912588</td><td>0.1734947</td><td>0.1931129</td><td>0.1606814</td><td>1.1831393</td><td>0.4528034</td><td>0.4150347</td></tr><tr><th>x8</th><td>0.3094121</td><td>0.1712597</td><td>0.2256760</td><td>0.2047152</td><td>0.2278637</td><td>0.1895962</td><td>0.4528034</td><td>1.0219828</td><td>0.4897205</td></tr><tr><th>x9</th><td>0.2836038</td><td>0.1569748</td><td>0.2068522</td><td>0.1876397</td><td>0.2088574</td><td>0.1737818</td><td>0.4150347</td><td>0.4897205</td><td>1.0150038</td></tr></tbody></table></div> 
<pre data-index="51" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">predict(fit8)
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li></ul></pre> 
<div class="table-box"><table><caption>
  A lavaan.matrix: 301 × 3 of type dbl
 </caption><thead><tr><th>visual</th><th>textual</th><th>speed</th></tr></thead><tbody><tr><td>-0.81767524</td><td>-0.13754501</td><td> 0.06150726</td></tr><tr><td> 0.04951940</td><td>-1.01272402</td><td> 0.62549360</td></tr><tr><td>-0.76139670</td><td>-1.87228634</td><td>-0.84057276</td></tr><tr><td> 0.41934153</td><td> 0.01848569</td><td>-0.27133710</td></tr><tr><td>-0.41590481</td><td>-0.12225009</td><td> 0.19432951</td></tr><tr><td> 0.02325632</td><td>-1.32981727</td><td> 0.70885348</td></tr><tr><td>-0.98496789</td><td> 0.65761381</td><td> 0.04370647</td></tr><tr><td> 0.10684376</td><td>-0.10512788</td><td>-0.53230194</td></tr><tr><td>-0.25397131</td><td> 0.40433106</td><td> 0.20036715</td></tr><tr><td>-1.05421886</td><td> 0.09291512</td><td>-0.56666789</td></tr><tr><td>-0.75848238</td><td>-0.76939476</td><td>-0.32272938</td></tr><tr><td> 0.39808636</td><td> 0.09621166</td><td>-0.36351841</td></tr><tr><td> 0.51898256</td><td>-0.14038719</td><td> 0.28709094</td></tr><tr><td> 0.24108494</td><td> 0.21574804</td><td>-0.24259754</td></tr><tr><td> 0.70257424</td><td> 1.15797443</td><td>-0.12973764</td></tr><tr><td>-0.42473596</td><td>-0.59549971</td><td>-0.55369318</td></tr><tr><td>-0.58761600</td><td>-0.69464666</td><td> 0.12080778</td></tr><tr><td>-0.05083838</td><td>-0.95018913</td><td>-0.10375995</td></tr><tr><td> 0.66490790</td><td> 1.09597201</td><td>-0.04174159</td></tr><tr><td> 0.97772373</td><td> 0.18795244</td><td>-0.12304567</td></tr><tr><td> 0.23952816</td><td>-1.35930395</td><td>-0.43925580</td></tr><tr><td> 1.33320492</td><td>-0.52348581</td><td> 0.47433613</td></tr><tr><td>-0.01872902</td><td> 0.72510961</td><td>-0.39098728</td></tr><tr><td>-0.65236812</td><td>-0.85126858</td><td> 0.35389317</td></tr><tr><td>-0.14193523</td><td>-0.64671143</td><td>-0.44254826</td></tr><tr><td> 0.07459743</td><td>-0.84369449</td><td> 0.17047103</td></tr><tr><td> 0.35906264</td><td>-1.08215625</td><td>-0.26763982</td></tr><tr><td> 0.06073595</td><td>-1.07208831</td><td>-0.37789768</td></tr><tr><td> 0.36284640</td><td>-0.68722561</td><td> 0.87878736</td></tr><tr><td>-0.53281609</td><td>-0.54291209</td><td>-0.16260680</td></tr><tr><td>...</td><td>...</td><td>...</td></tr><tr><td> 0.36579463</td><td> 0.286998384</td><td> 0.16020380</td></tr><tr><td>-0.11301304</td><td>-0.008594389</td><td> 0.78275251</td></tr><tr><td>-0.31322664</td><td>-0.117325314</td><td> 0.02863657</td></tr><tr><td> 0.43165862</td><td>-0.552461192</td><td> 0.39482293</td></tr><tr><td>-1.05019439</td><td>-0.817906236</td><td>-0.76617073</td></tr><tr><td>-0.17358766</td><td> 0.021497247</td><td>-0.40875089</td></tr><tr><td>-0.05252645</td><td> 0.367863096</td><td>-0.17593087</td></tr><tr><td> 0.15839234</td><td>-0.792699519</td><td> 0.50487360</td></tr><tr><td> 0.57832663</td><td>-0.121716586</td><td> 0.30412862</td></tr><tr><td>-0.88456464</td><td>-0.452929413</td><td> 0.11865986</td></tr><tr><td> 0.30021737</td><td> 1.335667006</td><td>-0.78516652</td></tr><tr><td>-0.61851705</td><td>-0.260155389</td><td>-0.71446297</td></tr><tr><td> 0.72163334</td><td> 0.713018089</td><td>-0.32928632</td></tr><tr><td>-0.14855811</td><td>-0.477111209</td><td> 0.51598547</td></tr><tr><td> 0.14577715</td><td>-0.219169373</td><td>-0.08770218</td></tr><tr><td> 0.56806351</td><td> 1.606779375</td><td> 0.09576261</td></tr><tr><td>-0.46039523</td><td>-0.501810492</td><td> 0.41742089</td></tr><tr><td>-0.49595506</td><td> 0.380804720</td><td> 0.41931919</td></tr><tr><td> 0.39787129</td><td>-0.001286655</td><td>-0.20616710</td></tr><tr><td>-1.00453500</td><td>-0.370879351</td><td> 0.37667244</td></tr><tr><td>-0.49694338</td><td>-1.079965387</td><td>-0.12580818</td></tr><tr><td> 0.14006996</td><td> 0.014458282</td><td> 0.12929032</td></tr><tr><td> 0.24014891</td><td> 0.086748659</td><td> 0.01910399</td></tr><tr><td> 0.18492002</td><td>-0.477628434</td><td>-0.08199923</td></tr><tr><td> 0.62226627</td><td> 0.181525443</td><td>-0.34620461</td></tr><tr><td>-0.49495815</td><td>-0.507343016</td><td> 0.05023989</td></tr><tr><td>-0.93999794</td><td>-0.698817917</td><td> 0.21812239</td></tr><tr><td> 0.03677903</td><td> 1.169004482</td><td> 0.56918416</td></tr><tr><td>-0.47087734</td><td> 0.138702247</td><td> 0.04466651</td></tr><tr><td> 0.14776003</td><td> 0.848046807</td><td> 0.33771119</td></tr></tbody></table></div> 
<pre data-index="52" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">inspect(fit8)  # matrix representation
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li></ul></pre> 
<dl> 
 
  $lambda
  
 <dd>
  <div class="table-box"><table><caption>
    A lavaan.matrix: 9 × 3 of type dbl
   </caption><thead><tr><th></th><th>visual</th><th>textual</th><th>speed</th></tr></thead><tbody><tr><th>x1</th><td>0</td><td>0</td><td>0</td></tr><tr><th>x2</th><td>1</td><td>0</td><td>0</td></tr><tr><th>x3</th><td>2</td><td>0</td><td>0</td></tr><tr><th>x4</th><td>0</td><td>0</td><td>0</td></tr><tr><th>x5</th><td>0</td><td>3</td><td>0</td></tr><tr><th>x6</th><td>0</td><td>4</td><td>0</td></tr><tr><th>x7</th><td>0</td><td>0</td><td>0</td></tr><tr><th>x8</th><td>0</td><td>0</td><td>5</td></tr><tr><th>x9</th><td>0</td><td>0</td><td>6</td></tr></tbody></table></div> 
 </dd> 
 
  $theta
  
 <dd>
  <div class="table-box"><table><caption>
    A lavaan.matrix.symmetric: 9 × 9 of type dbl
   </caption><thead><tr><th></th><th>x1</th><th>x2</th><th>x3</th><th>x4</th><th>x5</th><th>x6</th><th>x7</th><th>x8</th><th>x9</th></tr></thead><tbody><tr><th>x1</th><td>7</td><td>0</td><td>0</td><td> 0</td><td> 0</td><td> 0</td><td> 0</td><td> 0</td><td> 0</td></tr><tr><th>x2</th><td>0</td><td>8</td><td>0</td><td> 0</td><td> 0</td><td> 0</td><td> 0</td><td> 0</td><td> 0</td></tr><tr><th>x3</th><td>0</td><td>0</td><td>9</td><td> 0</td><td> 0</td><td> 0</td><td> 0</td><td> 0</td><td> 0</td></tr><tr><th>x4</th><td>0</td><td>0</td><td>0</td><td>10</td><td> 0</td><td> 0</td><td> 0</td><td> 0</td><td> 0</td></tr><tr><th>x5</th><td>0</td><td>0</td><td>0</td><td> 0</td><td>11</td><td> 0</td><td> 0</td><td> 0</td><td> 0</td></tr><tr><th>x6</th><td>0</td><td>0</td><td>0</td><td> 0</td><td> 0</td><td>12</td><td> 0</td><td> 0</td><td> 0</td></tr><tr><th>x7</th><td>0</td><td>0</td><td>0</td><td> 0</td><td> 0</td><td> 0</td><td>13</td><td> 0</td><td> 0</td></tr><tr><th>x8</th><td>0</td><td>0</td><td>0</td><td> 0</td><td> 0</td><td> 0</td><td> 0</td><td>14</td><td> 0</td></tr><tr><th>x9</th><td>0</td><td>0</td><td>0</td><td> 0</td><td> 0</td><td> 0</td><td> 0</td><td> 0</td><td>15</td></tr></tbody></table></div> 
 </dd> 
 
  $psi
  
 <dd>
  <div class="table-box"><table><caption>
    A lavaan.matrix.symmetric: 3 × 3 of type dbl
   </caption><thead><tr><th></th><th>visual</th><th>textual</th><th>speed</th></tr></thead><tbody><tr><th>visual</th><td>16</td><td>19</td><td>20</td></tr><tr><th>textual</th><td>19</td><td>17</td><td>21</td></tr><tr><th>speed</th><td>20</td><td>21</td><td>18</td></tr></tbody></table></div> 
 </dd> 
</dl> 
<pre data-index="53" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">inspect(fit8, "sampstat")
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li></ul></pre> 
<p><strong>$cov</strong> =</p> 
<div class="table-box"><table><caption>
  A lavaan.matrix.symmetric: 9 × 9 of type dbl
 </caption><thead><tr><th></th><th>x1</th><th>x2</th><th>x3</th><th>x4</th><th>x5</th><th>x6</th><th>x7</th><th>x8</th><th>x9</th></tr></thead><tbody><tr><th>x1</th><td>1.35836985</td><td> 0.40737133</td><td>0.57989932</td><td>0.5048350</td><td>0.4406155</td><td>0.4548081</td><td> 0.08476543</td><td>0.2638377</td><td>0.4583385</td></tr><tr><th>x2</th><td>0.40737133</td><td> 1.38178387</td><td>0.45106394</td><td>0.2089234</td><td>0.2110911</td><td>0.2475446</td><td>-0.09675102</td><td>0.1096594</td><td>0.2440095</td></tr><tr><th>x3</th><td>0.57989932</td><td> 0.45106394</td><td>1.27486486</td><td>0.2081696</td><td>0.1122963</td><td>0.2441090</td><td> 0.08834184</td><td>0.2123226</td><td>0.3738526</td></tr><tr><th>x4</th><td>0.50483500</td><td> 0.20892337</td><td>0.20816961</td><td>1.3506645</td><td>1.0977528</td><td>0.8955157</td><td> 0.21974259</td><td>0.1255933</td><td>0.2433627</td></tr><tr><th>x5</th><td>0.44061554</td><td> 0.21109108</td><td>0.11229629</td><td>1.0977528</td><td>1.6597858</td><td>1.0145240</td><td> 0.14299955</td><td>0.1806052</td><td>0.2952413</td></tr><tr><th>x6</th><td>0.45480813</td><td> 0.24754457</td><td>0.24410898</td><td>0.8955157</td><td>1.0145240</td><td>1.1963584</td><td> 0.14407839</td><td>0.1654310</td><td>0.2359969</td></tr><tr><th>x7</th><td>0.08476543</td><td>-0.09675102</td><td>0.08834184</td><td>0.2197426</td><td>0.1429995</td><td>0.1440784</td><td> 1.18313946</td><td>0.5352452</td><td>0.3732972</td></tr><tr><th>x8</th><td>0.26383768</td><td> 0.10965939</td><td>0.21232264</td><td>0.1255933</td><td>0.1806052</td><td>0.1654310</td><td> 0.53524522</td><td>1.0219828</td><td>0.4573166</td></tr><tr><th>x9</th><td>0.45833855</td><td> 0.24400945</td><td>0.37385257</td><td>0.2433627</td><td>0.2952413</td><td>0.2359969</td><td> 0.37329722</td><td>0.4573166</td><td>1.0150039</td></tr></tbody></table></div> 
<pre data-index="54" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">fitMeasures(fit8)
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li></ul></pre> 
<dl class="dl-horizontal"> 
 
  npar
  
 <dd>
  21
 </dd> 
 
  fmin
  
 <dd>
  0.141703524534838
 </dd> 
 
  chisq
  
 <dd>
  85.3055217699727
 </dd> 
 
  df
  
 <dd>
  24
 </dd> 
 
  pvalue
  
 <dd>
  8.50255321704907e-09
 </dd> 
 
  baseline.chisq
  
 <dd>
  918.851589292384
 </dd> 
 
  baseline.df
  
 <dd>
  36
 </dd> 
 
  baseline.pvalue
  
 <dd>
  0
 </dd> 
 
  cfi
  
 <dd>
  0.930559651799336
 </dd> 
 
  tli
  
 <dd>
  0.895839477699004
 </dd> 
 
  nnfi
  
 <dd>
  0.895839477699004
 </dd> 
 
  rfi
  
 <dd>
  0.86074107707263
 </dd> 
 
  nfi
  
 <dd>
  0.90716071804842
 </dd> 
 
  pnfi
  
 <dd>
  0.60477381203228
 </dd> 
 
  ifi
  
 <dd>
  0.931490849987258
 </dd> 
 
  rni
  
 <dd>
  0.930559651799336
 </dd> 
 
  logl
  
 <dd>
  -3737.7449266262
 </dd> 
 
  unrestricted.logl
  
 <dd>
  -3695.09216574121
 </dd> 
 
  aic
  
 <dd>
  7517.48985325239
 </dd> 
 
  bic
  
 <dd>
  7595.33916881212
 </dd> 
 
  ntotal
  
 <dd>
  301
 </dd> 
 
  bic2
  
 <dd>
  7528.73911173078
 </dd> 
 
  rmsea
  
 <dd>
  0.0921214845101686
 </dd> 
 
  rmsea.ci.lower
  
 <dd>
  0.0714184904399382
 </dd> 
 
  rmsea.ci.upper
  
 <dd>
  0.113678016811963
 </dd> 
 
  rmsea.pvalue
  
 <dd>
  0.000661236778051855
 </dd> 
 
  rmr
  
 <dd>
  0.0821843333342268
 </dd> 
 
  rmr_nomean
  
 <dd>
  0.0821843333342268
 </dd> 
 
  srmr
  
 <dd>
  0.0652050571843865
 </dd> 
 
  srmr_bentler
  
 <dd>
  0.0652050571843865
 </dd> 
 
  srmr_bentler_nomean
  
 <dd>
  0.0652050571843865
 </dd> 
 
  crmr
  
 <dd>
  0.0729014727869723
 </dd> 
 
  crmr_nomean
  
 <dd>
  0.0729014727869723
 </dd> 
 
  srmr_mplus
  
 <dd>
  0.0652050595246683
 </dd> 
 
  srmr_mplus_nomean
  
 <dd>
  0.0652050595246683
 </dd> 
 
  cn_05
  
 <dd>
  129.490200301456
 </dd> 
 
  cn_01
  
 <dd>
  152.654026533352
 </dd> 
 
  gfi
  
 <dd>
  0.943332061258476
 </dd> 
 
  agfi
  
 <dd>
  0.893747614859642
 </dd> 
 
  pgfi
  
 <dd>
  0.503110432671187
 </dd> 
 
  mfi
  
 <dd>
  0.903177285931363
 </dd> 
 
  ecvi
  
 <dd>
  0.422941932790607
 </dd> 
</dl> 
<pre data-index="55" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">parameterTable(fit8)
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li></ul></pre> 
<div class="table-box"><table><caption>
  A lavaan.data.frame: 24 × 15
 </caption><thead><tr><th>id</th><th>lhs</th><th>op</th><th>rhs</th><th>user</th><th>block</th><th>group</th><th>free</th><th>ustart</th><th>exo</th><th>label</th><th>plabel</th><th>start</th><th>est</th><th>se</th></tr><tr><th>&lt;int&gt;</th><th>&lt;chr&gt;</th><th>&lt;chr&gt;</th><th>&lt;chr&gt;</th><th>&lt;int&gt;</th><th>&lt;int&gt;</th><th>&lt;int&gt;</th><th>&lt;int&gt;</th><th>&lt;dbl&gt;</th><th>&lt;int&gt;</th><th>&lt;chr&gt;</th><th>&lt;chr&gt;</th><th>&lt;dbl&gt;</th><th>&lt;dbl&gt;</th><th>&lt;dbl&gt;</th></tr></thead><tbody><tr><td> 1</td><td>visual </td><td>=~</td><td>x1 </td><td>1</td><td>1</td><td>1</td><td> 0</td><td> 1</td><td>0</td><td></td><td>.p1. </td><td>1.0000000</td><td>1.0000000</td><td>0.00000000</td></tr><tr><td> 2</td><td>visual </td><td>=~</td><td>x2 </td><td>1</td><td>1</td><td>1</td><td> 1</td><td>NA</td><td>0</td><td></td><td>.p2. </td><td>0.7778315</td><td>0.5535003</td><td>0.09966512</td></tr><tr><td> 3</td><td>visual </td><td>=~</td><td>x3 </td><td>1</td><td>1</td><td>1</td><td> 2</td><td>NA</td><td>0</td><td></td><td>.p3. </td><td>1.1072550</td><td>0.7293702</td><td>0.10910970</td></tr><tr><td> 4</td><td>textual</td><td>=~</td><td>x4 </td><td>1</td><td>1</td><td>1</td><td> 0</td><td> 1</td><td>0</td><td></td><td>.p4. </td><td>1.0000000</td><td>1.0000000</td><td>0.00000000</td></tr><tr><td> 5</td><td>textual</td><td>=~</td><td>x5 </td><td>1</td><td>1</td><td>1</td><td> 3</td><td>NA</td><td>0</td><td></td><td>.p5. </td><td>1.1328936</td><td>1.1130766</td><td>0.06542011</td></tr><tr><td> 6</td><td>textual</td><td>=~</td><td>x6 </td><td>1</td><td>1</td><td>1</td><td> 4</td><td>NA</td><td>0</td><td></td><td>.p6. </td><td>0.9241826</td><td>0.9261462</td><td>0.05544886</td></tr><tr><td> 7</td><td>speed </td><td>=~</td><td>x7 </td><td>1</td><td>1</td><td>1</td><td> 0</td><td> 1</td><td>0</td><td></td><td>.p7. </td><td>1.0000000</td><td>1.0000000</td><td>0.00000000</td></tr><tr><td> 8</td><td>speed </td><td>=~</td><td>x8 </td><td>1</td><td>1</td><td>1</td><td> 5</td><td>NA</td><td>0</td><td></td><td>.p8. </td><td>1.2250736</td><td>1.1799508</td><td>0.16498657</td></tr><tr><td> 9</td><td>speed </td><td>=~</td><td>x9 </td><td>1</td><td>1</td><td>1</td><td> 6</td><td>NA</td><td>0</td><td></td><td>.p9. </td><td>0.8544057</td><td>1.0815302</td><td>0.15116744</td></tr><tr><td>10</td><td>x1 </td><td>~~</td><td>x1 </td><td>0</td><td>1</td><td>1</td><td> 7</td><td>NA</td><td>0</td><td></td><td>.p10.</td><td>0.6791849</td><td>0.5490540</td><td>0.11360092</td></tr><tr><td>11</td><td>x2 </td><td>~~</td><td>x2 </td><td>0</td><td>1</td><td>1</td><td> 8</td><td>NA</td><td>0</td><td></td><td>.p11.</td><td>0.6908919</td><td>1.1338390</td><td>0.10172337</td></tr><tr><td>12</td><td>x3 </td><td>~~</td><td>x3 </td><td>0</td><td>1</td><td>1</td><td> 9</td><td>NA</td><td>0</td><td></td><td>.p12.</td><td>0.6374324</td><td>0.8443240</td><td>0.09062318</td></tr><tr><td>13</td><td>x4 </td><td>~~</td><td>x4 </td><td>0</td><td>1</td><td>1</td><td>10</td><td>NA</td><td>0</td><td></td><td>.p13.</td><td>0.6753323</td><td>0.3711730</td><td>0.04771779</td></tr><tr><td>14</td><td>x5 </td><td>~~</td><td>x5 </td><td>0</td><td>1</td><td>1</td><td>11</td><td>NA</td><td>0</td><td></td><td>.p14.</td><td>0.8298929</td><td>0.4462551</td><td>0.05839278</td></tr><tr><td>15</td><td>x6 </td><td>~~</td><td>x6 </td><td>0</td><td>1</td><td>1</td><td>12</td><td>NA</td><td>0</td><td></td><td>.p15.</td><td>0.5981792</td><td>0.3562027</td><td>0.04303497</td></tr><tr><td>16</td><td>x7 </td><td>~~</td><td>x7 </td><td>0</td><td>1</td><td>1</td><td>13</td><td>NA</td><td>0</td><td></td><td>.p16.</td><td>0.5915697</td><td>0.7993916</td><td>0.08138156</td></tr><tr><td>17</td><td>x8 </td><td>~~</td><td>x8 </td><td>0</td><td>1</td><td>1</td><td>14</td><td>NA</td><td>0</td><td></td><td>.p17.</td><td>0.5109914</td><td>0.4876971</td><td>0.07419409</td></tr><tr><td>18</td><td>x9 </td><td>~~</td><td>x9 </td><td>0</td><td>1</td><td>1</td><td>15</td><td>NA</td><td>0</td><td></td><td>.p18.</td><td>0.5075019</td><td>0.5661313</td><td>0.07073694</td></tr><tr><td>19</td><td>visual </td><td>~~</td><td>visual </td><td>0</td><td>1</td><td>1</td><td>16</td><td>NA</td><td>0</td><td></td><td>.p19.</td><td>0.0500000</td><td>0.8093160</td><td>0.14546241</td></tr><tr><td>20</td><td>textual</td><td>~~</td><td>textual</td><td>0</td><td>1</td><td>1</td><td>17</td><td>NA</td><td>0</td><td></td><td>.p20.</td><td>0.0500000</td><td>0.9794914</td><td>0.11210585</td></tr><tr><td>21</td><td>speed </td><td>~~</td><td>speed </td><td>0</td><td>1</td><td>1</td><td>18</td><td>NA</td><td>0</td><td></td><td>.p21.</td><td>0.0500000</td><td>0.3837476</td><td>0.08620919</td></tr><tr><td>22</td><td>visual </td><td>~~</td><td>textual</td><td>0</td><td>1</td><td>1</td><td>19</td><td>NA</td><td>0</td><td></td><td>.p22.</td><td>0.0000000</td><td>0.4082324</td><td>0.07352388</td></tr><tr><td>23</td><td>visual </td><td>~~</td><td>speed </td><td>0</td><td>1</td><td>1</td><td>20</td><td>NA</td><td>0</td><td></td><td>.p23.</td><td>0.0000000</td><td>0.2622246</td><td>0.05627640</td></tr><tr><td>24</td><td>textual</td><td>~~</td><td>speed </td><td>0</td><td>1</td><td>1</td><td>21</td><td>NA</td><td>0</td><td></td><td>.p24.</td><td>0.0000000</td><td>0.1734947</td><td>0.04931466</td></tr></tbody></table></div> 
<pre data-index="56" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">parameterEstimates(fit8)
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li></ul></pre> 
<div class="table-box"><table><caption>
  A lavaan.data.frame: 24 × 9
 </caption><thead><tr><th>lhs</th><th>op</th><th>rhs</th><th>est</th><th>se</th><th>z</th><th>pvalue</th><th>ci.lower</th><th>ci.upper</th></tr><tr><th>&lt;chr&gt;</th><th>&lt;chr&gt;</th><th>&lt;chr&gt;</th><th>&lt;dbl&gt;</th><th>&lt;dbl&gt;</th><th>&lt;dbl&gt;</th><th>&lt;dbl&gt;</th><th>&lt;dbl&gt;</th><th>&lt;dbl&gt;</th></tr></thead><tbody><tr><td>visual </td><td>=~</td><td>x1 </td><td>1.0000000</td><td>0.00000000</td><td> NA</td><td> NA</td><td>1.00000000</td><td>1.0000000</td></tr><tr><td>visual </td><td>=~</td><td>x2 </td><td>0.5535003</td><td>0.09966512</td><td> 5.553601</td><td>2.798440e-08</td><td>0.35816025</td><td>0.7488403</td></tr><tr><td>visual </td><td>=~</td><td>x3 </td><td>0.7293702</td><td>0.10910970</td><td> 6.684742</td><td>2.313327e-11</td><td>0.51551912</td><td>0.9432213</td></tr><tr><td>textual</td><td>=~</td><td>x4 </td><td>1.0000000</td><td>0.00000000</td><td> NA</td><td> NA</td><td>1.00000000</td><td>1.0000000</td></tr><tr><td>textual</td><td>=~</td><td>x5 </td><td>1.1130766</td><td>0.06542011</td><td>17.014288</td><td>0.000000e+00</td><td>0.98485552</td><td>1.2412976</td></tr><tr><td>textual</td><td>=~</td><td>x6 </td><td>0.9261462</td><td>0.05544886</td><td>16.702711</td><td>0.000000e+00</td><td>0.81746848</td><td>1.0348240</td></tr><tr><td>speed </td><td>=~</td><td>x7 </td><td>1.0000000</td><td>0.00000000</td><td> NA</td><td> NA</td><td>1.00000000</td><td>1.0000000</td></tr><tr><td>speed </td><td>=~</td><td>x8 </td><td>1.1799508</td><td>0.16498657</td><td> 7.151799</td><td>8.564260e-13</td><td>0.85658310</td><td>1.5033186</td></tr><tr><td>speed </td><td>=~</td><td>x9 </td><td>1.0815302</td><td>0.15116744</td><td> 7.154518</td><td>8.397727e-13</td><td>0.78524742</td><td>1.3778129</td></tr><tr><td>x1 </td><td>~~</td><td>x1 </td><td>0.5490540</td><td>0.11360092</td><td> 4.833182</td><td>1.343676e-06</td><td>0.32640025</td><td>0.7717077</td></tr><tr><td>x2 </td><td>~~</td><td>x2 </td><td>1.1338390</td><td>0.10172337</td><td>11.146298</td><td>0.000000e+00</td><td>0.93446487</td><td>1.3332132</td></tr><tr><td>x3 </td><td>~~</td><td>x3 </td><td>0.8443240</td><td>0.09062318</td><td> 9.316866</td><td>0.000000e+00</td><td>0.66670587</td><td>1.0219422</td></tr><tr><td>x4 </td><td>~~</td><td>x4 </td><td>0.3711730</td><td>0.04771779</td><td> 7.778503</td><td>7.327472e-15</td><td>0.27764784</td><td>0.4646981</td></tr><tr><td>x5 </td><td>~~</td><td>x5 </td><td>0.4462551</td><td>0.05839278</td><td> 7.642299</td><td>2.131628e-14</td><td>0.33180733</td><td>0.5607028</td></tr><tr><td>x6 </td><td>~~</td><td>x6 </td><td>0.3562027</td><td>0.04303497</td><td> 8.277052</td><td>2.220446e-16</td><td>0.27185568</td><td>0.4405497</td></tr><tr><td>x7 </td><td>~~</td><td>x7 </td><td>0.7993916</td><td>0.08138156</td><td> 9.822761</td><td>0.000000e+00</td><td>0.63988671</td><td>0.9588966</td></tr><tr><td>x8 </td><td>~~</td><td>x8 </td><td>0.4876971</td><td>0.07419409</td><td> 6.573260</td><td>4.922529e-11</td><td>0.34227934</td><td>0.6331148</td></tr><tr><td>x9 </td><td>~~</td><td>x9 </td><td>0.5661313</td><td>0.07073694</td><td> 8.003333</td><td>1.110223e-15</td><td>0.42748944</td><td>0.7047731</td></tr><tr><td>visual </td><td>~~</td><td>visual </td><td>0.8093160</td><td>0.14546241</td><td> 5.563747</td><td>2.640432e-08</td><td>0.52421490</td><td>1.0944171</td></tr><tr><td>textual</td><td>~~</td><td>textual</td><td>0.9794914</td><td>0.11210585</td><td> 8.737201</td><td>0.000000e+00</td><td>0.75976795</td><td>1.1992148</td></tr><tr><td>speed </td><td>~~</td><td>speed </td><td>0.3837476</td><td>0.08620919</td><td> 4.451354</td><td>8.533051e-06</td><td>0.21478073</td><td>0.5527146</td></tr><tr><td>visual </td><td>~~</td><td>textual</td><td>0.4082324</td><td>0.07352388</td><td> 5.552379</td><td>2.818082e-08</td><td>0.26412828</td><td>0.5523366</td></tr><tr><td>visual </td><td>~~</td><td>speed </td><td>0.2622246</td><td>0.05627640</td><td> 4.659584</td><td>3.168493e-06</td><td>0.15192489</td><td>0.3725243</td></tr><tr><td>textual</td><td>~~</td><td>speed </td><td>0.1734947</td><td>0.04931466</td><td> 3.518116</td><td>4.346227e-04</td><td>0.07683973</td><td>0.2701496</td></tr></tbody></table></div> 
<pre data-index="57" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">varTable(fit8)
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li></ul></pre> 
<div class="table-box"><table><caption>
  A lavaan.data.frame: 9 × 10
 </caption><thead><tr><th>name</th><th>idx</th><th>nobs</th><th>type</th><th>exo</th><th>user</th><th>mean</th><th>var</th><th>nlev</th><th>lnam</th></tr><tr><th>&lt;chr&gt;</th><th>&lt;int&gt;</th><th>&lt;int&gt;</th><th>&lt;chr&gt;</th><th>&lt;int&gt;</th><th>&lt;int&gt;</th><th>&lt;dbl&gt;</th><th>&lt;dbl&gt;</th><th>&lt;int&gt;</th><th>&lt;chr&gt;</th></tr></thead><tbody><tr><td>x1</td><td> 7</td><td>301</td><td>numeric</td><td>0</td><td>0</td><td>4.935770</td><td>1.362898</td><td>0</td><td></td></tr><tr><td>x2</td><td> 8</td><td>301</td><td>numeric</td><td>0</td><td>0</td><td>6.088040</td><td>1.386390</td><td>0</td><td></td></tr><tr><td>x3</td><td> 9</td><td>301</td><td>numeric</td><td>0</td><td>0</td><td>2.250415</td><td>1.279114</td><td>0</td><td></td></tr><tr><td>x4</td><td>10</td><td>301</td><td>numeric</td><td>0</td><td>0</td><td>3.060908</td><td>1.355167</td><td>0</td><td></td></tr><tr><td>x5</td><td>11</td><td>301</td><td>numeric</td><td>0</td><td>0</td><td>4.340532</td><td>1.665318</td><td>0</td><td></td></tr><tr><td>x6</td><td>12</td><td>301</td><td>numeric</td><td>0</td><td>0</td><td>2.185572</td><td>1.200346</td><td>0</td><td></td></tr><tr><td>x7</td><td>13</td><td>301</td><td>numeric</td><td>0</td><td>0</td><td>4.185902</td><td>1.187083</td><td>0</td><td></td></tr><tr><td>x8</td><td>14</td><td>301</td><td>numeric</td><td>0</td><td>0</td><td>5.527076</td><td>1.025389</td><td>0</td><td></td></tr><tr><td>x9</td><td>15</td><td>301</td><td>numeric</td><td>0</td><td>0</td><td>5.374123</td><td>1.018387</td><td>0</td><td></td></tr></tbody></table></div> 
<pre data-index="58" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">subset(modindices(fit8), mi &gt; 5)
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li></ul></pre> 
<div class="table-box"><table><caption>
  A lavaan.data.frame: 15 × 8
 </caption><thead><tr><th></th><th>lhs</th><th>op</th><th>rhs</th><th>mi</th><th>epc</th><th>sepc.lv</th><th>sepc.all</th><th>sepc.nox</th></tr><tr><th></th><th>&lt;chr&gt;</th><th>&lt;chr&gt;</th><th>&lt;chr&gt;</th><th>&lt;dbl&gt;</th><th>&lt;dbl&gt;</th><th>&lt;dbl&gt;</th><th>&lt;dbl&gt;</th><th>&lt;dbl&gt;</th></tr></thead><tbody><tr><th>26</th><td>visual </td><td>=~</td><td>x5</td><td> 7.440646</td><td>-0.20989801</td><td>-0.18882843</td><td>-0.1465688</td><td>-0.1465688</td></tr><tr><th>28</th><td>visual </td><td>=~</td><td>x7</td><td>18.630638</td><td>-0.42186239</td><td>-0.37951580</td><td>-0.3489088</td><td>-0.3489088</td></tr><tr><th>30</th><td>visual </td><td>=~</td><td>x9</td><td>36.411031</td><td> 0.57702154</td><td> 0.51910006</td><td> 0.5152491</td><td> 0.5152491</td></tr><tr><th>31</th><td>textual</td><td>=~</td><td>x1</td><td> 8.902732</td><td> 0.35033114</td><td> 0.34672012</td><td> 0.2974884</td><td> 0.2974884</td></tr><tr><th>33</th><td>textual</td><td>=~</td><td>x3</td><td> 9.150895</td><td>-0.27163761</td><td>-0.26883773</td><td>-0.2380993</td><td>-0.2380993</td></tr><tr><th>48</th><td>x1 </td><td>~~</td><td>x7</td><td> 5.419590</td><td>-0.12911266</td><td>-0.12911266</td><td>-0.1948864</td><td>-0.1948864</td></tr><tr><th>50</th><td>x1 </td><td>~~</td><td>x9</td><td> 7.334930</td><td> 0.13789383</td><td> 0.13789383</td><td> 0.2473311</td><td> 0.2473311</td></tr><tr><th>51</th><td>x2 </td><td>~~</td><td>x3</td><td> 8.531827</td><td> 0.21823928</td><td> 0.21823928</td><td> 0.2230502</td><td> 0.2230502</td></tr><tr><th>55</th><td>x2 </td><td>~~</td><td>x7</td><td> 8.918022</td><td>-0.18272538</td><td>-0.18272538</td><td>-0.1919302</td><td>-0.1919302</td></tr><tr><th>59</th><td>x3 </td><td>~~</td><td>x5</td><td> 7.858085</td><td>-0.13009466</td><td>-0.13009466</td><td>-0.2119402</td><td>-0.2119402</td></tr><tr><th>65</th><td>x4 </td><td>~~</td><td>x6</td><td> 6.220497</td><td>-0.23480293</td><td>-0.23480293</td><td>-0.6457535</td><td>-0.6457535</td></tr><tr><th>66</th><td>x4 </td><td>~~</td><td>x7</td><td> 5.919707</td><td> 0.09818085</td><td> 0.09818085</td><td> 0.1802432</td><td> 0.1802432</td></tr><tr><th>76</th><td>x7 </td><td>~~</td><td>x8</td><td>34.145089</td><td> 0.53644397</td><td> 0.53644397</td><td> 0.8591510</td><td> 0.8591510</td></tr><tr><th>77</th><td>x7 </td><td>~~</td><td>x9</td><td> 5.182955</td><td>-0.18670689</td><td>-0.18670689</td><td>-0.2775377</td><td>-0.2775377</td></tr><tr><th>78</th><td>x8 </td><td>~~</td><td>x9</td><td>14.946392</td><td>-0.42309592</td><td>-0.42309592</td><td>-0.8052026</td><td>-0.8052026</td></tr></tbody></table></div> 
<h2><a name="t35"></a><a id="9_SEMsemPlot_1687"></a>9. 加载SEM绘图包(semPlot)</h2> 
<p>参考资料:</p> 
<p>Structural Equation Modeling with lavaan in R<br> Sacha Epskamp and with contributions from Simon Stuber (2017). semPlot: Path Diagrams and Visual Analysis of Various SEM Packages’<br> Output. R package version 1.1. https://CRAN.R-project.org/package=semPlot</p> 
<p>1 能画出结构方程模型图的软件有很多,比如Amos和SmartPLS,这两个软件在可视化方面做的非常好,Mplus和前两个软件有所不同,它是通过语法输入,从diagrammer生成图形,而Amos和SmartPLS是用户直接绘制图形。</p> 
<p>2 R语言也可以绘制结构方程模型图,其优势在于用户可以对SEM图中的变量、线条、形状和颜色进行DIY。本文使用semPlot包中的semPaths函数进行模型图的绘制。</p> 
<p>3 使用参数layout来改变图形样式,其可选值包括5种:tree;circle;spring;tree2;circle2</p> 
<p>4 大多数人在做CFA的时候会把因子画在左侧,指标画在右侧,这样的图比较适合放在论文中。其实只需要将之前图片样式为tree状的图旋转90°即可。旋转可选的值有:1,2,3,4,分别是默认、逆时针旋转90°、180°以及270°。rotation = 2</p> 
<p>5 给线条上色使用参数edge.color,如我们想要深绿色的图,在该参数后写入darkgreen即可。edge.color = “darkgreen”</p> 
<p>6 还可以对潜变量或指标配色,直接用color,而非edge.color。 color = “lightblue”</p> 
<p>7 如果出现负载荷,图中带有负载荷的线条会变成红色。我们也可以使用posCol,negCol自定义正负载荷的配色</p> 
<pre data-index="59" class="prettyprint"><code class="prism language-R has-numbering" οnclick="mdcp.signin(event)" style="position: unset;">semPaths(object, what = "paths", whatLabels, style, layout = "tree", 
  intercepts = TRUE, residuals = TRUE, thresholds = TRUE, intStyle = "multi", 
  rotation = 1, curve, curvature = 1, nCharNodes = 3, nCharEdges = 3, sizeMan = 5,
   sizeLat = 8,  sizeInt = 2, sizeMan2, sizeLat2, sizeInt2, shapeMan, shapeLat, 
  shapeInt = "triangle", ask, mar, title, title.color = "black", title.adj = 0.1, 
  title.line = -1, title.cex = 0.8, include, combineGroups = FALSE, manifests, 
  latents, groups, color, residScale, gui = FALSE, allVars = FALSE, edge.color, 
  reorder = TRUE, structural = FALSE, ThreshAtSide = FALSE, thresholdColor, 
  thresholdSize = 0.5, fixedStyle = 2, freeStyle = 1, 
  as.expression = character(0), optimizeLatRes = FALSE, inheritColor = TRUE, 
  levels, nodeLabels, edgeLabels, pastel = FALSE, rainbowStart = 0, intAtSide, 
  springLevels = FALSE, nDigits = 2, exoVar, exoCov = TRUE, centerLevels = TRUE, 
  panelGroups = FALSE, layoutSplit = FALSE, measurementLayout = "tree", subScale, 
  subScale2, subRes = 4, subLinks, modelOpts = list(mplusStd = "std"), 
  curveAdjacent = '&lt;-&gt;', edge.label.cex = 0.6,  cardinal = "none", 
  equalizeManifests = FALSE, covAtResiduals = TRUE, bifactor, optimPoints = 1:8 * (pi/4), 
  ...)
<div class="hljs-button signin" data-title="登录后复制" data-report-click="{&quot;spm&quot;:&quot;1001.2101.3001.4334&quot;}"></div></code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li></ul></pre>
                </div><div><div></div></div>
                <link href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/markdown_views-22a2fefd3b.css" rel="stylesheet">
                <link href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/style-4f8fbf9108.css" rel="stylesheet">
        </div>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值