Apologies, I wrote this a few days ago but forgot to submit it. Luckily the browser didn't delete it :-)
First of all, let's recreate your data frame:
library(dplyr)
library(tidyr)
d = data.frame(
inheritance=apply(m, 1, function(x) {c(rep("Oncogene", x[1]), rep("TS", x[2]), rep("Rest", x[3]))}) %>% unlist ,
genefunction = rep(c("Quescent", "Repressive", "Bivalent", "Active"), rowSums(m))) %>%
tbl_df
> d %>% count(inheritance, genefunction) %>% spread(inheritance, n)
# A tibble: 4 × 4
genefunction Oncogene Rest TS
* <fctr> <int> <int> <int>
11 Active 13 546 17
2 Bivalent 9 462 8
3 Quescent 7 257 6
4 Repressive 13 504 8
> d %>% head
# A tibble: 6 × 2
inheritance genefunction
<fctr> <fctr>
11 Oncogene Quescent
2 Oncogene Quescent
3 Oncogene Quescent
4 Oncogene Quescent
5 Oncogene Quescent
6 Oncogene Quescent
At this point we can use a regression to calculate how much belonging to a specific class (Active, Bivalent, etc..) increases the odds of being a TS gene:
> d %>% lm(I(inheritance=="TS")~genefunction-1, data=. ) %>% summary
Call:
lm(formula = I(inheritance == "TS") ~ genefunction - 1, data = .)
Residuals:
Min 1Q Median 3Q Max
-0.02951 -0.02951 -0.01670 -0.01524 0.98476
Coefficients:
Estimate Std. Error t value Pr(>|t|)
genefunctionActive 0.029514 0.005987 4.930 8.96e-07 ***
genefunctionBivalent 0.016701 0.006565 2.544 0.0110 *
genefunctionQuescent 0.022222 0.008744 2.541 0.0111 *
genefunctionRepressive 0.015238 0.006271 2.430 0.0152 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.1437 on 1846 degrees of freedom
Multiple R-squared: 0.02284, Adjusted R-squared: 0.02072
F-statistic: 10.78 on 4 and 1846 DF, p-value: 1.214e-08
In this case, Active genes are the only one significantly more likely to be TS, although the odds ratio is not big.
You need the background frequencies in addition, like how many tumor supressor genes and oncogenes are there in total in your genome? Then your problem reduces to the following urn-lottery: Set up a lottery: you put G balls into the basket, N labelled Tum. and M labelled Onc. Now you draw J < G balls from your lottery without putting them back. What is the probability of having n>=7 labelled Tum. and m>=6 labelled Onc. in your sample.
Thanks for reply Michael!!! I've edited the question. It may be a bit different from the previous one. Actually I use the second type of lists(TSG/OG) to annotate the first list(result list of my analysis).
You have 2 categorical lists (Quiescent, Repressive, Bivalent and Active) and (Tumor Suppressor Genes, Oncogenes) and want to compare which factor has more relevance? Then test it with McNemar. See this page for more help.
No, the second list contains three factors: Tumor Suppressors, Oncogenes, and All other genes.
What are the scores in your second file?
The score in second is the predicted score from the list(predicted from a large data set of mutation signature). The higher the score, the more likely that the gene would be TSG or OG. But in my case, I would be more interested in finding which gene in my gene list are predicted as TSG or OG.
This question is incomplete. Are you asking if repressive genes are more associated with tumor suppressors compared than any other gene, or compared to oncogenes? I would do a fisher test or a regression, but first you need to define what you are looking for.
I want to see whether repressive genes are more associated with tumor suppressors compared to oncogenes. Thanks for pointing out the incomplete part!
thanks, but notice that in this way the "all genes" dataset is not taken into consideration.