hints on directory standards.
[CommonLispStat.git] / examples / 00-loadingData.lisp
blob758a9cc979b028fc1c1646df215a669ab34152c1
1 ;;; -*- mode: lisp -*-
3 ;;; Time-stamp: <2010-02-10 09:01:38 tony>
4 ;;; Creation: <2009-03-12 17:14:56 tony>
5 ;;; File: template.lisp
6 ;;; Author: AJ Rossini <blindglobe@gmail.com>
7 ;;; Copyright: (c)2009--, AJ Rossini. BSD, LLGPL, or GPLv2, depending
8 ;;; on how it arrives.
9 ;;; Purpose: Template header file
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.
16 (in-package :cl-user)
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 "return a string denoting the complete path.
44 FIXME: UNIX-centric (though might work on Mac OSX). Might want to
45 return a pathspec, not a string/namespec"
46 (check-type x string)
47 (concatenate 'string *cls-home-dir* x))
51 (progn
52 ;; LISP-STAT COMPATIBILITY MODE:
54 ;; FIXME: Need to clean up data examples, licenses, attributions, etc.
55 ;; The following breaks because we should use a package to hold
56 ;; configuration details, and this would be the only package outside
57 ;; of packages.lisp, as it holds the overall defsystem structure.
58 (load-data "iris.lsp") ;; (the above partially fixed).
59 diabetes
60 (variables))
62 (progn
63 ;; COMMON LISP STATISTICS
64 ;; Importing data from DSV text files.
66 #| We use as an example a simple R datasert, chickwts, which has one
67 nominal categorical variable and one continuous categorical
68 variable. This dataset can be accessed in R as follows:
70 > data(chickwts)
71 > dim(chickwts)
72 [1] 71 2
73 > summary(chickwts)
74 weight feed
75 Min. :108.0 casein :12
76 1st Qu.:204.5 horsebean:10
77 Median :258.0 linseed :12
78 Mean :261.3 meatmeal :11
79 3rd Qu.:323.5 soybean :14
80 Max. :423.0 sunflower:12
84 (defparameter *chickwts-df* (filename.dsv->dataframe (localized-pathto "Data/R-chickwts.csv")))
85 ;; *chickwts-df*
86 (xref *chickwts-df* 1 1) ; => 160
87 (xref *chickwts-df* 40 2) ; => "sunflower"
88 *chickwts-df*)