renamed t-test example file, where it fits in the hierarchy. It's still BROKEN.
[CommonLispStat.git] / examples / linear-regression.lisp
blob8c0e686e67996c06047383711a1ad44339db1ceb
1 ;;; -*- mode: lisp -*-
3 ;;; Time-stamp: <2009-12-13 18:02:13 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 *m2*
28 (lm (list->vector-like iron)
29 (list->vector-like absorbtion))
30 "holding variable.")
32 (defparameter *m-fit*
33 (fit-model *m*))
35 (princ *m2*)
36 (princ *m-fit*)
38 (estimates *m-fit*)
39 (covariance-matrix *m-fit*)
41 (defparameter *m3*
42 (regression-model (transpose
43 (listoflist->matrix-like
44 (list iron aluminum)
45 :orientation :row-major))
46 (list->vector-like absorbtion)))
47 (princ *m3*)
48 (defparameter *m3-fit*
49 (fit-model *m3*))
52 ;; Should the above look something like:
53 (defparameter *m3-fit*
54 (spec-and-fit-model '(absorbtion = iron aluminum)))
55 ;; in which case we split the list before/after the "=" character.
58 (estimates *m3-fit*)
59 (covariance-matrix *m3-fit*)
63 ;; now to build a linear regression model from an external CSV datafile...
65 (defparameter *my-df*
66 (make-dataframe
67 (rsm.string::file->string-table
68 (concatenate 'string *cls-data-dir* "file.dsv"))
69 "Initial read-in of data."))
71 (defparameter *my-resp-var* (slice *my-df* ))
73 (defparameter *my-pred-vars* (slice *my-df* ))