Clear Filters
Clear Filters

Error in Variables Regression

6 views (last 30 days)
Hi. I'd like to perform a multilinear Error-in-Variables Regression, i.e. I have uncertainty in the predictors as well as in the dependent variable. This is sometimes also named Total Least Squares Regression. To my surprise, this is not part of the standard matlab functions as far as I can tell. Does anyone know if I missed something or if this (rather basic functionality I would say) is indeed not included with Matlab?

Accepted Answer

Torsten
Torsten on 2 Sep 2023
Edited: Torsten on 2 Sep 2023
Linear Total Least Squares Regression means minimizing the sum of distances of projections of your data on a linear subspace. This is usually accomplished by using "svd".
If you don't want to adapt "svd" according to your need, you can try the followig package:
  3 Comments
Fabrice Lambert
Fabrice Lambert on 4 Sep 2023
Edited: Fabrice Lambert on 4 Sep 2023
Thanks.
I modified his code to make it a bit more flexible in terms of dimensions in case anyone's interested.
function [Crit_TLS, ThetaEstimTLS] = tls(Pred,Crit,Predstd,Critstd)
%tls Total Least Squares Regression
% Pred: Predictors in column form
% Crit: Criterions in column form
% Predstd: standard deviation of Predictors, horizontal vector
% Critstd: standard deviation of Criterions, horizontal vector.
% Modified from Antonio Sala Piqueras, Universitat Politècnica de València.
if size(Pred,1) ~= size(Crit,1)
error('X and Y must have the same number of rows')
end
Crit_N = size(Crit,2);
Pred_N = size(Pred,2);
Crit_std = diag(Critstd);
Pred_std = diag(Predstd);
Crit_scaled = (Crit-mean(Crit)) / Crit_std; % scale to mean zero (data) and unit variance (noise)
Pred_scaled = (Pred-mean(Pred)) / Pred_std; % scale to mean zero (data) and unit variance (noise)
Data_scaled=[Crit_scaled Pred_scaled];
[N,~]=size(Data_scaled);
[~,~,V]=svd(Data_scaled / sqrt(N-1),'econ'); %TLS and SVD are the same with the proposed scaling.
Model_scaled = V(:,Pred_N+1:end);
ModPred_sc = Model_scaled(end-Pred_N+1:end,:);
ModCrit_sc = Model_scaled(1:Crit_N,:);
ModCrit = Crit_std \ ModCrit_sc;
ModPred = Pred_std \ ModPred_sc;
ThetaEstimTLS = -ModPred / ModCrit;
Crit_TLS = Pred * ThetaEstimTLS;
end

Sign in to comment.

More Answers (0)

Categories

Find more on Descriptive Statistics in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!