【问题标题】:R SEM error "Incorrect number of dimensionsR SEM 错误“尺寸数不正确
【发布时间】:2020-12-30 07:43:16
【问题描述】:
#Loehlin problem 2.5 
obs.var2.5 = c('Ach1',  'Ach2',  'Amb1',  'Amb2',  'Amb3')
R.prob2.5 = matrix(c(
1.00 ,  .60  , .30,  .20,   .20,                                               
.60,  1.00,   .20,   .30,   .10,                                                
.30,   .20,  1.00,   .70,   .60 ,                                               
.20,   .30,   .70,  1.00,   .50,                                                
.20,   .10,   .60,  .50,  1.00), ncol=5,byrow=TRUE)    

#correlated factors structure (ambition <-> Achievement) 
model2.5=matrix(c(
'Ambit ->  Amb1',      'a', NA,
'Ambit -> Amb2' ,      'b', NA,
'Ambit -> Amb3' ,      'c', NA,
'Achieve -> Ach1',     'd', NA,
'Achieve -> Ach2',     'e', NA,
'Ambit <-> Achieve',   'f', NA,
'Amb1 <-> Amb1' ,      'u', NA,
'Amb2 <-> Amb2' ,      'v', NA,
'Amb3 <-> Amb3' ,      'w', NA,
'Ach1 <-> Ach1' ,      'x', NA,
'Ach2 <-> Ach2' ,      'y', NA,
'Achieve <-> Achieve',  NA, 1,
'Ambit <-> Ambit',      NA, 1),
ncol=3, byrow=TRUE)

sem2.5= sem(model2.5,R.prob2.5,60, obs.var2.5)
summary(sem2.5,digits=3)

**** 来自http://personality-project.org/r/r.sem.html

我尝试通过简单地将代码原样复制/粘贴到 jupyter 笔记本中并逐块运行代码来简单地重新创建结果。

在我尝试重新创建模型之前,代码都运行良好:

即:sem2.5= sem(model2.5,R.prob2.5,60, obs.var2.5)

我不断收到此错误:


Error in data[, obs.variables]: incorrect number of dimensions
Traceback:

1. sem(model2.5, R.prob2.5, 60, obs.var2.5)
2. sem.semmod(model2.5, R.prob2.5, 60, obs.var2.5)
------------------------------------------------------------

我到底错过了什么?在对包依赖项和版本控制进行了很​​多讨论之后,我觉得我只是在这里睁一只眼闭一只眼,答案就在眼前。

我需要做什么才能重新创建已发布的此模型?

【问题讨论】:

    标签: r structural-equation-model


    【解决方案1】:

    该文档中有错误。您需要命名变量。

    rownames(R.prob2.5) <-  colnames(R.prob2.5 ) <- c('Ach1',  'Ach2',  'Amb1',  'Amb2',  'Amb3’)
    sem2.5= sem(model2.5,R.prob2.5,60)
    

    这应该可以解决问题。

    (2 月 15 日更正)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多