Questions tagged [least-squares]

Refers to a general estimation technique that selects the parameter value to minimize the squared difference between two quantities, such as the observed value of a variable, and the expected value of that observation conditioned on the parameter value. Questions about the theory behind least-squares should utilize the Cross Validated (https://stats.stackexchange.com/questions) Stack Exchange site.

Overview

From the "Least squares" article on Wikipedia:

The method of least squares is a standard approach to the approximate solution of overdetermined systems, i.e., sets of equations in which there are more equations than unknowns. "Least squares" means that the overall solution minimizes the sum of the squares of the errors made in the results of every single equation.

Least squares problems fall into two categories: linear or ordinary least squares and non-linear least squares, depending on whether or not the residuals are linear in all unknowns. The linear least-squares problem occurs in statistical regression analysis; it has a closed-form solution. A closed-form solution (or closed-form expression) is any formula that can be evaluated in a finite number of standard operations. The non-linear problem has no closed-form solution and is usually solved by iterative refinement; at each iteration the system is approximated by a linear one, and thus the core calculation is similar in both cases.

Other References

Least squares methods are treated in many introductory statistics resources and textbooks, but there are also advanced resources dedicated only to the subject, for example:

Tag usage

Questions on should be about implementation and programming problems, not about the statistical or theoretical properties of the technique. Consider whether your question might be better suited to Cross Validated, the StackExchange site for statistics, machine learning and data analysis.

1013 questions
0
votes
1 answer

It Matlab, how do you mathematically get a quadratic line of best fit?

I'm having trouble getting a quadratic line of best fit in Matlab. We aren't aloud to use the built in line of best fit functions, but instead have to calculate it. This is what I have: dat = load('co2.dat'); x = dat(:,1); y=…
rphello101
  • 1,671
  • 5
  • 31
  • 59
0
votes
0 answers

least square minimisation in MATLAB

I'm trying to fit a curve in MATLAB to a data set I have and am trying to get a least squares minimisation. The curve is a convolution of a Gaussian and an exponential function so I've used a for loop, the curve has 5 variables. clip =…
0
votes
1 answer

Least-square fit with Google Script

I would like to solve a least-square optimization problem using Google Script. Is there a way to solve such mathematical optimization problems with Google Apps Script? Are there APIs or services to connect to that solve such much advanced math…
0
votes
0 answers

Python: 4-curve gaussian fitting with non-linear least-squares with multiple spectra

I'm using the top rated code from here and modified it to fit 4 gaussian gives for 3 spectra. The code works when I'm just doing working one spectra at a time but I want to automate the code so that I do curve fitting on multiple spectra. Here is…
user1821176
  • 1,141
  • 2
  • 18
  • 29
0
votes
0 answers

Implementation of a Least mean squares adaptive filter (LMS)

Designing an adaptive filter (example : LMS filter http://en.wikipedia.org/wiki/Least_mean_squares_filter) is highly technical and would need high skills in signal processing in order to code such a filter. Do you think there is somewhere a…
Basj
  • 41,386
  • 99
  • 383
  • 673
0
votes
0 answers

Segmented Least Squares and real world application

I've recently wrote a segmented least squares algorithm for a Java project I'm working on that involves the accelerometers in our smart phones. While nice an neat test data (like a sine wave) does well when I apply my algorithm, when I use data…
0
votes
1 answer

Different results when lm() is used vs. matrix multiplication formula

I am running a simple multivariate regression on a panel/time-series dataset, using lm() and the underlying formula $(X'X)^{-1} X'Y$ expecting to get the same coefficient values from the two methods. However, I get completely different…
Mayou
  • 8,498
  • 16
  • 59
  • 98
0
votes
0 answers

scipy leastsq gaussian fit won't work unless given an expectation value

I have some data which when I give the fit an expectation value it will correctly fit a gaussian to my data. If I don't give it the expectation value it draws a horizontal line across my data (fit hasn't worked). The reason why I want to get the…
user1958508
  • 605
  • 3
  • 7
  • 10
0
votes
0 answers

Supressing Octave leasqr CONVERGENCE NOT ACHIEVED message

I'm trying to fit a function using leasqr in Octave. This performs properly most of the time. Sometimes, however, leasqr fails to converge. (I'm not sure why, because the solution it comes up with looks fine). Untill I can figure out why it's not…
jessems
  • 1,582
  • 2
  • 11
  • 16
0
votes
2 answers

Convexity of function and its optimization

Is function convex in x and y jointly? I want is to estimate both parameter x and y, that minimizes the least square. If the function is convex in both x and y jointly, then technically I can find x and y by iterating between 2 steps: Find best x…
0
votes
3 answers

Multivar linear regression should be mathematically undetermined (Octave)

I apologize in advance for the rather abstract nature of my question, but it is indirectly a question about programming algorithms, and I don't think I'll be the only programmer to wonder about this. This is about the implementation of the…
0
votes
1 answer

least square optimization NOT CURVE FITTING

i'm dealing with a least squares(SCIPY) problem. usually a least sq problem has the X data and Y data given and the general form of the function is given such as linear/quadratic/log and based on the x and y data, we optimize the parameters of the…
0
votes
1 answer

SciPy LeastSq Failed to Provide Best Solution

I tried to use Leastsq to fit a very simple curve. However, its solutions are not optimized. Could anyone give me some suggestion? Below is my code: from scipy import optimize import numpy as np hl_obs = np.array([10.0, 23.0,…
TTT
  • 4,354
  • 13
  • 73
  • 123
0
votes
0 answers

Least squares with very large sparse matrix

What is the best function to obtain a least squares minimum solution from a linear problem like Ax = b in Octave, with A very large but sparse? x = A\b gives the error: SparseQR: sparse matrix QR factorization filled" that I don't understand.
andreaconsole
  • 430
  • 3
  • 17
0
votes
1 answer

Shape-matching of plots using non-linear least squares

What would b the best way to implement a simple shape-matching algorithm to match a plot interpolated from just 8 points (x, y) against a database of similar plots (> 12 000 entries), each plot having >100 nodes. The database has 6 categories of…
Natalia Zoń
  • 980
  • 2
  • 12
  • 22