【问题标题】:repeated measures anova: length of 'dimnames' [1] not equal to array extent重复测量方差分析:“dimnames”[1] 的长度不等于数组范围
【发布时间】:2016-05-08 15:58:11
【问题描述】:

我进行了重复测量anova,这是我的代码,操作简单,我总是很快。

Link to mydata in .csv format

library(car)
vivo4  <- read.csv("vivo1.csv",sep=";",dec=",")

ageLevels  <- c(1, 2,3,4,5,6,7,8,9,10,12)
ageFactor  <- as.factor(ageLevels)
ageFrame  <- data.frame(ageFactor)

measures  <- function(data = vivo4, n = 4) { #n=4 is 4 variables
  ## Editor comment:
  ## correct way to initialize a list, don't use "list(n)"
  ## you can compare what you get from "list(4)" and "vector ("list", length = 4)"
  ## lmo's comment: don't use "list" for your variable name (may mask R function "list")
  ## I have corrected it as "Mylist"
  Mylist  <- vector("list", length = n)
  for(i in 0:3) {Mylist[[i+1]]  <- as.matrix(cbind(data[, 12*i + 1:12])) # 12 visits
  }
  Mylist
}

measures_list  <- measures()

models  <- lapply(
  measures_list, function(x) {
    ageModel  <- lm(x ~ 1)
    Anova.mlm (ageModel, idata = ageFrame, idesign = ~ageFactor)
  } )

models #View the result

但我得到了错误

Error in `rownames<-`(`*tmp*`, value = colnames(B)) : 
  length of 'dimnames' [1] not equal to array extent 

我已经阅读了很多答案,但无法理解问题所在,我需要监督。

【问题讨论】:

  • 至少,将您的对象命名为与重要的对象类相同是一种糟糕的形式。我建议您使用与列表不同的名称,例如 myList。

标签: r anova r-car


【解决方案1】:

您的数据集中有 12 个级别,但在年龄级别中,您只表示了 11 个级别。 即你忘了指明 14

ageLevels 14)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-25
    • 1970-01-01
    • 2016-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多