R中斜率系数的推论
默认情况下lm
汇总测试斜率系数等于0。我的问题非常基本。我想知道如何测试斜率系数等于非零值。一种方法是使用confint,但这不提供p值。我还想知道如何使用 lm 进行单方面测试。
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group <- gl(2,10,20, labels=c("Ctl","Trt"))
weight <- c(ctl, trt)
lm.D9 <- lm(weight ~ group)
summary(lm.D9)
Call:
lm(formula = weight ~ group)
Residuals:
Min 1Q Median 3Q Max
-1.0710 -0.4938 0.0685 0.2462 1.3690
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 5.0320 0.2202 22.850 9.55e-15 ***
groupTrt -0.3710 0.3114 -1.191 0.249
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.6964 on 18 degrees of freedom
Multiple R-squared: 0.07308, Adjusted R-squared: 0.02158
F-statistic: 1.419 on 1 and 18 DF, p-value: 0.249
confint(lm.D9)
2.5 % 97.5 %
(Intercept) 4.56934 5.4946602
groupTrt -1.02530 0.2833003
感谢您的时间和精力。
By default lm
summary test slope coefficient equal to zero. My question is very basic. I want to know how to test slope coefficient equal to non-zero value. One approach could be to use confint
but this does not provide p-value. I also wonder how to do one-sided test with lm
.
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group <- gl(2,10,20, labels=c("Ctl","Trt"))
weight <- c(ctl, trt)
lm.D9 <- lm(weight ~ group)
summary(lm.D9)
Call:
lm(formula = weight ~ group)
Residuals:
Min 1Q Median 3Q Max
-1.0710 -0.4938 0.0685 0.2462 1.3690
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 5.0320 0.2202 22.850 9.55e-15 ***
groupTrt -0.3710 0.3114 -1.191 0.249
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.6964 on 18 degrees of freedom
Multiple R-squared: 0.07308, Adjusted R-squared: 0.02158
F-statistic: 1.419 on 1 and 18 DF, p-value: 0.249
confint(lm.D9)
2.5 % 97.5 %
(Intercept) 4.56934 5.4946602
groupTrt -1.02530 0.2833003
Thanks for your time and effort.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
除了所有其他好的答案之外,您还可以使用偏移量。分类预测变量有点棘手,因为您需要知道编码。
这里的
1*
是不必要的,但放入它是为了强调您正在测试差异为 1 的假设(如果您想测试差异为d
的假设)代码>,然后使用d*(group=="Trt")
In addition to all the other good answers, you could use an offset. It's a little trickier with categorical predictors, because you need to know the coding.
The
1*
here is unnecessary but is put in to emphasize that you are testing against the hypothesis that the difference is 1 (if you want to test against a hypothesis of a difference ofd
, then used*(group=="Trt")
您可以使用
t.test
对您的数据执行此操作。mu
参数设置组均值差异的假设。alternative
参数可让您在单侧测试和两侧测试之间进行选择。You can use
t.test
to do this for your data. Themu
parameter sets the hypothesis for the difference of group means. Thealternative
parameter lets you choose between one and two-sided tests.编写您自己的测试代码。您知道估计系数并且知道标准误差。您可以构建自己的测试统计数据。
Code up your own test. You know the estimated coeffiecient and you know the standard error. You could construct your own test stat.
正如@power所说,你可以用手做。
这是一个示例:
您可以通过省略
2*
进行单面测试。更新
这里是双边和单边概率的示例:
请注意,上限概率和下限概率之和恰好为 1。
as @power says, you can do by your hand.
here is an example:
and you can do one-side test by omitting
2*
.UPDATES
here is an example of two-side and one-side probability:
note that sum of upper and lower probabilities is exactly 1.
使用
car
包中的linearHypothesis
函数。例如,您可以使用以下命令检查groupTrt
的系数是否等于-1。Use the
linearHypothesis
function fromcar
package. For instance, you can check if the coefficient ofgroupTrt
equals -1 using.smatr 包有一个
slope.test()
函数,您可以通过它使用 OLS。The smatr package has a
slope.test()
function with which you can use OLS.