Effacer les filtres
Effacer les filtres

Error in Variables Regression

6 vues (au cours des 30 derniers jours)
Fabrice Lambert
Fabrice Lambert le 1 Sep 2023
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?

Réponse acceptée

Torsten
Torsten le 2 Sep 2023
Modifié(e) : Torsten le 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 commentaires
Torsten
Torsten le 2 Sep 2023
Fabrice Lambert
Fabrice Lambert le 4 Sep 2023
Modifié(e) : Fabrice Lambert le 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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Descriptive Statistics dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by