https://github.com/cran/pracma
Revision b5e4bf28fcba9f5eaffbeecfb0bc307452d074ee authored by Hans W. Borchers on 01 November 2014, 00:00:00 UTC, committed by Gabor Csardi on 01 November 2014, 00:00:00 UTC
1 parent d57c14d
Tip revision: b5e4bf28fcba9f5eaffbeecfb0bc307452d074ee authored by Hans W. Borchers on 01 November 2014, 00:00:00 UTC
version 1.7.7
version 1.7.7
Tip revision: b5e4bf2
odregress.R
##
## o d r l i n r e g . R Orthogonal Distance Regression
##
# Linear orthogonal distance regression method
odregress <- function(x, y) {
stopifnot(is.numeric(x), is.numeric(y))
Z <- cbind(x, y)
n <- nrow(Z) # no. of data points
m <- ncol(Z) - 1 # no. of independent variables
meanZ <- repmat(apply(Z, 2, mean), n, 1)
svdZ <- svd(Z - meanZ)
V <- svdZ$v
a <- -V[1:m, m+1] / V[m+1, m+1]
b <- mean(Z %*% V[, m+1]) / V[m+1, m+1]
# Fitted values
yfit <- cbind(x, 1) %*% c(a, b)
resd <- y - yfit
# orthogonal distance
normal <- V[, m+1]
err <- abs((Z - meanZ) %*% normal)
ssq <- sum(err^2)
return( list(coeff = c(a, b), ssq = ssq, err = err,
fitted = yfit, resid = resd, normal = normal) )
}
Computing file changes ...