How to finish this loop for my anova model as single variable analysis?

I have a dataset about gene expression, which has n=62 observations and p=2000 variables (human genes). I also have one Y binary variable, which denotes as 2==Tumor and 1==Normal.

I need to create one-way ANOVA between y and each X. So there are 2000 ANOVAs. I need to extract each p-value. So I will create a vector that has 2000 components, here are 2000 p values. Then I need to order these p-values. The reason that I do this is I will do false discovery rate (FDR) (Benjamini and Hochberg) later.

one.way <- aov(response ~ X1, data = df)
summary(one.way)[[1]][["Pr(>F)"]][1]

one.way <- aov(response ~ X2, data = df)
summary(one.way)[[1]][["Pr(>F)"]][1]

one.way <- aov(response ~ X3, data = df)
summary(one.way)[[1]][["Pr(>F)"]][1]

I need to do response ~ X1 until response ~ X2000. How to do that and order these p-values and its corresponding X?

By the way, I omit uploading my dataset. Because otherwise the website will be full of my data.

dput(head(df,4))

Could you add the output of this?

okay, I have to add part of the output. Because it is too much.

dput(head(df,1))

structure(list(X1 = 2.1147523, X2 = 1.087244, X3 = 0.9173305, ..., X1998 = -0.14065557, X1999 = 1.5858229, X2000 = 0.20834469, 
    response = 2), row.names = "V1", class = "data.frame")
1 Like

The question is solved by using for loop.

1 Like