Hello.
My data frame has different rows of bacterial genes and a total of 6 columns, 3 for the control group and 3 for the experimental group. I want to do a t-test between the control group and the experimental group, and for each row, i.e. for each bacteria, I want to get the p-value between the two groups.
Here's the R code I used to do this:
col_t_test <- function(col) {
WT <- col(kegg_counts[1:3])
PK <- col(kegg_counts[4:6])
t_test_result <- t.test(WT, PK)
return(c(t_test_result$estimate, t_test_result$p.value))
}
results <- t(apply(kegg_counts, 1, col_t_test))
If you run the above code, all result values will be the same. Something seems wrong. Is there a good way?
Thank you for help!
A solution would be to use
t_test
function from therstatix
package, it provides an easy solution to your problem.A t-test isn't appropriate for count data.
I understand that you have count data (interger) with 3 replicates per group. It is important to understand where these counts are coming from to devise a good testing strategy. Please note that the accepted answer in this case would be incorrect.