问题描述
我想测试简单线性回归中的斜率是否等于给定的常数,而不是零.
I want to test if the slope in a simple linear regression is equal to a given constant other than zero.
> x <- c(1,2,3,4)
> y <- c(2,5,8,13)
> fit <- lm(y ~ x)
> summary(fit)
Call:
lm(formula = y ~ x)
Residuals:
1 2 3 4
0.4 -0.2 -0.8 0.6
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -2.0000 0.9487 -2.108 0.16955
x 3.6000 0.3464 10.392 0.00913 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.7746 on 2 degrees of freedom
Multiple R-squared: 0.9818, Adjusted R-squared: 0.9727
F-statistic: 108 on 1 and 2 DF, p-value: 0.009133
> confint(fit)
2.5 % 97.5 %
(Intercept) -6.081855 2.081855
x 2.109517 5.090483
在此示例中,我想测试斜率是否等于5.我知道我不会拒绝它,因为5在95%CI中.但是有没有可以直接给我p值的函数?
In this example, I want to test if the slope is equal to 5. I know I won't reject it since 5 is in the 95% CI. But is there a function which can give me the p-value directly?
推荐答案
测试拟合是否与特定系数显着不同的一种方法是构建偏移",其中将该系数用作应用于系数的因数. x值.您应该将其视为至少将零斜率"重置为零".估计,拦截仍然是免费"的,可以四处走动".
One approach to testing whether a fit is significantly different than a particular coefficient is to construct an "offset" in which that coefficient is used as a factor applied to the x-value. You should think of this as re-setting the "zero" at least the zero-for-the-slope. The Intercept is still "free" to "move around", er, to be estimated.
fit2 <- lm( y~x +offset(5*x) )
#----------------
summary(fit2)
#--------
Call:
lm(formula = y ~ x + offset(5 * x))
Residuals:
1 2 3 4
0.4 -0.2 -0.8 0.6
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -2.0000 0.9487 -2.108 0.1695
x -1.4000 0.3464 -4.041 0.0561 .
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.7746 on 2 degrees of freedom
Multiple R-squared: 0.9818, Adjusted R-squared: 0.9727
F-statistic: 108 on 1 and 2 DF, p-value: 0.009133
现在将其与您的fit
对象的结果进行比较. x的系数恰好相差5.模型拟合统计量是相同的,但是您怀疑x
变量的p值要低得多,而要高得多,即不那么重要.
Now compare to the results from your fit
-object. The coefficients for x differ by exactly 5. The model fit statistics are the same, but as you suspected the p-value for the x
-variable is much lower ... er, higher, i.e. less significant.
> summary(fit)
Call:
lm(formula = y ~ x)
Residuals:
1 2 3 4
0.4 -0.2 -0.8 0.6
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -2.0000 0.9487 -2.108 0.16955
x 3.6000 0.3464 10.392 0.00913 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.7746 on 2 degrees of freedom
Multiple R-squared: 0.9818, Adjusted R-squared: 0.9727
F-statistic: 108 on 1 and 2 DF, p-value: 0.009133
这篇关于测试简单线性回归中的斜率是否等于R中的给定常数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!