tls: Weighted Total Least Square Regression.

Description Usage Arguments Value Author(s) References Examples

View source: R/wtls.R

Description

Weigthed total least square regression according to Golub and Van Loan (1980) in SIAM J.Numer.Anal Vol 17 No.6.

Usage

1
tls(formula, D = NULL, T = NULL, precision = .Machine$double.eps)

Arguments

formula

An object of class formula.

D

Diagonal weigth matrix. Default weights are set to 1.

T

Diagonal weigth matrix. Default weights are set to 1.

precision

Smallest possible numeric value on this machine (default).

Value

tls returns a lm object.

Author(s)

Sebastian Duemcke duemcke@lmb.uni-muenchen.de

References

Golub, G.H. and Van Loan, C.F. (1980). An analysis of the total least squares problem. SIAM J. Numer. Anal., 17:883-893.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
f = 1.5 # true ratio
a = rnorm(5000)
b = f*a
a = a + rnorm(5000,sd=0.5)
b = b + rnorm(5000,sd=0.5)

coeff.tls = coef(tls(b ~ a + 0))
coeff.lm1 = coef(lm(b ~ a + 0))
coeff.lm2 = 1/coef(lm(a ~ b + 0))

heatscatter(a,b)
abline(0,coeff.lm1,col="red",pch=19,lwd=2)
abline(0,coeff.lm2,col="orange",pch=19,lwd=2)
abline(0,coeff.tls,col="green",pch=19,lwd=2)
abline(0,f,col="grey",pch=19,lwd=2,lty=2)
legend("topleft", c("Least-squares regr. (y ~ x + 0)", "Least-squares regr. (x ~ y + 0)", "Total Least-squares regr.", "True ratio"), col=c("red", "orange", "green", "grey"), lty=c(1,1,1,2), lwd=2)

results = c(coeff.tls,coeff.lm1,coeff.lm2)
names(results) = c("coeff.tls","coeff.lm1","coeff.lm2")
print(results)

Example output

Loading required package: LSD
Warning message:
In model.matrix.default(mt, mf, contrasts) :
  non-list contrasts argument ignored
coeff.tls coeff.lm1 coeff.lm2 
 1.493489  1.188385  1.665393 

DTA documentation built on Nov. 8, 2020, 7:22 p.m.