Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8487867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:22:21+00:00 2026-06-10T21:22:21+00:00

Given two random variables/measurements ( x , y ), both measured with error (error-in-variables

  • 0

Given two random variables/measurements (x, y), both measured with error (error-in-variables case),
is there a routine in MATLAB to calculate the estimators (a, b) of a regression line y(i)=a·x(i)+b using the method of orthogonal distance regression?

Here’s my implementation of Maximum Likelihood estimator:

x= [1.0, 0.6, 1.2, 1.4, 0.2];
y=[0.5, 0.3, 0.7, 1.0, 0.2];

mx = mean(x);
my = mean(y);
p = (x(:) - mx) .^ 2;
q = (y(:) - mx) .^ 2;
w = p .* q;
sxx = sum(p);
syy = sum(q);
sxy = sum(w);    w=p.*q;   sxy=sum(w);

l = 1;  %# orthogonal distance regression
a = (syy - l * syy + sqrt((syy - l * sxx) ^ 2 + 4 * l * sxy^2)) / (2 * sxy);
b = my - a * mx;

EDIT (addressed to EitanT):

Here’s a comparison of my estimators and yours:

comparison

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T21:22:23+00:00Added an answer on June 10, 2026 at 9:22 pm

    MATLAB doesn’t have a built-in function exactly like that, but you can easily find the estimators a and b with svd approximation1,2:

    data = [x(:), y(:)];
    [U, S, V] = svd(data - repmat(mean(data), size(data, 1), 1), 0);
    a = -V(1, end) / V(2, end);
    b = mean(data * V(:, end)) / V(2, end);
    

    Which is in fact the orthogonal distance regression method.

    EDIT #1:
    Here’s a plot of the original data, alongside my estimator and yours.

    comparison

    Your estimator is highly inaccurate, which brings me to believe that that your implementation is flawed.

    EDIT #2:

    Here’s an updated plot if the computation of a is corrected to:

    a=(syy-l*syy+sqrt((syy-l*sxx)^2+4*l*sxy^2)) / (2*sxy);  %# Forgot parentheses!
    

    enter image description here

    Closer, but still not as accurate as mine.

    EDIT #1:

    You can further improve the accuracy of sxx, syy and sxy, like so:

    cov_mat = cov(x, y);
    sxx = cov_mat(1, 1);  %# Same as: sxx = var(x);
    syy = cov_mat(2, 2);  %# Same as: syy = var(y);
    sxy = cov_mat(1, 2);  %# Same as: sxy = cov_mat(2, 1);
    

    1 Gene H. Golub and Charles F. Van Loan (1996) “Matrix Computations” (3rd ed.). The Johns Hopkins University Press. pp 596.
    2 http://en.wikipedia.org/wiki/Total_least_squares

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given two arrays, how to find the maximum element which is common to both
Given two dates, what is the best method to calculate the number of days
I have two scripts which both generate random forests in R , which as
I wrote method that return random number between two given numbers. Here it's header:
Given two random integer generators one that generates between 1 and 7 and another
I would like to know how to generate a random number between two given
Given two data frames: C1<-c(3,4,4,4,5) C2<-c(3,7,3,4,5) C3<-c(5,6,3,7,4) DF<-data.frame(C1=C1,C2=C2,C3=C3) DF C1 C2 C3 1 3
Given two tuples of the same arity, how can I lexicographically compare them? It
Given two sorted arrays of integers, a and b , and an integer c
Given two strings text1 and text2 : public SOMEUSABLERETURNTYPE Compare(string text1, string text2) {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.