Good morning, now I've improved it:
Thank you for your tips and help, then I will try it with Limma. As far as I know, x1 and x2 are already a vector. I'm trying to compare the RIGHT and FALSE.
A wrapper function to perform a t-test for all genes
my.t.test <- function(y, group, alternative = "two.sided"){
"x is a column vector of observations, take has two columns with logical values true or false"
x1 <- t(y[group[,1]])
x2 <- t(y[group[,2]])
tres <- t.test(x = x1, y = x2, alternative = alternative)
fc <- mean(x1) - mean(x2)
stat <- tres$statistic
if(alternative == "two.sided"){
stat <- abs(stat)
}
res<-matrix(c(stat, tres$p.value, fc), ncol=3)
colnames(res)<-c("statistic","p.value","fc")
return(res)
}
x <- exprs(wangExpr)
geneNames <- featureNames(wangExpr)
daten=list(x=x, geneid=as.character(1:nrow(x)) ,genename=geneNames , logged2=TRUE)
test sensitiv versus non sensitiv genes:
sVr<-cbind(cell.lines$drugsens=="s",cell.lines$drugsens=="r")
colnames(sVr)<-c("sensitiv", "rezesiv")
SensitivVersusRezesiv <- apply(X=x, MARGIN=1, FUN=my.t.test, group=sVr)
SensitivVersusRezesiv <- as.data.frame(t(SensitivVersusRezesiv))
colnames(SensitivVersusRezesiv)<-c("statistic","p.value","fc")
hist(SensitivVersusRezesiv$p.value, xlab = "pvalue",breaks=100)
SensitivVersusRezesiv <- SensitivVersusRezesiv[order(
abs(SensitivVersusRezesiv$p.value), decreasing=FALSE), ]
calculate q-values:
q.val <- qvalue(SensitivVersusRezesiv$p.value)
SensitivVersusRezesiv <- cbind.data.frame(SensitivVersusRezesiv, q.val$qvalues)
names(SensitivVersusRezesiv)<-c("statistic","p.value","fc", "q.value")
plot(SensitivVersusRezesiv$p.value, q.val$qvalues)
plot(q.val)
hist(SensitivVersusRezesiv$fc, breaks=100)
plot(SensitivVersusRezesiv$fc, -log(SensitivVersusRezesiv$p.value,base = 10),
xlab="fold change", ylab="-log10(p-value)")
computing you own FDRs using an FDR simulation:
permutDist <- function(x, group, observedStatistics){
group<-group[sample(1:nrow(group), replace = FALSE), ]
permStat <- apply(X=x, MARGIN=2, FUN=my.t.test, group=group)
permStat <-as.data.frame(t(permStat))
colnames(permStat)<-c("statistic","p.value","fc")
#print(permStat)
nGreater <- sapply(observedStatistics,
FUN = function(obs, perm){
return(sum(perm>obs))
}, permStat$statistic)
return(nGreater)
}
SensitivVersusRezesiv <- SensitivVersusRezesiv[order(
abs(SensitivVersusRezesiv$statistic), decreasing=TRUE), ]
B<-60
nGreaterThanObserved <- permutDist(x,sVr, SensitivVersusRezesiv$statistic)
for(bin in 2:B){
nGreaterThanObserved <- nGreaterThanObserved +
permutDist(x,sVr, SensitivVersusRezesiv$statistic)
}
nGreaterThanObserved <- nGreaterThanObserved/B
FDR <- nGreaterThanObserved/rank(nGreaterThanObserved)
SensitivVersusRezesiv<- cbind.data.frame(SensitivVersusRezesiv, FDR)
With this I got the following table:
statistic p.value fc q.value FDR 204855_at 9.587725 1.773681e-06 6.7472272 0.003023996 0 205239_at 8.533018 4.325952e-06 4.9501956 0.004603323 0 209270_at 8.330318 1.651930e-06 4.0318072 0.003023996 0 211667_x_at 8.320601 1.956686e-06 -0.4831631 0.003023996 0 200623_s_at 8.155573 6.163027e-05 -1.1984421 0.011102301 0 205070_at 8.139732 1.393233e-06 -1.4371348 0.003023996 0 210150_s_at 8.038277 1.351106e-06 1.7837117 0.003023996 0 210074_at 7.901260 1.655555e-06 4.0735272 0.003023996 0 37943_at 7.890438 2.009131e-06 1.1689482 0.003023996 0 209016_s_at 7.741336 3.320958e-06 6.3220215 0.003926546 0 210424_s_at 7.700025 2.273429e-06 1.1350697 0.003023996 0 204989_s_at 7.507732 9.725657e-06 2.9636502 0.005872305 0 201474_s_at 7.313394 4.823997e-06 2.7317807 0.004666638 0 206685_at 7.204983 6.409281e-06 1.1157027 0.005246332 0 203313_s_at 7.197138 1.899697e-04 1.9678139 0.014863984 0 206295_at 7.126566 9.389864e-06 4.8828937 0.005872305 0 213073_at 7.118477 7.881381e-06 1.4589036 0.005872305 0 206884_s_at 7.093565 3.307580e-05 5.0306353 0.009664292 0 201684_s_at 7.089161 7.378596e-05 0.7150009 0.011379270 0 214908_s_at 7.044968 5.965220e-06 -1.0282009 0.005246332 0
These are the top 20 genes, sorted by the t-statistic. I'm confused now, why the FDR = 0 is. But otherwise it looks good?
I don't think this is a good idea. There are advanced statistical frameworks for differential expression analysis.
please tell me you've got more than one resistant cell line; and please learn
limmahttps://bioconductor.org/packages/release/bioc/html/limma.htmlYes, but that should be our job. Do you know how to get it out with the t-test?
Please use
ADD COMMENTorADD REPLYto answer to previous reactions, as such this thread remains logically structured and easy to follow. I have now moved your reaction but as you can see it's not optimal. Adding an answer should only be used for providing a solution to the question asked.Right. Sorry, I just did not pay attention. I will pay attention to it now.
You will also find this useful: How to add images to a Biostars post
Using a straight t-test is a fools errand. Learn how to do it using moderated t-tests in limma
But I can not use that. In the picture I have attached, it says that I should do it only with a t-test first. For me it does not work at the moment. Is "limma" the same?
So this is an assignment?
Yes, I have more than one. This should only be an excerpt.