Confidence interval for orthogonal regression
I have not found a method to estimate confidence interval of orthogonal regression. Then I build one using bootstrap.
OrthogonalRegression <- function(x, y) {
library("pracma")
xnew <- seq(from=min(x), to=max(x), length.out = 100)
replicate <- 1000
m <- matrix(data=NA, nrow=replicate, ncol=length(xnew))
c <- NULL
d <- NULL
odrx <- odregress(x, y)
for (r in 1:replicate) {
s <- sample(1:length(x), length(x), replace = TRUE)
odr <- odregress(x[s], y[s])
cc <- odr$coeff
c <- c(c, cc[1])
d <- c(d, cc[2])
# Prediction
ynew <- cbind(xnew, 1) %*% cc
m[r, ] <- ynew
}
q <- apply(m, MARGIN=2, FUN=quantile, probs=c(0.025, 0.5, 0.975))
q <- rbind(q, x=xnew)
qb <- quantile(c, probs=c(0.025, 0.5, 0.975))
qa <- quantile(d, probs=c(0.025, 0.5, 0.975))
return(list(model=odrx,
values=q,
intercept=qa,
slope=qb))
}
x <- runif(100, min=10, max=20)
y <- runif(100, min=5, max=15)+x
or <- OrthogonalRegression(x, y)
plot(x, y, bty="n", las=1)
par(xpd=FALSE)
lines(or$values["x", ], or$values["50%", ])
lines(or$values["x", ], or$values["2.5%", ], lty=2)
lines(or$values["x", ], or$values["97.5%", ], lty=2)
abline(a=or$intercept[1], b=or$slope[3], col="red")
abline(a=or$intercept[3], b=or$slope[1], col="red")
OrthogonalRegression <- function(x, y) {
library("pracma")
xnew <- seq(from=min(x), to=max(x), length.out = 100)
replicate <- 1000
m <- matrix(data=NA, nrow=replicate, ncol=length(xnew))
c <- NULL
d <- NULL
odrx <- odregress(x, y)
for (r in 1:replicate) {
s <- sample(1:length(x), length(x), replace = TRUE)
odr <- odregress(x[s], y[s])
cc <- odr$coeff
c <- c(c, cc[1])
d <- c(d, cc[2])
# Prediction
ynew <- cbind(xnew, 1) %*% cc
m[r, ] <- ynew
}
q <- apply(m, MARGIN=2, FUN=quantile, probs=c(0.025, 0.5, 0.975))
q <- rbind(q, x=xnew)
qb <- quantile(c, probs=c(0.025, 0.5, 0.975))
qa <- quantile(d, probs=c(0.025, 0.5, 0.975))
return(list(model=odrx,
values=q,
intercept=qa,
slope=qb))
}
x <- runif(100, min=10, max=20)
y <- runif(100, min=5, max=15)+x
or <- OrthogonalRegression(x, y)
plot(x, y, bty="n", las=1)
par(xpd=FALSE)
lines(or$values["x", ], or$values["50%", ])
lines(or$values["x", ], or$values["2.5%", ], lty=2)
lines(or$values["x", ], or$values["97.5%", ], lty=2)
abline(a=or$intercept[1], b=or$slope[3], col="red")
abline(a=or$intercept[3], b=or$slope[1], col="red")
Commentaires
Enregistrer un commentaire