Method ao/linfit


  LINFIT is a linear fitting tool
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
  DESCRIPTION: LINFIT is a linear fitting tool based on MATLAB's
  lscov function. It solves an equation in the form
 
      Y = P(1) + X * P(2)
 
  for the fit parameters P.
  The output is a pest object where the fields are containing:
  Quantity                              % Field
  Fit parameters                            y
  Uncertainties on the fit parameters
  (given as standard deviations)            dy
  The reduced CHI2 of the fit              chi2
  The covariance matrix                    cov
  The degrees of freedom of the fit        dof
 
  CALL:       P = linfit(X, Y, PL)
              P = linfit(A, PL)
 
  INPUTS:     Y   - dependent variable
              X   - input variable
              A   - data ao whose x and y fields are used in the fit
              PL  - parameter list
 
  OUTPUT:     P   - a pest object with the fitting coefficients
 
 
  PARAMETERS:
     'dy' - uncertainty on the dependent variable
     'dx' - uncertainties on the input variable
     'p0' - initial guess on the fit parameters used ONLY to propagate
            uncertainities in the input variable X to the dependent variable Y
 
  Parameters Description
 
  EXAMPLES:
 
   %% Make fake AO from polyval
    nsecs = 100;
    fs    = 10;
 
    u1 = unit('fm s^-2');
    u2 = unit('nT');
 
    pl1 = plist('nsecs', nsecs, 'fs', fs, ...
      'tsfcn', 'polyval([10 1], t) + randn(size(t))', ...
      'xunits', 's', 'yunits', u1);
 
    pl2 = plist('nsecs', nsecs, 'fs', fs, ...
      'tsfcn', 'polyval([-5 0.2], t) + randn(size(t))', ...
      'xunits', 's', 'yunits', u2);
 
    a1 = ao(pl1);
    a2 = ao(pl2);
 
   %% 1) Determine dependance from time of a time-series
   %% Fit a stright line the a1 dependance from time
    p1 = linfit(a1, plist());
    p2 = linfit(a1, plist('dx', 0.1*ones(size(a1.x)), 'dy', 0.1*ones(size(a1.y)), 'P0', ao([0 0])));
    p3 = linfit(a1, plist('dx', ao(0.1, plist('yunits', a1.xunits)), 'dy', ao(0.1, plist('yunits', a1.yunits)), 'P0', p1));
 
   %% Compute fit: evaluating pest
 
    b1 = p1.eval(plist('type', 'tsdata', 'XData', a1, 'xfield', 'x'));
    b2 = p2.eval(plist('type', 'tsdata', 'XData', a1.x));
    b3 = p3.eval(plist('type', 'tsdata', 'XData', a1.x));
 
   %% Plot fit
    iplot(a1, b1, b2, b3, plist('LineStyles', {'', '--', ':', '-.'}));
 
   %% Remove linear trend
    c = a1 - b1;
    iplot(c)
 
   %% 2) Determine dependance of a time-series from another time-series
   %% Fit with a straight line the a1 dependance from a2
 
    p1 = linfit(a1, a2, plist());
    p2 = linfit(a1, a2, plist('dx', 0.1*ones(size(a1.x)), 'dy', 0.1*ones(size(a1.x)), 'P0', ao([0 0])));
    p3 = linfit(a1, a2, plist('dx', ao(0.1, plist('yunits', a1.yunits)), 'dy', ao(0.1, plist('yunits', a2.yunits)), 'P0', p1));
 
   %% Compute fit: evaluating pest
 
    b1 = p1.eval(plist('type', 'xydata', 'XData', a1.y, 'xunits', a1.yunits));
    b2 = p2.eval(plist('type', 'xydata', 'XData', a1));
    b3 = p3.eval(plist('type', 'xydata', 'XData', a1.y, 'xunits', a1.yunits));
 
   %% Build reference object
    a12 = ao(plist('xvals', a1.y, 'yvals', a2.y, ...
      'xunits', a1.yunits, 'yunits', a2.yunits));
 
   %% Plot fit
    iplot(a12, b1, b2, b3, plist('LineStyles', {'', '--', ':', '-.'}));
 
    %% Remove linear trend
    c = a12 - b3;
    iplot(c)
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Method Details
Access public
Defining Class ao
Sealed 0
Static 0

Parameter Description

Default

no description
Key Default Value Options Description
linfit
DY [] none Uncertainty on Y. Can be expressed as
  • an AO with single value or
  • an AO with a vector of the right length or
  • a double or
  • an array of double of the right length
DX [] none Uncertainty on X(1..N). Can be expressed as
  • an AO with single value or
  • an AO with a vector of the right length or
  • a double or
  • an array of double of the right length
P0 [] none Initial guess of the fit parameters. Can be expressed as:
  • an AOs with a vector
  • an array of scalars or
  • a pest object

Example

plist('DY', [[]], 'DX', [[]], 'P0', [[]])

back to top back to top

Some information of the method ao/linfit are listed below:
Class name ao
Method name linfit
Category Signal Processing
Package name ltpda
VCS Version 967b0eec0dece803a81af8ef54ad2f8c784b20b2
Min input args 1
Max input args -1
Min output args 1
Max output args -1
Can be used as modifier 0
Supported numeric types {'double'}




©LTP Team