本题中,在不含截距的简单线性回归中,用零假设对
统计量进行假设检验。首先,我们使用下面方法生成预测变量x和响应变量y。
            
            
              R
              
              
            
          
          set.seed(1)
x <- rnorm(100)
y <- 2*x+rnorm(100)(a)不含截距的线性回归模型构建。
(1)建立y关于x的不含截距项的简单线性回归。估计系数及其标准差、t 统计量和与零假设相关的p值。分析这些结果。
这里我们使用下面代码实现没有截距的简单线性回归。
            
            
              R
              
              
            
          
          lm(y~x+0)代码如下:
            
            
              R
              
              
            
          
          set.seed(1)
x = rnorm(100)
y = 2*x + rnorm(100)
lm.fit = lm(y~x+0)
summary(lm.fit)输出结果:
            
            
              R
              
              
            
          
          Call:
lm(formula = y ~ x + 0)
Residuals:
    Min      1Q  Median      3Q     Max 
-1.9154 -0.6472 -0.1771  0.5056  2.3109 
Coefficients:
  Estimate Std. Error t value Pr(>|t|)    
x   1.9939     0.1065   18.73   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.9586 on 99 degrees of freedom
Multiple R-squared:  0.7798,	Adjusted R-squared:  0.7776 
F-statistic: 350.7 on 1 and 99 DF,  p-value: < 2.2e-16由输出结果得出:
简单线性回归方程:
其中:
其中:t 统计量的 p 值接近于零,因此拒绝原假设。t 统计量的 p 值接近于零,因此拒绝原假设。
(b)参数估计。
(2)建立x关于y的不含截距项的简单线性回归。估计系数及其标准差、t 统计量和与零假设相关的p值。分析这些结果。
            
            
              R
              
              
            
          
          lm.fit = lm(x~y+0)
summary(lm.fit)输出结果:
            
            
              R
              
              
            
          
          Call:
lm(formula = x ~ y + 0)
Residuals:
    Min      1Q  Median      3Q     Max 
-0.8699 -0.2368  0.1030  0.2858  0.8938 
Coefficients:
  Estimate Std. Error t value Pr(>|t|)    
y  0.39111    0.02089   18.73   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.4246 on 99 degrees of freedom
Multiple R-squared:  0.7798,	Adjusted R-squared:  0.7776 
F-statistic: 350.7 on 1 and 99 DF,  p-value: < 2.2e-16由输出结果得出:
简单线性回归方程:
 
其中:
其中: t 统计量的 p 值接近于零,因此拒绝原假设。
(c)模型结果分析。
(3)(1)和(2)所得到的结果有什么关系?
 (1)和(2)的结果反映了同一个线性关系模型,
 和 
在一定程度上是等价的线性关系模型,他们的 t 值都等于 18.73。
(d)t 统计量检验证明。
(4)对于y对x的不含截距的简单线性回归,零假设: 的 t 统计量具有
的形式,其中
由下式给出,其中:
用代数的方法证明上面式子可以写成如下形式,并在R中进行确认。
证明:
R语言验证:
            
            
              R
              
              
            
          
          sqrt(length(x)-1) * sum(x*y)) / (sqrt(sum(x*x) * sum(y*y) - (sum(x*y))^2)
            
            
              R
              
              
            
          
          [1] 18.72593由输出结果得出:这与上面显示的 t 统计量相同。
(e)简单线性回归中y对x回归与x对y回归的 t 统计量相等。
(f2)无截距情况证明:
(5)用(4)的结果证明y对x回归与x对y回归的 t 统计量相等。
如果你把 t(x,y) 换成 t(y,x),那么你会发现 t(x,y) = t(y,x)。
(f2)有截距情况证明:
(6)在R中证明在截距的回归中,零假设: 的 t 统计量在y对x的回归中和x对y的回归中是一样的。
代码如下:
            
            
              R
              
              
            
          
          lm.fit = lm(y~x)
lm.fit2 = lm(x~y)
            
            
              R
              
              
            
          
          summary(lm.fit)输出:
            
            
              R
              
              
            
          
          Call:
lm(formula = y ~ x)
Residuals:
    Min      1Q  Median      3Q     Max 
-1.8768 -0.6138 -0.1395  0.5394  2.3462 
Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) -0.03769    0.09699  -0.389    0.698    
x            1.99894    0.10773  18.556   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.9628 on 98 degrees of freedom
Multiple R-squared:  0.7784,	Adjusted R-squared:  0.7762 
F-statistic: 344.3 on 1 and 98 DF,  p-value: < 2.2e-16
            
            
              R
              
              
            
          
          summary(lm.fit2)输出:
            
            
              R
              
              
            
          
          Call:
lm(formula = x ~ y)
Residuals:
     Min       1Q   Median       3Q      Max 
-0.90848 -0.28101  0.06274  0.24570  0.85736 
Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  0.03880    0.04266    0.91    0.365    
y            0.38942    0.02099   18.56   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.4249 on 98 degrees of freedom
Multiple R-squared:  0.7784,	Adjusted R-squared:  0.7762 
F-statistic: 344.3 on 1 and 98 DF,  p-value: < 2.2e-16由表格结果,零假设: 的 t 统计量在y对x的回归中为18.556,在x对y的回归中为18.556,说明在截距的回归中,零假设:
 的 t 统计量在y对x的回归中和x对y的回归中是一样的。