Reputation: 11
I conducted the repeated measures anova, that's my code, it's simple operation and i always did it quickly.
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
but i got the error
Error in `rownames<-`(`*tmp*`, value = colnames(B)) :
length of 'dimnames' [1] not equal to array extent
I have read many answers and can't understand whats wrong, i need supervision.
Upvotes: 1
Views: 1263
Reputation: 3195
You have 12 levels in your dataset,but in agelevels, you indicated only 11 levels. i.e. you forgot indicate 14
ageLevels <- c(1, 2,3,4,5,6,7,8,9,10,12,14)
Upvotes: 1