用R对数据进行T检验,如何得到的标准差 标准误误

苹果/安卓/wp
积分 690, 距离下一级还需 110 积分
权限: 自定义头衔, 签名中使用图片
道具: 彩虹炫, 涂鸦板, 雷达卡, 热点灯, 金钱卡, 显身卡, 匿名卡, 抢沙发下一级可获得
权限: 隐身
购买后可立即获得
权限: 隐身
道具: 金钱卡, 彩虹炫, 雷达卡, 热点灯, 涂鸦板
17:28:24 上传
这是我用这是我用R做的y对x1,x2,x3,x4的多元回归的检验结果。有两个问题想请教一下:①“Sum Sq”和&Mean Sq&那两列的数值为什么是一样的?②为什么x1,x2,x3,x4都有一个F值。按我的理解,要做F检验的话不是只有一个F值吗?而且应该是针对y计算的F值呀?
第一个问题那两列一样是因为自由度为1,sum/1=Mean
第二个问题多元回归除对回归方程要做显著性检验外还需要需要对回归系数做显著性检验,这就是会有F的原因,当然这里也可以用t检验,但是可以用t检验那就一定可以用F检验,这个从统计量就能看出来
回答完毕,希望对lz有用
热心帮助其他会员
总评分:&论坛币 + 50&
个人主页,欢迎订阅http://chenangliu.info/
In response to question 2, You should know that you are fitting a ordinary linear model with 4 predictors (not the traditional one way ANOVA for single factor problem), that is why you got 4 F values. Also take care when you are trying to interpret them, since the variables are not mutually orthogonal. (check the concepts such as &sequential sum squares& and &partial sum squares&)
To sum, before applying any software to data, try to understand what model you used and how to interpret it.
hugebear 发表于
In response to question 2, You should know that you are fitting a ordinary linear model with 4 predi ...学习了
最好的医生是自己,最好的药物是时间……
初级热心勋章
初级热心勋章
初级信用勋章
初级信用勋章
中级热心勋章
中级热心勋章
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
如有投资本站或合作意向,请联系(010-);
邮箱:service@pinggu.org
投诉或不良信息处理:(010-)
论坛法律顾问:王进律师利用R进行配对数据t检验利用R进行配对数据t检验一花视界百家号在生物学和医学试验中,经常将试验材料配成对子。如单卵双生子的两个孪生子,同一植株上的两根枝条等。这些试验产生的数据之间存在紧密的内在联系,称为配对数据。配对数据的t检验公式可由
单样本t检验
公式推导,其本质是将配对数据差值看做一个单样本,进行单样本t检验。配对数据t统计量计算公式为: 其中
原假设(无效假设或零假设):ud=0备择假设:ud≠0ud&0ud&0例题为了研究两种病毒对番茄的致病能力有无差异,在8种番茄上各选取一个叶片,并沿主脉分成对称的两部分,把两种病毒分别随机涂抹在每片叶的两半片叶上,一周后观测叶片上的病斑数。试测验两种处理方法的差异显著性。品种
8.375正态性检验代码:#赋值A=c(25,12,14,15,12,27,18,18)B=c(10,13,8,3,5,20,6,9)x=A-B#shapiro检验shapiro.test(A)shapiro.test(B)shapiro.test(x)程序运行结果程序运行结果
上述结果表明:样本数据均通过正态性检验配对t检验代码:t.test(x,paired=T)程序运行结果: 配对t检验 结果表明,p-value = 0..01,两种处理方法的具有极显著差异。本文仅代表作者观点,不代表百度立场。系作者授权百家号发表,未经许可不得转载。一花视界百家号最近更新:简介:一花一树皆学问,凡事洞明即文章作者最新文章相关文章苹果/安卓/wp
积分 449, 距离下一级还需 1 积分
权限: 自定义头衔, 签名中使用图片
道具: 彩虹炫, 涂鸦板, 雷达卡, 热点灯, 金钱卡, 显身卡, 匿名卡下一级可获得
道具: 抢沙发
购买后可立即获得
权限: 隐身
道具: 金钱卡, 彩虹炫, 雷达卡, 热点灯, 涂鸦板
开心签到天数: 24 天连续签到: 1 天[LV.4]偶尔看看III
R语言回归后,例如L=lm(Y~X1+X2+X3),通过summary(L),会得到一些指标,想问下有没有什么简单的语句直接能够提取t值和p值,例如我想直接提取出残差,可以直接写residuals(L)即可,那么,能分别直接提取出值t值和p值吗
data(mtcars)
fit1 &- lm(mpg~cyl,data=mtcars)
y&-as.data.frame(summary(fit1))
# 系数t值
y$t
# 系数p值
y$Pr复制代码
& y=as.data.frame(summary(fit1))
Error in as.data.frame.default(summary(fit1)) :
&&cannot coerce class &&summary.lm&& to a data.frame
本帖最后由 crystal8832 于
02:31 编辑
summary(fit1)$coefficients[,'t value']
summary(fit1)$coefficients[,'Pr(&|t|)']
用broom包里的tidy()函数,整理成数据框就可以了。
愤怒的小鸟! 发表于
R语言回归后,例如L=lm(Y~X1+X2+X3),通过summary(L),会得到一些指标,想问下有没有什么简单的语句直接能够 ...谢谢大家
kk=summary(L)
kk$coef[1,3]就是第一个参数的t值
初级热心勋章
初级热心勋章
中级热心勋章
中级热心勋章
初级信用勋章
初级信用勋章
初级学术勋章
初级学术勋章
中级信用勋章
中级信用勋章
高级热心勋章
高级热心勋章
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
如有投资本站或合作意向,请联系(010-);
邮箱:service@pinggu.org
投诉或不良信息处理:(010-)
论坛法律顾问:王进律师苹果/安卓/wp
积分 436, 距离下一级还需 14 积分
权限: 自定义头衔, 签名中使用图片
道具: 彩虹炫, 涂鸦板, 雷达卡, 热点灯, 金钱卡, 显身卡, 匿名卡下一级可获得
道具: 抢沙发
购买后可立即获得
权限: 隐身
道具: 金钱卡, 彩虹炫, 雷达卡, 热点灯, 涂鸦板
R过程及结果:
& a &- c(22,212,57,4,5,1,5)
& b &- c(5,54,2,5,5,5,58,8)
& t.test(a,b,var.equal=T,alternative=&less&)
& && &&&Two Sample t-test
data:&&a and b
t = 0.9125, df = 13, p-value = 0.8109
alternative hypothesis: true difference in means is less than 0
95 percent confidence interval:
& &&&-Inf 76.35499
sample estimates:
mean of x mean of y
& && && && && && && && && && && && && && && && &&&SAS 系统& && && && & 日 星期五 下午02时43分08秒& &6
& && && && && && && && && && && && && && && && & The TTEST Procedure
& && && && && && && && && && && && && && && && &&&Variable:&&a&&(a)
& && && && && && && &h& && && && &&&N& && &&&Mean& &&&Std Dev& &&&Std Err& &&&Minimum& &&&Maximum
& && && && && && && &0& && && && &&&8& &&&17.7500& &&&23.6869& && &8.3746& && &2.0000& &&&58.0000
& && && && && && && &1& && && && &&&7& &&&43.7143& &&&76.7761& &&&29.0186& && &1.0000& && & 212.0
& && && && && && && &Diff (1-2)& && && & -25.9643& &&&54.9790& &&&28.4543
& && && && &h& && && && & Method& && && && && &Mean& && & 95% CL Mean& && &&&Std Dev& && &95% CL Std Dev
& && && && &0& && && && && && && && && && & 17.7500& &&&-2.8& &&&23.6869& &&&15.4
& && && && &1& && && && && && && && && && & 43.7143& & -27.2918& & 114.7& &&&76.7761& &&&49.4740& & 169.1
& && && && &Diff (1-2)& & Pooled& && && &&&-25.9643& & -87.5& &&&54.9790& &&&39.4
& && && && &Diff (1-2)& & Satterthwaite& & -25.9643& & -97.4
& && && && && && && && && &&&Method& && && &&&Variances& && &&&DF& & t Value& & Pr & |t|
& && && && && && && && && &&&Pooled& && && &&&Equal& && && && &13& && &-0.91& && &0.3781
& && && && && && && && && &&&Satterthwaite& & Unequal& && &6.9994& && &-0.86& && &0.4184
& && && && && && && && && && && && && && && && &Equality of Variances
& && && && && && && && && && && & Method& && &Num DF& & Den DF& & F Value& & Pr & F
& && && && && && && && && && && & Folded F& && && &6& && && &7& && &10.51& & 0.0066
& & & & & & & & & & & & & & & & & & & & 独立样本检验
& & & & & & & & 方差方程的 Levene 检验& & & & & & & & & & & & & & & & & & & & 均值方程的 t 检验
& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & 差分的 95% 置信区间
& & & & & & & & F& & & & Sig.& & & & t& & & & df& & & & Sig.(双侧)& & & & 均值差值& & & & 标准误差值& & & & 下限& & & & 上限
a& & & & 假设方差相等& & & & 2.970& & & & .109& & & & .912& & & & 13& & & & .378& & & & 25.964& & & & 28.454& & & & -35.508& & & & 87.436
& & & & 假设方差不相等& & & & & & & & & & & & .860& & & & 6.999& & & & .418& & & & 25.964& & & & 30.203& & & & -45.455& & & & 97.384
SAS和SPSS结果一直,两者与R结果不一致,请较专家,谢谢!
备择假设不一样
热心帮助其他会员
总评分:&论坛币 + 20&
个人主页,欢迎订阅http://chenangliu.info/
求证1加1 发表于
备择假设不一样谢谢!能否再讲详细些?比如,R的备择假设是什么?SAS、SPSS的是什么?谢谢!
panxinfeng 发表于
谢谢!能否再讲详细些?比如,R的备择假设是什么?SAS、SPSS的是什么?谢谢!alternative=&less&
你自己设置的咯
个人主页,欢迎订阅http://chenangliu.info/
不好意思!我是初学,从网上找来模仿的,又学到新东西了,多谢啦!
初级热心勋章
初级热心勋章
初级信用勋章
初级信用勋章
中级热心勋章
中级热心勋章
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
&nbsp&nbsp|
如有投资本站或合作意向,请联系(010-);
邮箱:service@pinggu.org
投诉或不良信息处理:(010-)
论坛法律顾问:王进律师数据挖掘专题 | 用R怎么做T检验
我的图书馆
数据挖掘专题 | 用R怎么做T检验
### T检验统计基础http://www.sthda.com/english/wiki/t-test-formulaProbably one of the most popular research questions is whether&two independent samples&differ from each other.&Student’s t test&is one of the common&statistical test&used for comparing the means of&two independent&or&paired samples.### 测试数据data =&read.csv('https://stats.idre.ucla.edu/stat/data/hsb2.csv')###&测试需求1:ses=1与ses=2时,write变量是否具有显著差异http://www.cookbook-r.com/Statistical_analysis/t-test/关于var.equal参数:【设置数据是否是齐方差】By default,&t.test&does&not&assume equal variances, it uses the Welch t-test by default. Note that in the Welch t-test, df=88.466, because of the adjustment for unequal variances. To use Student’s t-test, set&var.equal=TRUE.### 测试需求2:不同ses水平(取值1,2,3)之间,write变量是否具有显著差异ANOVA分析结果如下:如图所示,不同ses组之间,write变量具有显著差异,但是该差异显著性主要是由谁贡献的,两两ses组之间的write是否具有显著差异呢?事后多重比较:post-hoc analysishttps://stats.idre.ucla.edu/r/faq/how-can-i-do-post-hoc-pairwise-comparisons-in-r/After an ANOVA, you may know that the means of your response variable differ significantly across your factor, but you do not know which pairs of the factor levels are significantly different from each other.& At this point, you can conduct pairwise comparisons.###&pairwise分析http://psych.wisc.edu/moore/Rpdf/610-R3_post-hoc_one-way_betw.pdfhttps://rtutorialseries.blogspot.com/2011/03/r-tutorial-series-anova-pairwise.html即两两比较分析,需要做三组(ses=1 vs.&ses=2;ses=1 vs.&ses=3;ses=2 vs.&ses=3)# 无矫正:pairwise.t.test 默认参数pool.sd&= T,与t.test中设置var.equal=T效果比较类似,但是很容易发现的一个问题是,对于ses为1和2之间的p值,在pairwise的计算中是0.4306,而在t.test中的计算结果是0.4279...在网上检索到相同问题:https://stat.ethz.ch/pipermail/r-help/2010-September/252267.htmlThe pool.sd&switch calculates a common SD for all groups, so the denominator is not the same as when testing each pair separately.解决办法如下:pairwise.t.test(data$write, data$ses,&p.adj='none',pool.sd=F,var.eq=T)此时,我们再看,pairwise的结果即与每个pair单独分析的结果一致!而如果只设置pool.sd=F时,结果则与t.test默认参数(Welch’s T-test)结果一致!To get separate standard deviation estimates instead of a pooled standard deviation, set the pool.sd=FALSE.This is unnecessary, since default is to assume homogeneity of variance. If that assumption weren’t true for your data, you could use pool.sd=F.# FDR矫正:因为涉及到多比较,所以就要考虑多重假设检验矫正,当然对于p值的矫正方法是多种多样的,如目前最常用的BH矫正、即FDR,矫正之后的p值普遍会增加:矫正结果与单独对p值使用p.adjust矫正结果一致:矫正方法在pairwise.t.test函数中使用p.adj参数即可进行限定,p.adj参数的可选值与p.adjust函数中内置的矫正方法一致:'holm', 'hochberg', 'hommel', 'bonferroni', 'BH', 'BY',&'fdr', 'none';#&TukeyHSD:Tukey’s test&is a single-step multiple comparison procedure and statistical test. It is a post-hoc analysis, what means that it is used in conjunction with an ANOVA.The Tukey Honest Significant Difference (HSD) method controls for the Type I error rate across multiple comparisons and is generally considered an acceptable technique.&diff&is the difference in means between the two groups,&lwr&is the lower estimate of the 95% confidence interval of the difference in means,&upr&is the upper estimate of the same 95% confidence interval, and&p adj&is the significance of the test after correcting for family-wise error rate.&The adjustment of the p-value is necessary in controlling for Type 1 error inflation.#&针对多组中的两组比较,T检验的结果可信还是TukeyHSD中的结果可信?https://www.researchgate.net/post/What_is_the_difference_between_Tukeys_Post_Hoc_Test_and_Students_t-testhttps://stats.stackexchange.com/questions/61732/two-sample-t-test-vs-tukeys-method建议是:TukeyHSD【考虑全部数据,矫正】# 各种方法比较www.ijsmi.com/Journal/index.php/IJSMI/article/download/1/pdfhttps://www.stata.com/meeting/chicago16/slides/chicago16_ender.pdf### 总结一下对于两组数据的Welch’s T-test,使用t.test函数,默认参数;对于两组数据的Student’s T-test,使用t.test函数,加参数var.equal=T;对于两两组间的差异分析,使用TukeyHSD比较方便。### 延伸http://www.sthda.com/english/wiki/print.php?id=94多数情况下(就像上面说的一大堆一样),我们在做的分析的时候都是默认数据服从正态分布、齐方差,所以不管三七二十一上来就用Student’s T-test,由此带来的问题是,使用不适合的统计方法得到的结论可能是有偏倚甚至是错误的。Statistical errors&are common in scientific literature, and about 50% of the published articles have at least one error. Many of the statistical procedures including correlation, regression,&t test, and analysis of variance assume that the data are&normally distributed.对于本次测试数据:由图可见,ses=1组的write变量近似服从正态分布(Shapiro test p-value > 0.05),但是ses=2组的数据并不服从正态分布!所以针对不同的数据,要找到更适合的分析方法,不能盲目
TA的最新馆藏
喜欢该文的人也喜欢}

我要回帖

更多关于 均值的标准误 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信