'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)
I have created a simple linear regression model with the data above. In this model, the estimates are tested against 0.
I am looking to test the slope (!) against 1 (identity line, where y=x). This should be with a one-sample ttest. This should help detect systematic deviation from the identity line in our model.
Solution 1:[1]
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)
Looks like the points follow the identity function:

qplot(x, y - x)
This can be rewritten as y - x has a slope of 0:

This can be tested using various ways:
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
Created on 2022-05-11 by the reprex package (v2.0.0)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | danlooo |
