Opened 6 years ago

Closed 6 years ago

#17732 closed enhancement (duplicate)

Function "linear_model_fit" to carry out least squares fits to linear models

Reported by: rafa.lopez Owned by:
Priority: major Milestone: sage-duplicate/invalid/wontfix
Component: packages: standard Keywords: regression, function fitting, linear model
Cc: Merged in:
Authors: Reviewers: Jeroen Demeyer
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

A function ("linear_model_fit") is proposed for least squares fits to linear models. The main difference (which increases functionality) with respect to SAGE's "find_fit" function is that "linear_model_fit" provides detailed information about the quality of the fit and parameters error estimation.

In particular, it provides the values of R2, residuals, residuals sum (Delta2), variance estimation (s2), covariance and correlation matrices, standard errors estimation, parameters error estimation for the confidence level required, t-Statistics, Pvalues, fitting function and functions corresponding to upper and lower boundaries of mean confidence region.

This function enables fitting of points with one or several independent variables to linear combinations of any arbitrary functions from either SAGE's standard functions, or any valid arithmetic expression built from them. Since only linear models are allowed, functions must not contain non-numerical symbols other than variable names. (A check on this point is carried out inside the function).

The output can be a list or a dictionary. To get it as a dictionary, the optional input parameter "solution_dict" must be set to True, as in other SAGE functions such as "solve" or "find_fit".

"linear_model_fit" tries to mimic Mathematica's function "LinearModelFit?" (not in full) and its correctness has been tested against the latter. I am attaching a pdf print of the worksheet used to run the examples, as well as a mathematica notebook for further checking. The current content of the notebook (also attached as a pdf file) corresponds to these examples. Obviously, the notebook can be run with other data.

If you find it interesting, please let me know whether you consider that the function should provide further items such as ANOVA table entries and alike (for further options, see mathematica "LinearModelFit?"). I have not included them in the current version because it seemed to be too verbose, but I can reconsider this.

Attachments (3)

Test_examples_linear_model_fit.pdf (303.1 KB) - added by rafa.lopez 6 years ago.
Worksheet with examples
Test_Linear_model_fit.pdf.gz (1.4 MB) - added by rafa.lopez 6 years ago.
Mathematica's notebook with same examples as in worksheet
Test_Linear_model_fit.nb (107.2 KB) - added by rafa.lopez 6 years ago.
Mathematica's notebook for testing purposes

Download all attachments as: .zip

Change History (6)

Changed 6 years ago by rafa.lopez

Worksheet with examples

Changed 6 years ago by rafa.lopez

Mathematica's notebook with same examples as in worksheet

Changed 6 years ago by rafa.lopez

Mathematica's notebook for testing purposes

comment:1 Changed 6 years ago by jdemeyer

  • Authors Rafael López deleted
  • Branch rafa_branch deleted
  • Merged in src/sage/numerical/optimize.py deleted
  • Milestone changed from sage-6.5 to sage-duplicate/invalid/wontfix
  • Report Upstream changed from Reported upstream. No feedback yet. to N/A
  • Reviewers changed from Vincent Knight to Jeroen Demeyer
  • Status changed from new to needs_review

Looks like an exact duplicate of #17733

comment:2 Changed 6 years ago by jdemeyer

  • Status changed from needs_review to positive_review

comment:3 Changed 6 years ago by vbraun

  • Resolution set to duplicate
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.