compiles again -- fixed function calls, but need to get the generic function signatur...
[CommonLispStat.git] / examples / 00-loadingData.lisp
blob0d51a53afe63c2d4a28f448e8f7eaf8ff874c39c
1 ;;; -*- mode: lisp -*-
3 ;;; Time-stamp: <2012-10-08 16:21:58 tony>
4 ;;; Creation: <2009-03-12 17:14:56 tony>
5 ;;; File: 00-loadingData.lisp
6 ;;; Author: AJ Rossini <blindglobe@gmail.com>
7 ;;; Copyright: (c)2009--2012, AJ Rossini. MIT license.
8 ;;; Purpose: Example of loading data
10 ;;; What is this talk of 'release'? Klingons do not make software
11 ;;; 'releases'. Our software 'escapes', leaving a bloody trail of
12 ;;; designers and quality assurance people in its wake.
14 (in-package :cl-user)
16 (ql:quickload :cls)
18 (cl:defpackage :cls-examples ;; similar setup to cls-user, without test data
19 (:use :common-lisp
20 :lisp-matrix
21 :common-lisp-statistics)
22 (:shadowing-import-from :lisp-stat
23 call-method call-next-method
25 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
26 asin acos atan sinh cosh tanh asinh acosh atanh float random
27 truncate floor ceiling round minusp zerop plusp evenp oddp
28 < <= = /= >= > > ;; complex
29 conjugate realpart imagpart phase
30 min max logand logior logxor lognot ffloor fceiling
31 ftruncate fround signum cis
33 <= float imagpart)
34 (:export localized-pathto
35 *chkwgts-df*))
37 ;; start within the cls-examples package, which is similar to cls-user
38 (in-package :cls-examples)
40 ;; we'll be loading from directories in the CLS homedir, so we want to
41 ;; make it easier to reach.
42 (defun localized-pathto (x)
43 "Given a string representing a relative path from the CLS home
44 directory, return a string denoting the complete path.
46 FIXME: UNIX-centric (though might work on Mac OSX). We really want to
47 return a pathspec, not a string/namespec"
48 (check-type x string)
49 (concatenate 'string *cls-installation-home-dir* x))
52 (progn
53 ;; LISP-STAT COMPATIBILITY MODE:
55 ;; FIXME: Need to clean up data examples, licenses, attributions, etc.
56 ;; The following breaks because we should use a package to hold
57 ;; configuration details, and this would be the only package outside
58 ;; of packages.lisp, as it holds the overall defsystem structure.
59 (load-data "iris.lsp") ;; (the above partially fixed).
60 diabetes
61 ;; FIXME above: Diabetes unbound, but it shouldn't be. I think
62 ;; we need to eliminate LispStat v1.
63 (variables))
65 (progn
66 ;; COMMON LISP STATISTICS
67 ;; Importing data from DSV text files.
69 #| We use as an example a simple R datasert, chickwts, which has one
70 nominal categorical variable and one continuous categorical
71 variable. This dataset can be accessed in R as follows:
73 > data(chickwts)
74 > dim(chickwts)
75 [1] 71 2
76 > summary(chickwts)
77 weight feed
78 Min. :108.0 casein :12
79 1st Qu.:204.5 horsebean:10
80 Median :258.0 linseed :12
81 Mean :261.3 meatmeal :11
82 3rd Qu.:323.5 soybean :14
83 Max. :423.0 sunflower:12
87 (defparameter *chickwts-df* (filename.dsv->dataframe (localized-pathto "Data/R-chickwts.csv")))
88 ;; *chickwts-df*
89 (xref *chickwts-df* 1 1) ; => 160
90 (xref *chickwts-df* 40 2) ; => "sunflower"
91 *chickwts-df*)