# KeepNotes blog

Stay hungry, Stay Foolish.

0%

#### Fitting a Line to Scatter Plots

The default assumption is trying to demonstrate exact concordance(identity) between both measurement procedures

##### 3. Maxed Variability (Standard Deviation and Coefficient of Variation)

Deming和Passing-Bablok方法均可用于混合变化的回归分析。

##### 6. Comfidence Intervals

Deming回归的CI建议使用Jackknife方法，Passing-Bablok回归的CI建议使用bootstrap方法计算

#### Deming and Passing Bablok Regression in R

Deming回归的基本思想也是指定x和y，建立x对y的回归方程。但在计算回归系数的时候思路不同。线性回归中，回归系数的计算是基于y的残差最小，也就是最小二乘回归回归；而在Deming回归中，同时考虑x的残差最小和y的残差最小。

Passing-Bablok回归的思路其实也不难，相当于把任意的两个点，计算其斜率，这样能计算出很多斜率。比如一共4个点，就能计算出6个斜率，然后取6个斜率的中位数，这就是Passing-Bablok回归的斜率估计值

``````set.seed(20)
x <- runif(100,0,100)
y <- 1.10*x - 0.001*x^2 + rnorm(100,0,1)*(2 + 0.05*x) + 15

library(mcr)
dem.reg <- mcreg(x,y, method.reg = "Deming", alpha=0.05, method.ci="jackknife")
printSummary(dem.reg)
> dem.reg@para
EST        SE        LCI      UCI
Intercept 0.3909254 1.8467746 -3.8677445 4.649595
Slope     0.9422886 0.2028027  0.4746247 1.409952``````

``````w.dem.reg <- mcreg(x,y, method.reg = "WDeming", alpha=0.05, ,method.ci="jackknife")
w.dem.reg@para``````

``````PB.reg <- mcreg(x,y, method.reg = "PaBa", alpha = 0.05, method.ci = "bootstrap")
PB.reg@para``````

• The variables X and Y are highly, positively correlated (for method comparison only).
• The relationship between X and Y is linear (straight-line).
• No special assumptions are made about the distributions (including the variances) of X and Y.

Passing and Bablok (1983) proposed testing this assumption using a modified cusum test.

``````PB.reg <- mcreg(x,y, method.reg = "PaBa", alpha = 0.05,
res <- calcCUSUM(PB.reg)``````

``````pkstwo <- function(x, tol = 1e-06) {
if (is.numeric(x))
x <- as.double(x)
else stop("argument 'x' must be numeric")
p <- rep(0, length(x))
p[is.na(x)] <- NA
IND <- which(!is.na(x) & (x > 0))
if (length(IND))
p[IND] <- .Call(stats:::C_pKS2, p = x[IND], tol)
p
}``````

``````h <- res\$max.cusum / sqrt(res\$nNeg + 1)
pvalue <- 1 - pkstwo(x = h)
> pvalue
[1] 0.5175508``````