Error in Variables Regression

6 次查看(过去 30 天)
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?

采纳的回答

Torsten
Torsten 2023-9-2
编辑:Torsten 2023-9-2
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 个评论
Fabrice Lambert
Fabrice Lambert 2023-9-4
编辑:Fabrice Lambert 2023-9-4
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Descriptive Statistics 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by