![](/img/trans.png)
[英]How to calculate the 95% confidence interval for the slope in a linear regression model in 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 包於 2022-05-11 創建 (v2.0.0)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.