first near final draft of talk -- just have to decide if I should include or exclude...
[CommonLispStat.git] / examples / linear-regression.lisp
blob27cd16e7c9e32cfa31385aa25106bb974ccd4f7b
1 ;;; -*- mode: lisp -*-
3 ;;; Time-stamp: <2009-04-20 18:44:42 tony>
4 ;;; Creation: <2009-04-19 09:41:09 tony>
5 ;;; File: linear-regression.lisp
6 ;;; Author: AJ Rossini <blindglobe@gmail.com>
7 ;;; Copyright: (c)2009--, AJ Rossini. BSD, MIT, LLGPL, or
8 ;;; GPLv2+, or GPLv3+ depending on how it arrives.
9 ;;; Purpose: Example of basic linear regression data analysis in CLS.
11 ;;; What is this talk of 'release'? Klingons do not make software
12 ;;; 'releases'. Our software 'escapes', leaving a bloody trail of
13 ;;; designers and quality assurance people in its wake.
15 (in-package :ls-user)
17 ;; TODO:
18 ;; - confirm estimates for multivariate case,
19 ;; - pretty-print output
20 ;; - fix up API -- what do we want this to look like?
22 (defparameter *m*
23 (regression-model (list->vector-like iron)
24 (list->vector-like absorbtion))
25 "holding variable.")
27 (defparameter *m-fit*
28 (fit-model *m*))
30 (princ *m*)
31 (princ *m-fit*)
33 (estimates *m-fit*)
34 (covariance-matrix *m-fit*)
36 (defparameter *m3*
37 (regression-model (transpose
38 (listoflist->matrix-like
39 (list iron aluminum)
40 :orientation :row-major))
41 (list->vector-like absorbtion)))
42 (princ *m3*)
43 (defparameter *m3-fit*
44 (fit-model *m3*))
47 ;; Should the above look something like:
48 (defparameter *m3-fit*
49 (spec-and-fit-model '(absorbtion = iron aluminum)))
50 ;; in which case we split the list before/after the "=" character.
53 (estimates *m3-fit*)
54 (covariance-matrix *m3-fit*))
58 ;; now to build a linear regression model from an external CSV datafile...
60 (defparameter *my-df*
61 (make-dataframe
62 (rsm.string::filestream->string-table
63 "/path/to/file.dsv"))
64 "Initial read-in of data.")