start putting together unittesting framework for linear regression models.
[CommonLispStat.git] / model-fit.lisp
blobd0cc7fd347e2bb16745b5f697a4a456e2c3e3cfa
1 ;;; -*- mode: lisp -*-
2 ;;; Copyright (c) 2005--2007, by A.J. Rossini <blindglobe@gmail.com>
3 ;;; See COPYRIGHT file for any additional restrictions (BSD license).
4 ;;; Since 1991, ANSI was finally finished. Edited for ANSI Common Lisp.
6 ;;; File: model-fit.lisp
7 ;;; Author: AJ Rossini <blindglobe@gmail.com>
8 ;;; Copyright: (c)2007, AJ Rossini. BSD, LLGPL, or GPLv2, depending
9 ;;; on how it arrives.
10 ;;; Purpose: models as a data summarization tools.
11 ;;; Time-stamp: <2006-05-19 12:33:41 rossini>
12 ;;; Creation: <2006-05-17 21:34:07 rossini>
14 ;;; What is this talk of 'release'? Klingons do not make software
15 ;;; 'releases'. Our software 'escapes', leaving a bloody trail of
16 ;;; designers and quality assurance people in its wake.
18 ;;; The model class is used to map a partial or complete model
19 ;;; specification (partial specification made complete by assumptions
20 ;;; inherent in the type of model used, i.e. linear regression assumes
21 ;;; mean-zero and homoskedasticity) and the model-fit class is used to
22 ;;; complete the model specification into how the model instance and
23 ;;; type will then get computed. The approach tken is that we
24 ;;; definitiely want to be able to see how we can explicitly try to
25 ;;; characterize the work that we are trying to infere about the data.
27 (in-package :cl-user)
29 (defpackage :lisp-stat-model-fit
30 (:documentation "Model fitting theory.")
31 (:nicknames :ls-model-fit)
32 (:use :common-lisp
33 :lisp-stat-config
34 :lisp-stat-object-system
35 :lisp-stat-types
36 :lisp-stat-compound-data
37 :lisp-stat-matrix
38 :lisp-stat-linalg)
39 (:shadowing-import-from :lisp-stat-object-system
40 slot-value call-method call-next-method)
41 (:export fit))
43 (in-package :lisp-stat-model)
45 (defclass fit ()
46 ((criteria-functin-name :initform nil
47 :initarg :name
48 :accessor name
49 :reader model-name)
50 (criteria-function :initform nil
51 :initarg :formula
52 :accessor function
53 :reader fit-criteria)
54 (parameter-vars :initform nil
55 :initarg :parameter-vars
56 :accessor param-vars
57 :reader model-formula)
58 (data-vars :initform nil
59 :initarg :data-vars
60 :accessor data-vars
61 :reader model-formula)
62 (fixed-vars :initform nil
63 :initarg :fixed-vars
64 :accessor fixed-vars
65 :reader model-formula)
67 (:documentation "Mathematical Model Fit approach"))
69 (defclass optimization (model-fit))
72 (defclass least-squares (optimization))
73 (defclass weighted-least-squares (least-squares))
75 (defclass maximum-likelihood (optimization))
76 (defclass minimax (optimization))
77 (defclass maximin (optimization))
79 (defclass minimum-entropy (optimization))
80 (defclass lq-norm (optimization))
82 (defclass root-finding (model-fit))
84 (defclass method-of-moments (root-finding))
85 (defclass marginal-models (method-of-moments))
86 (defclass gee (marginal-models))
87 (defclass gee2 (marginal-models))
91 ;;; How would this be used?
93 (setf my-regr-model-1
94 (new 'least-squares '(- y (+ (* beta1 x1) (* beta2 x2)))))
96 ;; and there should be an approach which could provide a mapping to this, i.e.
98 (regression-model (list y) (list x1 x2))
100 ;; could map to the above via macros.