'Perform T test on DE genes pathologies in R

I have this:

subset_1 <- degs[degs$pathol=='fibrosis'&degs$value==1,]
mean_1 <- mean(subset_1$logFC)
sd_1 <- sd(subset_1$logFC)
tsub_1 <- t.test(mean_1, sd_1 alternative = c(“two.sided”, “less”, “greater”))

subset_0 <- degs[degs$pathol=='fibrosis'&degs$value==0,]
mean_0 <- mean(subset_0$logFC)
sd_0 <- sd(subset_0$logFC)

ttest <- t.test(mean_1, sd_1)

I am getting this error:

Error in t.test.default(mean_1, sd_1) : not enough 'x' observations

I am trying to make a t.test on the subset_1 and subset_0 LogFC column.

I am not sure how to calculate the t.test, I thought I need put as input the mean and standard deviation that I calculated from a column in the subset tables which has a column for logFC, I took the mean and sd of that... and tried both ways to obtain the t.test. I read a lot of info on this but still am having trouble with the input.



Solution 1:[1]

You are complicating too much. Use t.test argument subset to keep the rows you want.
Untested, since there are no data in the question.

fibr <- degs$pathol == "fibrosis"
val01 <- degs$value %in% c(0, 1)

ttest <- t.test(logFC ~ value, data = degs, subset = fibr & val01)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rui Barradas