# using feces ESI(-) data for a showcase
# Step 1. Data transformation: Pareto scaling followed by log10 transformation
# write up my functions
pareto_scaling <- function(x){
(x - mean(x)) / sqrt(sd(x))
}
log_transf <- function(x){
log10(x+abs(min(x))+1.1)
}
fecNeg <- read.csv("raw4Trans_fec_neg.csv",encoding="UTF-8")
samplename_fecneg <- read.csv("samplename_fecneg.csv")
rownames(fecNeg) <- as.vector(samplename_fecneg$fec_neg)
fecNeg_pareto <- t(apply(fecNeg, 1, pareto_scaling))
write.csv(fecNeg_pareto,"fecNeg_pareto.csv")
fecNeg_pareto_log10 <- t(apply(fecNeg_pareto,1,log_transf))
write.csv(fecNeg_pareto_log10,"fecNeg_pareto_log10.csv")
# Step 2. Compute two-way ANOVA
gender0 <- rep(c("male","female"), each = 6)
gender1 <- rep(c("female","male"), each = 6)
gender <- c(gender0,gender1)
gender
group <- rep(c("CONV-R","GF"), each = 12)
group
# transpose the data --> make column feature, row as factor
p_fecNeg <- as.data.frame(t(fecNeg_pareto_log10))
# Perform NA Imputation if there are any
any(is.na(p_fecNeg))
# attach factor information
p_fecNeg$gender <- gender
p_fecNeg$group <- group
# two-way ANOVA
#----------------------------
# use p_fecPos as an example
# check the matrices for ANOVA computation
library(tidyverse)
library(ggpubr)
library(rstatix)
# try just one feature first; see this will work
class(p_fecNeg)
str(p_fecNeg)
colnames(p_fecNeg)
aov_fecNeg <- p_fecNeg %>% anova_test(M100T0_1 ~ gender * group)
aov_fecNeg
colnames(p_fecNeg)[[4801]]
aov_fecNeg <- p_fecNeg %>% anova_test(M198T1_5 ~ gender * group)
aov_fecNeg
str(aov_fecNeg)
跑最后几句的时候,出现了问题 ,它说没有定义选定列,可我不会做
aov_fecNeg <- p_fecNeg %>% anova_test(M100T0_1 ~ gender * group)
Error in[.data.frame
(.args$data, , model.variables) :
undefined columns selected