差异基因的检测方法很多,但生物学家偏好使用的是fold change(FC)和t-test。猜测因为一是它们比较简单,二来好解释。 很多研究表明,改进的t-test可以提高top gene list的质量。 值得注意的是,基于FC的gene list比基于t-test的可重复性强,但这不代表着更准确。 所以,如果关注基因表达的绝对变化,则看FC 如果关注潜在的噪音,则用t-test。 2 T-test 差异性=signal/noise,期中signal即为组间变异,二noise为组内变异 groupA和groupB的差异XA均值-XB均值,这个同FC的M均值。 继而,有基于贝叶斯理论的moerated t-test。也是最常用的。
# Welch t-test t.test(extra ~ group, sleep) #> #> Welch Two Sample t-test #> #> data: extra by group 注意Welch t-test结果中df=17.776,这是因为对不同质方差进行了校正。要使用Student t检验的话,设置var.equal=TRUE。 # Student t-test t.test(extra ~ group, sleep, var.equal=TRUE) #> #> Two Sample t-test #> #> data: extra 再次说明,t-test函数可以用于有分组变量的数据框或者两个向量。它依赖相对位置来决定配对。如果你使用有分组变量的长格式数据,group=1的第一行与group2的第一行配对。 # Sort by group then ID sleep <- sleep[order(sleep$group, sleep$ID), ] # Paired t-test t.test(extra
多组比较,到底该用Ordinary one-way ANOVA还是t-test? 我们只要记住一点:选择哪种检验,不应由“有几组数据”决定,而应由“你想回答什么科学问题”决定。 场景一:应该直接使用t-test或它的变体(只关心“处理 vs 对照”)你事先只计划比较特定的几组。例如,你的实验有“对照组”、“药物A低剂量”、“药物A高剂量”、“药物B”四组。 你从实验设计之初就只关心:“药物A高剂量” vs “对照组”“药物B” vs “对照组”正确做法:放弃全局ANOVA,直接使用事先计划好的比较,比如 Dunnett检验(与单个对照组比较)或 Bonferroni校正的t-test 首选 Dunnett 检验(一对多、对照型比较);或 多次 t-test + Holm/Šidák/Bonferroni 校正;若方差不齐/样本不等,用 Welch t-test + 校正 或 不等方差版
issues/65#issuecomment-407211245[1] library(tidyverse) library(rstatix) library(ggpubr) # Pairwise t-test p method p.adj y.position 1 0.5 len OJ VC 3.1697328 0.0064 T-test 0.0128 35 2 1.0 len OJ VC 4.0327696 0.0010 T-test 0.0030 35 3 2.0 len OJ VC -0.0461361 0.9600 T-test 0.9600 35 # Create a box plot and add the p-value p <
需要利用BayesFactor包进行建模, 内容非常多,不做过多介绍了,有兴趣的小伙伴自己去搜一下吧(๑→ܫ←) library(BayesFactor) # one sample t-test mod1 <- ttestBF(mtcars$wt, mu = 3) # independent t-test mod2 <- ttestBF(formula = wt ~ am, data = mtcars ) # paired t-test mod3 <- ttestBF(x = sleep$extra[1:10], y = sleep$extra[11:20], paired = TRUE) # correlation = .5) # list of plots combine_plots( plotlist = list( ggcoefstats(mod1, title = "one sample <em>t-test</em> "), ggcoefstats(mod2, title = "independent <em>t-test</em>"), ggcoefstats(mod3, title = "paired <em>t-test</em>
30.8) 1.000 Distress (mean (sd)) 22.86 (11.38) 24.13 (11.88) 0.222 With a p-value of 0.222, Student’s t-test group 0 mean in group 1 ## 0 0 ## ## ## [[2]] ## ## Welch Two Sample t-test group 0 mean in group 1 ## 37.6 39.6 ## ## ## [[3]] ## ## Welch Two Sample t-test ecls_cov, function(v) { t.test(dta_m[, v] ~ dta_m$catholic) }) ## [[1]] ## ## Welch Two Sample t-test We can use a t-test,Or we can use OLS with or without covariates。
如果要检验均值是否相等 t.test(women_weight,men_weight) 输出结果是 Welch Two Sample t-test data: women_weight and men_weight 这个做的是Welch Two Sample t-test,如果要做学生式T检验,可以在t.test()函数里加var.equal=T参数 > t.test(women_weight,men_weight ,var.equal=T) Two Sample t-test data: women_weight and men_weight t = -20.791, df = 38, p-value < 结果 Two Sample t-test data: men_weight and women_weight t = 20.791, df = 38, p-value < 2.2e-16 alternative
需要利用BayesFactor包进行建模, 内容非常多,不做过多介绍了,有兴趣的小伙伴自己去搜一下吧(๑→ܫ←) library(BayesFactor) # one sample t-test mod1 <- ttestBF(mtcars$wt, mu = 3) # independent t-test mod2 <- ttestBF(formula = wt ~ am, data = mtcars ) # paired t-test mod3 <- ttestBF(x = sleep$extra[1:10], y = sleep$extra[11:20], paired = TRUE) # correlation = .5) # list of plots combine_plots( plotlist = list( ggcoefstats(mod1, title = "one sample <em>t-test</em> "), ggcoefstats(mod2, title = "independent <em>t-test</em>"), ggcoefstats(mod3, title = "paired <em>t-test</em>
(1)用Student’s t-test 计算差异基因表达、差异甲基化,用GISTIC2方法识别样本的拷贝数扩增和缺失,将样本根据基因的拷贝数状态分组,然后用Student’s t-test 计算差异表达 cnv_data,amp_gene,del_gene, p.adjust=FALSE,method="fdr") #若p.adjust=TRUE,则返回校正后的P值 (2)getExpp 对基因表达数据进行t-test 方法计算联合P值 (1)combinep_three 计算联合三个维度的P值,用以计算z-score 所用示例文件(其实就是上述1.(1)(2)(3)中得到的结果文件): exp.p:Student’s t-test 计算差异基因表达,然后校正P值 meth.p:Student’s t-test 差异甲基化,然后校正P值 cnv.p:GISTIC2方法识别样本的拷贝数扩增和缺失,将样本根据基因的拷贝数状态分组,然后用 Student’s t-test 计算差异表达,然后校正P值 exp.p<-GetExampleData("exp.p") meth.p<-GetExampleData("meth.p") cnv.p
安装过程如下 source(“http://bioconductor.org/biocLite.R“) biocLite(“bsseq”) bsseq的分析主要包括以下4步: 读取原始数据 BSmooth t-test T-test 在分析之前,有必要过滤掉覆盖度较低的甲基化位点。通常保留在所有样本中覆盖度大于2的甲基化位点,但是也可以修改这个条件。 cutoff 指定DMR的阈值,这个阈值根据t-test的结果进行调整。subset对差异甲基化的结果进行筛选,筛选包含甲基化位点个数大于3而且meanDiff 大于0.1的甲基化区域。
本教程分为三个部分; 他们是: t-测试 独立样本的t检验 相关样本的t检验 t检验 t检验(Student’s t-Test)是一种统计假设检验,用来检验两个样本是否如逾期一样来自同一人群。 例如,参见Welch’s t-test。 t检验有两个主要版本: 独立样本。两个样本不相关的情况。 相关样本。样本相关的情况,例如对同一种群的重复测量。也称为配对检验(paired test)。 我们可以将这些部分组合成一个简单的函数来计算两个独立样本的t检验: # function for calculating the t-test for two independent samples def 完整的示例: # Student's t-test for independent samples from numpy.random import seed from numpy.random import 以下是完整的示例,包括已开发的函数和函数结果的解释: # t-test for dependent samples from math import sqrt from numpy.random import
ggstatsplot在统计学分析方面:目前它支持最常见的统计测试类型:t-test / anova,非参数,相关性分析,列联表分析和回归分析。 reproducibility set.seed(123) # let's leave out one of the factor levels and see if instead of anova, a t-test the plot fill.gradient = TRUE, # use color gradient test.value = 10, # the comparison value for t-test test.value.line = TRUE, # display a vertical line at test value type = "bf", # bayes factor for one sample t-test
library(MASS) t.test(Prob ~ So,data=UScrime) 输出: Welch Two Sample t-test data: Prob by So t = -3.8954 为非独立的数值向量 t.test(y1,y2,paired=TRUE) library(MASS) with(UScrime, t.test(U1,U2,paired=TRUE)) 输出:Paired t-test
> t.test(intake,mu=7725) One Sample t-test data: intake t = -2.8203, df = 10, p-value = 0.01815 alternative percent confidence interval: 5986.394 7521.061 sample estimates: mean of x 6753.727 结果解释:One Sample t-test 我们的目的是比较两组的能量消耗水平是否有差异,所以我们使用如下的t检验(设定数据满足正态分布): > t.test(expend~stature) Welch Two Sample t-test data > t.test(expend~stature,var.equal=T) Two Sample t-test data: expend by stature t = -3.9456, df = 20 配对t检验可以通过下面代码实现: > t.test(pre,post,paired=T) Paired t-test data: pre and post t = 11.941, df = 10,
> t.test(intake,mu=7725) One Sample t-test data: intake t = -2.8203, df = 10, p-value = 0.01815 alternative percent confidence interval: 5986.394 7521.061 sample estimates: mean of x 6753.727 结果解释:One Sample t-test 我们的目的是比较两组的能量消耗水平是否有差异,所以我们使用如下的t检验(设定数据满足正态分布): > t.test(expend~stature) Welch Two Sample t-test data > t.test(expend~stature,var.equal=T) Two Sample t-test data: expend by stature t = -3.9456, df = 20 配对t检验可以通过下面代码实现: > t.test(pre,post,paired=T) Paired t-test data: pre and post t = 11.941, df = 10,
# 识别标记基因 sc.tl.rank_genes_groups(adata, 'leiden', method='t-test') # 可视化标记基因 sc.pl.rank_genes_groups( # 差异表达分析 sc.tl.rank_genes_groups(adata, 'leiden', method='t-test') # 查看结果 sc.pl.rank_genes_groups(adata , n_genes=25, sharey=False) scanpy.tl.rank_genes_groups 支持多种方法,如't-test', 'logreg', 'wilcoxon'等。 sc.pl.rank_genes_groups(adata, n_genes=25, sharey=False) # 差异表达分析 sc.tl.rank_genes_groups(adata, 'leiden', method='t-test
在 Herderson 的论文中,two-sample t-test 和自举置信区间试验可用于此目的。 T-test 和 Welch's test 为了验证两个种群具有相同的均值的假设(零假设 ? )。一个 2-sample t-test 可以在两个种群的变量假设为一致时进行测试。 在这种情况下,2-sample t-test的变种 Welch's test 被提出了。 使用 Welch's t-test 实验的步骤为: 基于 ? 计算自由度 v 和 t-statistics; 通过 t-table 查表获取 ? 选择 t-test 的显著级别 α 会导致第一种错误的情况。但是,上图显示的是减少这种概率归结为提高 ? 的值,这最终导致了第二种错误的出现。
在 Herderson 的论文中,two-sample t-test 和自举置信区间试验可用于此目的。 T-test 和 Welch's test 为了验证两个种群具有相同的均值的假设(零假设 ? )。一个 2-sample t-test 可以在两个种群的变量假设为一致时进行测试。 在这种情况下,2-sample t-test的变种 Welch's test 被提出了。 使用 Welch's t-test 实验的步骤为: 基于 ? 计算自由度 v 和 t-statistics; 通过 t-table 查表获取 ? 选择 t-test 的显著级别 α 会导致第一种错误的情况。但是,上图显示的是减少这种概率归结为提高 ? 的值,这最终导致了第二种错误的出现。
continuous data, the differences between two groups were assessed using Mann-Whitney U test or Student's t-test lesion glycolysis image.png Shapiro-Wilk test:进行正态分布的检验 Mann-Whitney U test, MWW检验,对独立样本进行的一种不要求正态分布的t-test
np.random.normal(0, 3, 30) factory_b = np.full(30, 353) + np.random.normal(0, 3, 30) # Run a 1 sample t-test np.random.normal(0, 3, 30) factory_b = np.full(30, 353) + np.random.normal(0, 3, 30) # Run a two sample t-test + np.random.randint(-1, 4) post_training = list(map(apply_training, pre_training)) # Run a paired t-test productivity, pre vs. post differences = [x-y for x,y in zip(post_training, pre_training)] # Run a 1-sample t-test