# Total least squares with weights [duplicate]

I am looking for a way to perform weighted total least squares in R. I know one can use PCA for this as described nicely in the following post. How to perform orthogonal regression (total least squares) via PCA?

However, I need a weighted version of total least squares, i.e. I want to account for measurement error in my data, where the error $(\Delta x_i, \Delta y_i)$ can be different for each data point $(x_i, y_i)$. Any suggestions? Specifically, I want to do the following:

x = rnorm(10,0,2)
x.se = rnorm(10,0,0.7)
y = 20*x
y.se = rnorm(10,0,1)
r <- prcomp( ~ x + y )
slope <- r$rotation[2,1] / r$rotation[1,1]
intercept <- r$center[2] - slope*r$center[1]


However, here I am not accounting for the varying measurement errors in $x$ and $y$. Is there any R package which I can use to account for the x.se and y.se vectors?

• Yes, I mean error in x is not equal to error in y. I agree this is not weighted PCA but really weighted TLS - where you can include the standard error in the variables as weights. – user19758 Oct 26 '15 at 17:30
• Yes, there is a package for Deming regression in R. However, Deming regression assumes that the standard error is uniform across all points or one can enter the ratio of the variances of $x$ and $y$. But I would like to explicitly include the $x.se$ and $y.se$. – user19758 Oct 28 '15 at 13:11

## 1 Answer

I've been looking for the same thing. I see that Deming regression offered in the mcr package only allows a ratio of $x$ and $y$ variances to be specified (as you say), but it looks like the deming package allows you to specify vectors for xstd and ystd - is this not what you need?

• +1, from the description of the deming function in the deming package cran.r-project.org/web/packages/deming/deming.pdf it does look like it can work with variable error values for each data point. – amoeba Oct 31 '15 at 14:07
• Yes, thanks for pointing that out. I also found this. Do you have any suggestions on what are the most appropriate weights to use? If I use x.se and y.se as the weights -I get very strange results and a very poor fit. But I guess one should use the ratio of variances (so 1/x.se^2) as the weights. Which in my case becomes very sensitive to outliers in the data and the confidence interval is very large. – user19758 Oct 31 '15 at 22:34