whitespace and docs
[CommonLispStat.git] / examples / 00-loadingData.lisp
blob809701ee7b9a991df0922b631ea51c9145dbd497
1 ;;; -*- mode: lisp -*-
3 ;;; Time-stamp: <2010-02-10 14:07:45 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.
15 (in-package :cl-user)
17 (cl:defpackage :cls-examples ;; similar setup to cls-user, without test data
18 (:use :common-lisp
19 :lisp-matrix
20 :common-lisp-statistics)
21 (:shadowing-import-from :lisp-stat
22 call-method call-next-method
24 expt + - * / ** mod rem abs 1+ 1- log exp sqrt sin cos tan
25 asin acos atan sinh cosh tanh asinh acosh atanh float random
26 truncate floor ceiling round minusp zerop plusp evenp oddp
27 < <= = /= >= > > ;; complex
28 conjugate realpart imagpart phase
29 min max logand logior logxor lognot ffloor fceiling
30 ftruncate fround signum cis
32 <= float imagpart)
33 (:export localized-pathto
34 *chkwgts-df*))
36 ;; start within the cls-examples package, which is similar to cls-user
37 (in-package :cls-examples)
39 ;; we'll be loading from directories in the CLS homedir, so we want to
40 ;; make it easier to reach.
41 (defun localized-pathto (x)
42 "return a string denoting the complete path.
43 FIXME: UNIX-centric (though might work on Mac OSX). Might want to
44 return a pathspec, not a string/namespec"
45 (check-type x string)
46 (concatenate 'string *cls-home-dir* x))
49 (progn
50 ;; LISP-STAT COMPATIBILITY MODE:
52 ;; FIXME: Need to clean up data examples, licenses, attributions, etc.
53 ;; The following breaks because we should use a package to hold
54 ;; configuration details, and this would be the only package outside
55 ;; of packages.lisp, as it holds the overall defsystem structure.
56 (load-data "iris.lsp") ;; (the above partially fixed).
57 diabetes
58 (variables))
60 (progn
61 ;; COMMON LISP STATISTICS
62 ;; Importing data from DSV text files.
64 #| We use as an example a simple R datasert, chickwts, which has one
65 nominal categorical variable and one continuous categorical
66 variable. This dataset can be accessed in R as follows:
68 > data(chickwts)
69 > dim(chickwts)
70 [1] 71 2
71 > summary(chickwts)
72 weight feed
73 Min. :108.0 casein :12
74 1st Qu.:204.5 horsebean:10
75 Median :258.0 linseed :12
76 Mean :261.3 meatmeal :11
77 3rd Qu.:323.5 soybean :14
78 Max. :423.0 sunflower:12
82 (defparameter *chickwts-df* (filename.dsv->dataframe (localized-pathto "Data/R-chickwts.csv")))
83 ;; *chickwts-df*
84 (xref *chickwts-df* 1 1) ; => 160
85 (xref *chickwts-df* 40 2) ; => "sunflower"
86 *chickwts-df*)