I want to perform a 1-factor ANOVA with 4 levels, ie is.ctl
, II
, III
, and IV
.
# Tissue grades
is.ctl <- grepl("^NB", names(dat))
II <- grepl("^II", names(dat))
III <- grepl("^III", names(dat))
IV <- grepl("^IV", names(dat))
#1-factor ANOVA with 4 levels
aov.all.genes <- function(x,s1,s2,s3,s4) {
x1 <- as.numeric(x[s1])
x2 <- as.numeric(x[s2])
x3 <- as.numeric(x[s3])
x4 <- as.numeric(x[s4])
fac <- c(rep("A",length(x1)), rep("B",length(x2)), rep("C",length(x3)), rep("D",length(x4)))
a.dat <- data.frame(as.factor(fac),c(x1,x2,x3,x4))
names(a.dat) <- c("factor","express")
p.out <- summary(aov(express~factor, a.dat))[[1]][1,5]
#p.out <- summary(aov(express~factor, a.dat))[[1]][1,4] # use to get F-statistic
return(p.out)
}
#run AVOVA function
dat.log <- log2(dat)
aov.pv <- apply(dat.log, 1, aov.all.genes,s1=is.ctl,s2=II,s3=III,s4=IV)
Error in
contrasts<-
(*tmp*
, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels
Since dput
of a dataframe subset did not reproduce the error, I'm attaching a link to the full data:
https://drive.google.com/file/d/1i_ZysUdpQKTLNoRxkHW_UNs5SqTRyaP0/view?usp=sharing