I have two normalized gene expression values (log2 of cpm)
> head(biomarker[,1:5])
A2 A3 A4 A6 A7
A2M 12.4071618 12.631601 12.889748 11.842511 11.574134
ABCB11 0.5151957 6.176788 5.414905 7.134915 1.247590
ABCC2 6.7244303 6.487794 10.178615 6.384132 6.089462
ABCC6 6.3977122 5.823627 7.370761 7.397091 6.071587
ABCF1 9.1609847 9.893258 10.116638 10.225520 10.838486
ABCG2 7.6841874 7.738293 6.833152 6.888041 6.030032
>
And
> head(immune[,1:5])
A2 A3 A4 A6 A7
A2M 10.904748 11.388404 9.910614 11.513439 12.963609
ABCB11 5.011380 6.359443 7.145992 8.451947 7.722605
ABCC2 5.040461 6.477014 3.873996 6.409777 9.133971
ABCC6 7.798441 7.601848 9.948072 11.628533 12.701460
ABCF1 8.553597 8.615425 11.145903 10.289098 11.444140
ABCG2 6.224294 5.629375 8.293416 7.979859 8.603793
>
> dim(biomarker)
[1] 719 56
> dim(immune)
[1] 719 56
>
I have matched samples in these experiments and same gene too. I could roughly say in both experiments everything has been constant. However, I want to do Student's t-Test to find genes that they had inconsistent gene expression patterns between the two data sets.
By this function I am getting a list but I don't know how to extract the names of genes with p-value > 0.05 or whatever cut-off
> f <- function(x,y){
+ test <- t.test(x,y, paired=TRUE)
+ out <- data.frame(stat = test$statistic,
+ df = test$parameter,
+ pval = test$p.value,
+ conl = test$conf.int[1],
+ conh = test$conf.int[2]
+ )
+ return(out)
+ }
> t=sapply(seq(ncol(t(biomarker))), function(x) f(t(biomarker)[,x], t(immune)[,x]))
Any help please?
str(t)
[list output truncated]
- attr(*, "dim")= int [1:2] 5 719
- attr(*, "dimnames")=List of 2
..$ : chr [1:5] "stat" "df" "pval" "conl" ...
..$ : NULL
>
> sapply(t, "[[", "pval")
Error in FUN(X[[i]], ...) : subscript out of bounds
>
> pvalueGenes <- sapply(colnames(biomarker),function(i) t.test(biomarker[i, ],immune[i, ], paired = TRUE)$p.value)
Error in if (stderr < 10 * .Machine$double.eps * abs(mx)) stop("data are essentially constant") :
missing value where TRUE/FALSE needed
In addition: Warning messages:
1: In mean.default(x) : argument is not numeric or logical: returning NA
2: In if (stderr < 10 * .Machine$double.eps * abs(mx)) stop("data are essentially constant") :
Show Traceback
Rerun with Debug
Error in if (stderr < 10 * .Machine$double.eps * abs(mx)) stop("data are essentially constant") :
missing value where TRUE/FALSE needed
colnames
instead? Have you searched the internet about how to get names of the variables you iterate over them? BTW you might be interested in the broom package, functiontidy
. $\endgroup$tibble::rownames_to_column(biomarker, col_name)
. You could even dobiomarker$col_name <- colnames(biomarker)
$\endgroup$