Module pyqt_fit.plot_fit — PyQt-Fit 1.3.1 documentation

### Navigation

- index
- modules |
- next |
- previous |
- PyQt-Fit 1.3.1 documentation »
- Modules of PyQt-Fit »

\[\DeclareMathOperator{\erf}{erf} \DeclareMathOperator{\argmin}{argmin} \newcommand{\R}{\mathbb{R}} \newcommand{\n}{\boldsymbol{n}}\]

# Module `pyqt_fit.plot_fit`

Author: | Pierre Barbier de Reuille <pierre.barbierdereuille@gmail.com>

This modules implement functions to test and plot parametric regression.

## Analyses of the residuals

`pyqt_fit.plot_fit.` `fit_evaluation`(fit, xdata, ydata, eval_points=None, CI=(), CIresults=None, xname='X', yname='Y', fct_desc=None, param_names=(), residuals=None, res_name='Standard')

  This function takes the output of a curve fitting experiment and store all the relevant information for evaluating its success in the result.

  Parameters: | fit (fitting object) – object configured for the fitting xdata (ndarray of shape (N,) or (k,N) for function with k prefictors) – The independent variable where the data is measured ydata (ndarray) – The dependant data eval_points (ndarray or None) – Contain the list of points on which the result must be expressed. It is used both for plotting and for the bootstrapping. CI (tuple of int) – List of confidence intervals to calculate. If empty, none are calculated. xname (string) – Name of the X axis yname (string) – Name of the Y axis fct_desc (string) – Formula of the function param_names (tuple of strings) – Name of the various parameters residuals (callable) – Residual function res_desc (string) – Description of the residuals
  Return type: | `ResultStruct`
  Returns: | Data structure summarising the fitting and its evaluation

`pyqt_fit.plot_fit.` `residual_measures`(res)

  Compute quantities needed to evaluate the quality of the estimation, based solely on the residuals.

  Return type: | `ResidualMeasures`
  Returns: | the scaled residuals, their ordering, the theoretical quantile for each residuals, and the expected value for each quantile.

## Plotting the residuals

`pyqt_fit.plot_fit.` `plot_dist_residuals`(res)

  Plot the distribution of the residuals.

  Returns: | the handle toward the histogram and the plot of the fitted normal distribution

`pyqt_fit.plot_fit.` `plot_residuals`(xname, xdata, res_desc, res)

  Plot the residuals against the X axis

  Parameters: | xname (str) – Name of the X axis xdata (ndarray) – 1D array with the X data res_desc (str) – Name of the Y axis res (ndarray) – 1D array with the residuals

  The shapes of `xdata` and `res` must be the same

  Returns: | The handles of the the plots of the residuals and of the smoothed residuals.

`pyqt_fit.plot_fit.` `scaled_location_plot`(yname, yopt, scaled_res)

  Plot the scaled location, given the dependant values and scaled residuals.

  Parameters: | yname (str) – Name of the Y axis yopt (ndarray) – Estimated values scaled_res (ndarray) – Scaled residuals
  Returns: | the handles for the data and the smoothed curve

`pyqt_fit.plot_fit.` `qqplot`(scaled_res, normq)

  Draw a Q-Q Plot from the sorted, scaled residuals (i.e. residuals sorted and normalized by their standard deviation)

  Parameters: | scaled_res (ndarray) – Scaled residuals normq (ndarray) – Expected value for each scaled residual, based on its quantile.
  Returns: | handle to the data plot

`pyqt_fit.plot_fit.` `plot_residual_tests`(xdata, yopts, res, fct_name, xname='X', yname='Y', res_name='residuals', sorted_yopts=None, scaled_res=None, normq=None, fig=None)

  Plot, in a single figure, all four residuals evaluation plots: `plot_residuals()`, `plot_dist_residuals()`, `scaled_location_plot()` and `qqplot()`.

  Parameters: | xdata (ndarray) – Explaining variables yopt (ndarray) – Optimized explained variables fct_name (str) – Name of the fitted function xname (str) – Name of the explaining variables yname (str) – Name of the dependant variables res_name (str) – Name of the residuals sorted_yopts (ndarray) – `yopt`, sorted to match the scaled residuals scaled_res (ndarray) – Scaled residuals normq (ndarray) – Estimated value of the quantiles for a normal distribution fig (handle or None) – Handle of the figure to put the plots in, or None to create a new figure
  Return type: | `ResTestResult`
  Returns: | The handles to all the plots

## General plotting

`pyqt_fit.plot_fit.` `plot1d`(result, loc=0, fig=None, res_fig=None)

  Use matplotlib to display the result of a fit, and return the list of plots used

  Return type: | `Plot1dResult`
  Returns: | hangles to the various figures and plots

## Output to a file

`pyqt_fit.plot_fit.` `write1d`(outfile, result, res_desc, CImethod)

  Write the result of a fitting and its evaluation to a CSV file.

  Parameters: | outfile (str) – Name of the file to write to result (ResultStruct) – Result of the fitting evaluation (e.g. output of `fit_evaluation()`) res_desc (str) – Description of the residuals (in more details than just the name of the residuals) CImethod (str) – Description of the confidence interval estimation method

## Return types

Most function return a tuple. For easier access, there are named tuple, i.e. tuples that can be accessed by name.

class `pyqt_fit.plot_fit.` `ResultStruct`(...)

  Note

  This is a class created with `pyqt_fit.utils.namedtuple()`.

  `fct`

    Fitted function (i.e. result of the fitted function)

  `fct_desc`

    Description of the function being fitted

  `param_names`

    Name of the parameters fitted

  `xdata`

    Explaining variables used for fitting

  `ydata`

    Dependent variables observed during experiment

  `xname`

    Name of the explaining variables

  `yname`

    Name of the dependent variabled

  `res_name`

    Name of the residuals

  `residuals`

    Function used to compute the residuals

  `popt`

    Optimal parameters

  `res`

    Residuals computed with the parameters `popt`

  `yopts`

    Evaluation of the optimized function on the observed points

  `eval_points`

    Points on which the function has been interpolated (may be equal to xdata)

  `interpolation`

    Interpolated function on `eval_points` (may be equal to `yopt`)

  `sorted_yopts`

    Evaluated function for each data points, sorted in increasing residual order

  `scaled_res`

    Scaled residuals, ordered by increasing residuals

  `normq`

    Expected values for the residuals, based on their quantile

  `CI`

    List of confidence intervals evaluated (in percent)

  `CIs`

    List of arrays giving the confidence intervals for the dependent variables and for the parameters.

  `CIresults`

    Object returned by the confidence interval method

class `pyqt_fit.plot_fit.` `ResidualMeasures`(scaled_res, res_IX, prob, normq)

  Note

  This is a class created with `pyqt_fit.utils.namedtuple()`.

  `scaled_res`

    Scaled residuals, sorted

  `res_IX`

    Sorting indices for the residuals

  `prob`

    Quantiles of the scaled residuals

  `normq`

    Expected values of the quantiles for a normal distribution

class `pyqt_fit.plot_fit.` `ResTestResult`(res_figure, residuals, scaled_residuals, qqplot, dist_residuals)

  Note

  This is a class created with `pyqt_fit.utils.namedtuple()`.

  `res_figure`

    Handle to the figure

  `residuals`

    Handles created by `plot_residuals()`

  `scaled_residuals`

    Handles created by `scaled_location_plot()`

  `qqplot`

    Handles created by `qqplot()`

  `dist_residuals`

    Handles created by `plot_dist_residuals()`

class `pyqt_fit.plot_fit.` `Plot1dResult`(figure, estimate, data, CIs, *ResTestResult)

  Note

  This is a class create with `pyqt_fit.utils.namedtuple()`. Also, it contains all the first of `ResTestResult` at the end of the tuple.

  `figure`

    Handle to the figure with the data and fitted curve

  `estimate`

    Handle to the fitted curve

  `data`

    Handle to the data

  `CIs`

    Handles to the confidence interval curves

### Navigation

- index
- modules |
- next |
- previous |
- PyQt-Fit 1.3.1 documentation »
- Modules of PyQt-Fit »