如何测试线性回归模型斜率到 R 中的恒等线斜率

How to test a linear regression model slope to the identity line slope in R

x <- c(504.4058, 468.5829, 390.4110, 568.7277, 431.8638, 442.0493, 440.5432, 582.7658, 501.7017, 433.0584, 469.9929, 298.3949, 542.2075, 546.3904, 460.8759)
y <- c(608.0258, 540.5613, 442.7069, 495.3577, 474.0115, 460.9367, 472.2706, 605.1223, 549.1775, 397.4574, 402.2889, 352.1810, 606.1858, 617.0409, 559.2026)

mod1 <- lm(y ~ x, Data)

我用上面的数据创建了一个简单的线性回归模型。在这个模型中,估计值是针对 0 进行检验的。

我想测试斜率 (!) 对 1(标识线,其中 y=x)。这应该是单样本测试。这应该有助于检测我们模型中与身份线的系统偏差。

library(ggplot2)

x <- c(504.4058, 468.5829, 390.4110, 568.7277, 431.8638, 442.0493, 440.5432, 582.7658, 501.7017, 433.0584, 469.9929, 298.3949, 542.2075, 546.3904, 460.8759)
y <- c(608.0258, 540.5613, 442.7069, 495.3577, 474.0115, 460.9367, 472.2706, 605.1223, 549.1775, 397.4574, 402.2889, 352.1810, 606.1858, 617.0409, 559.2026)
qplot(x,y) + geom_abline(slope = 1)

看起来这些点遵循恒等函数:

qplot(x, y - x)

这可以改写为 y - x 的斜率为 0:

这可以通过多种方式进行测试:

lm(y - x ~ x) |> anova()
#> Analysis of Variance Table
#> 
#> Response: y - x
#>           Df Sum Sq Mean Sq F value Pr(>F)
#> x          1    617   617.3  0.2001  0.662
#> Residuals 13  40106  3085.1
lm(y ~ x + offset(x)) |> anova()
#> Analysis of Variance Table
#> 
#> Response: y
#>           Df Sum Sq Mean Sq F value Pr(>F)
#> x          1    617   617.3  0.2001  0.662
#> Residuals 13  40106  3085.1
lm(y ~ x) |> car::linearHypothesis("x = 1")
#> Linear hypothesis test
#> 
#> Hypothesis:
#> x = 1
#> 
#> Model 1: restricted model
#> Model 2: y ~ x
#> 
#>   Res.Df   RSS Df Sum of Sq      F Pr(>F)
#> 1     14 40723                           
#> 2     13 40106  1     617.3 0.2001  0.662

reprex package (v2.0.0)

创建于 2022-05-11