and loading the new dataframe structure!
[CommonLispStat.git] / ls-demo.lisp
bloba51911bc882eacd7d23f0a18cba5edc1cd994bf8
1 ;;; -*- mode: lisp -*-
2 ;;; Copyright (c) 2006-2008, by A.J. Rossini <blindglobe@gmail.com>
3 ;;; See COPYRIGHT file for any additional restrictions (BSD license).
4 ;;; Since 1991, ANSI was finally finished. Edited for ANSI Common Lisp.
6 ;;; Time-stamp: <2009-09-04 18:00:16 tony>
7 ;;; Creation: sometime in 2006...
8 ;;; File: ls-demo.lisp
9 ;;; Author: AJ Rossini <blindglobe@gmail.com>
10 ;;; Copyright: (c) 2007, AJ Rossini. BSD.
11 ;;; Purpose: demonstrations of how one might use CLSv2.
13 ;;; What is this talk of 'release'? Klingons do not make software
14 ;;; 'releases'. Our software 'escapes', leaving a bloody trail of
15 ;;; designers and quality assurance people in its wake.
17 (in-package :cl-user)
20 ;; (asdf:oos 'asdf:compile-op 'cls :force t)
21 (asdf:oos 'asdf:load-op 'cls)
23 (in-package :ls-user)
25 ;; a bit of infrastructure for beginners
26 (defparameter *my-cls-homedir*
27 "/media/disk/Desktop/sandbox/CLS.git/") ;; CHANGE THIS TO LOCALIZE!!
28 (concatenate 'string *my-cls-homedir* "Data/example.csv")
29 ;; implies
30 (defun localized-pathto (x)
31 (check-type x string)
32 (concatenate 'string *my-cls-homedir* x))
34 ;;; == READ DATA
36 (defparameter *my-df-1*
37 (make-instance 'dataframe-array
38 :storage #2A((1 2 3 4 5)
39 (10 20 30 40 50))
40 :doc "This is an un-interesting dataframe-array"
41 :case-labels (list "x" "y")
42 :var-labels (list "a" "b" "c" "d" "e")))
44 (setf (xref *my-df-1* 0 0) -1d0)
45 ;; *my-df-1*
48 (make-dataframe #2A((1 2 3 4 5)
49 (10 20 30 40 50)))
51 (make-dataframe (rand 4 3))
56 (defparameter *my-df-2*
57 (make-dataframe #2A((1 2 3 4 5)
58 (10 20 30 40 50))
59 :caselabels (list "x" "y")
60 :varlabels (list "a" "b" "c" "d" "e")
61 :doc "This is another boring dataframe-array"))
63 (caselabels *my-df-1*)
64 (varlabels *my-df-1*)
68 (defparameter *my-df-2*
69 (make-dataframe #2A((a 2 T 4 5)
70 (b 20 nil 40 50))
71 :caselabels (list "x" "y")
72 :varlabels (list "a" "b" "c" "d" "e")
73 :doc "This is another boring dataframe-array"))
75 ;; *my-df-2*
78 ;;; HERE#1
80 ;;; read in a CSV dataframe...
83 ;; a better approach is:
84 (asdf:oos 'asdf:load-op 'rsm-string)
85 (rsm.string:file->string-table
86 (localized-pathto "Data/example-mixed.csv")
87 :delims ",")
89 (rsm.string:file->number-table
90 (localized-pathto "Data/example-numeric.csv")
91 :delims ",")
93 (rsm.string:file->number-table
94 (localized-pathto "Data/R-chickwts.csv")
95 :delims ",")
96 (rsm.string:file->string-table
97 (localized-pathto "Data/R-chickwts.csv")
98 :delims ",")
100 (defparameter *my-df-2*
101 (make-instance 'dataframe-array
102 :storage
103 (listoflist->array
104 (rsm.string:file->string-table
105 (localized-pathto "Data/example-mixed.csv")))
106 :doc "This is an interesting dataframe-array"))
107 ;; *my-df-2*
109 (defparameter *my-df-3*
110 (make-instance 'dataframe-array
111 :storage
112 (listoflist->array
113 (transpose-listoflist
114 (rsm.string:file->number-table
115 (localized-pathto "Data/example-numeric.csv"))))
116 :doc "This is an interesting dataframe-array"))
117 ;; *my-df-3*
120 (defparameter *my-df-4*
121 (make-instance 'dataframe-array
122 :storage
123 (listoflist->array
124 (rsm.string:file->number-table
125 (localized-pathto "Data/R-chickwts.csv")
126 :delims ","))
127 :doc "This is an interesting dataframe-array that currently fails"))
128 ;; *my-df-4*
131 (defparameter *my-df-5*
132 (make-instance 'dataframe-array
133 :storage
134 (listoflist->array
135 (transpose-listoflist
136 (rsm.string:file->number-table
137 (localized-pathto "Data/R-swiss.csv"))))
138 :doc "This is an interesting dataframe-array that currently fails"))
139 ;; *my-df-5*
143 (defparameter *mat-1*
144 (make-matrix 3 3
145 :initial-contents #2A((2d0 3d0 4d0) (3d0 2d0 4d0) (4d0 4d0 5d0))))
147 (defparameter *mat-1*
148 (make-matrix 3 3
149 :initial-contents #2A((2d0 3d0 -4d0)
150 (3d0 2d0 -4d0)
151 (4d0 4d0 -5d0))))
152 (mref *mat-1* 2 0)
154 (defparameter *mat-2*
155 (let ((m (rand 3 3)))
156 (m* m (transpose m))))
158 (axpy 100.0d0 *mat-2* (eye 3 3))
160 (potrf (copy *mat-2*)) ;; factor
161 (potri (copy *mat-2*)) ;; invert
162 (minv-cholesky (copy *mat-2*))
163 (m* (minv-cholesky (copy *mat-2*)) *mat-2*)
165 (defparameter *mat-3*
166 (make-matrix
168 :initial-contents '((16d0 13d0 12d0)
169 (13d0 22d0 7d0)
170 (12d0 7d0 17d0))))
172 (potrf (copy *mat-3*)) ;; factor
175 *mat-3* =>
176 #<LA-SIMPLE-MATRIX-DOUBLE 3 x 3
177 16.0 13.0 12.0
178 13.0 22.0 7.0
179 12.0 7.0 17.0>
181 (potrf (copy *mat-3*)) =>
182 (#<LA-SIMPLE-MATRIX-DOUBLE 3 x 3
183 4.0 3.25 3.0
184 13.0 3.3819373146171707 -0.8131433980500301
185 12.0 7.0 2.7090215603069034>
186 "U" NIL)
188 ;; and compare with...
190 > testm <- matrix(data=c(16,13,12,13,22,7,12,7,17),nrow=3)
191 > chol(testm)
192 [,1] [,2] [,3]
193 [1,] 4 3.250000 3.0000000
194 [2,] 0 3.381937 -0.8131434
195 [3,] 0 0.000000 2.7090216
198 ;; which suggests that the major difference is that R zero's out the
199 ;; appropriate terms, and that CLS does not.
203 (potri (copy *mat-2*)) ;; invert
204 (minv-cholesky (copy *mat-2*))
205 (m* (minv-cholesky (copy *mat-2*)) *mat-2*)
209 (lu-decomp #2A((2 3 4) (1 2 4) (2 4 5)))
210 ;; => (#2A((2.0 3.0 4.0) (1.0 1.0 1.0) (0.5 0.5 1.5)) #(0 2 2) -1.0 NIL)
211 (lu-solve
212 (lu-decomp #2A((2 3 4) (1 2 4) (2 4 5)))
213 #(2 3 4))
214 ;; => #(-2.333333333333333 1.3333333333333335 0.6666666666666666)
216 (getrf
217 (make-matrix 3 3
218 :initial-contents #2A((2d0 3d0 4d0) (1d0 2d0 4d0) (2d0 4d0 5d0))))
220 #| => ; so not so good for the vector, but matrix matches.
221 (#<LA-SIMPLE-MATRIX-DOUBLE 3 x 3
222 2.0 3.0 4.0
223 1.0 1.0 1.0
224 0.5 0.5 1.5>
225 #<FNV-INT32 (3) 1 3 3> NIL)
228 (msolve-lu
229 (make-matrix 3 3
230 :initial-contents #2A((2d0 3d0 4d0)
231 (1d0 2d0 4d0)
232 (2d0 4d0 5d0)))
233 (make-vector 3 :type :column
234 :initial-contents '((2d0)
235 (3d0)
236 (4d0))))
238 #| =>
239 #<LA-SIMPLE-VECTOR-DOUBLE (3 x 1)
240 -2.3333333333333335
241 1.3333333333333335
242 0.6666666666666666>
247 ;;; LU common applications
249 (defun minv-lu (a)
250 "invert A using LU Factorization"
251 (let ((a-fac (getrf (copy a))))
252 (first (getri (first a-fac) (second a-fac)))))
254 #+nil (progn
255 (let ((m1 (rand 3 3)))
256 (m* m1 (minv-lu m1))))
258 (defun msolve-lu (a b)
259 "Compute `x1' solving `A x = b', with LU factorization."
260 (let ((a-fac (getrf (copy a))))
261 (first (getrs (first a-fac) b (second a-fac)))))
265 ;; (inverse #2A((2 3 4) (1 2 4) (2 4 5)))
266 ;; #2A((2.0 -0.33333333333333326 -1.3333333333333335)
267 ;; (-1.0 -0.6666666666666666 1.3333333333333333)
268 ;; (0.0 0.6666666666666666 -0.3333333333333333))
270 (minv-lu
271 (make-matrix
273 :initial-contents #2A((2d0 3d0 4d0)
274 (1d0 2d0 4d0)
275 (2d0 4d0 5d0))))
279 #<LA-SIMPLE-MATRIX-DOUBLE 3 x 3
280 2.0 -0.3333333333333333 -1.3333333333333333
281 -1.0 -0.6666666666666666 1.3333333333333333
282 0.0 0.6666666666666666 -0.3333333333333333>
284 ;; so is correct.
288 ;;;;;HERE#2
290 (factorize
291 (make-matrix 3 3
292 :initial-contents #2A((2d0 3d0 4d0)
293 (1d0 2d0 4d0)
294 (2d0 4d0 5d0)))
295 :by :svd)
297 ;; (sv-decomp #2A((2 3 4) (1 2 4) (2 4 5)))
298 ;; (#2A((-0.5536537653489974 0.34181191712789266 -0.7593629708013371)
299 ;; (-0.4653437312661058 -0.8832095891230851 -0.05827549615722014)
300 ;; (-0.6905959164998124 0.3211003503429828 0.6480523475178517))
301 ;; #(9.699290438141343 0.8971681569301373 0.3447525123483081)
302 ;; #2A((-0.30454218417339873 0.49334669582252344 -0.8147779426198863)
303 ;; (-0.5520024849987308 0.6057035911404464 0.5730762743603965)
304 ;; (-0.7762392122368734 -0.6242853493399995 -0.08786630745236332))
305 ;; T)
309 (qr-decomp #2A((2 3 4) (1 2 4) (2 4 5)))
310 ;; (#2A((-0.6666666666666665 0.7453559924999298 5.551115123125783e-17)
311 ;; (-0.3333333333333333 -0.2981423969999719 -0.894427190999916)
312 ;; (-0.6666666666666666 -0.5962847939999439 0.44721359549995787))
313 ;; #2A((-3.0 -5.333333333333334 -7.333333333333332)
314 ;; (0.0 -0.7453559924999292 -1.1925695879998877)
315 ;; (0.0 0.0 -1.3416407864998738)))
317 (rcondest #2A((2 3 4) (1 2 4) (2 4 5)))
318 ;; 6.8157451e7
319 ;;; CURRENTLY FAILS!!
321 (eigen #2A((2 3 4) (1 2 4) (2 4 5)))
322 ;; (#(10.656854249492381 -0.6568542494923802 -0.9999999999999996)
323 ;; (#(0.4999999999999998 0.4999999999999997 0.7071067811865475)
324 ;; #(-0.49999999999999856 -0.5000000000000011 0.7071067811865474)
325 ;; #(0.7071067811865483 -0.7071067811865466 -1.2560739669470215e-15))
326 ;; NIL)
328 (spline #(1.0 1.2 1.3 1.8 2.1 2.5)
329 #(1.2 2.0 2.1 2.0 1.1 2.8) :xvals 6)
330 ;; ((1.0 1.3 1.6 1.9 2.2 2.5)
331 ;; (1.2 2.1 2.2750696543866313 1.6465231041904045 1.2186576148879609 2.8))
333 ;;; using KERNEL-SMOOTH-FRONT, not KERNEL-SMOOTH-CPORT
334 (kernel-smooth #(1.0 1.2 1.3 1.8 2.1 2.5)
335 #(1.2 2.0 2.1 2.0 1.1 2.8) :xvals 5)
336 ;; ((1.0 1.375 1.75 2.125 2.5)
337 ;; (1.6603277642110226 1.9471748095239771 1.7938127405752287
338 ;; 1.5871511322219498 2.518194783156392))
340 (kernel-dens #(1.0 1.2 2.5 2.1 1.8 1.2) :xvals 5)
341 ;; ((1.0 1.375 1.75 2.125 2.5)
342 ;; (0.7224150453621405 0.5820045548233707 0.38216411702854214
343 ;; 0.4829822708587095 0.3485939156929503))
345 (fft #(1.0 1.2 2.5 2.1 1.8))
346 ;; #(#C(1.0 0.0) #C(1.2 0.0) #C(2.5 0.0) #C(2.1 0.0) #C(1.8 0.0))
348 (lowess #(1.0 1.2 2.5 2.1 1.8 1.2) #(1.2 2.0 2.1 2.0 1.1 2.8))
349 ;; (#(1.0 1.2 1.2 1.8 2.1 2.5))
353 ;;;; Special functions
355 ;; Log-gamma function
357 (log-gamma 3.4) ;;1.0923280596789584
361 ;;;; Probability functions
363 ;; looking at these a bit more, perhaps a more CLOSy style is needed, i.e.
364 ;; (quantile :list-or-cons loc :type type (one of 'empirical 'normal 'cauchy, etc...))
365 ;; similar for the cdf, density, and rand.
366 ;; Probably worth figuring out how to add a new distribution
367 ;; efficiently, i.e. by keeping some kind of list.
369 ;; Normal distribution
371 (normal-quant 0.95) ;;1.6448536279366268
372 (normal-cdf 1.3) ;;0.9031995154143897
373 (normal-dens 1.3) ;;0.17136859204780736
374 (normal-rand 2) ;;(-0.40502015f0 -0.8091404f0)
376 (bivnorm-cdf 0.2 0.4 0.6) ;;0.4736873734160288
378 ;; Cauchy distribution
380 (cauchy-quant 0.95) ;;6.313751514675031
381 (cauchy-cdf 1.3) ;;0.7912855998398473
382 (cauchy-dens 1.3) ;;0.1183308127104695
383 (cauchy-rand 2) ;;(-1.06224644160405 -0.4524695943939537)
385 ;; Gamma distribution
387 (gamma-quant 0.95 4.3) ;;8.178692439291645
388 (gamma-cdf 1.3 4.3) ;;0.028895150986674906
389 (gamma-dens 1.3 4.3) ;;0.0731517686447374
390 (gamma-rand 2 4.3) ;;(2.454918912880936 4.081365384357454)
392 ;; Chi-square distribution
394 (chisq-quant 0.95 3) ;;7.814727903379012
395 (chisq-cdf 1 5) ;;0.03743422675631789
396 (chisq-dens 1 5) ;;0.08065690818083521
397 (chisq-rand 2 4) ;;(1.968535826180572 2.9988646156942997)
399 ;; Beta distribution
401 (beta-quant 0.95 3 2) ;;0.9023885371149876
402 (beta-cdf 0.4 2 2.4) ;;0.4247997418541529
403 (beta-dens 0.4 2 2.4) ;;1.5964741858913518
404 (beta-rand 2 2 2.4) ;;(0.8014897077282279 0.6516371997922659)
406 ;; t distribution
408 (t-quant 0.95 3) ;;2.35336343484194
409 (t-cdf 1 2.3) ;;0.794733624298342
410 (t-dens 1 2.3) ;;0.1978163816318102
411 (t-rand 2 2.3) ;;(-0.34303672776089306 -1.142505872436518)
413 ;; F distribution
415 (f-quant 0.95 3 5) ;;5.409451318117459
416 (f-cdf 1 3.2 5.4) ;;0.5347130905510765
417 (f-dens 1 3.2 5.4) ;;0.37551128864591415
418 (f-rand 2 3 2) ;;(0.7939093442091963 0.07442694152491144)
420 ;; Poisson distribution
422 (poisson-quant 0.95 3.2) ;;6
423 (poisson-cdf 1 3.2) ;;0.17120125672252395
424 (poisson-pmf 1 3.2) ;;0.13043905274097067
425 (poisson-rand 5 3.2) ;;(2 1 2 0 3)
427 ;; Binomial distribution
429 (binomial-quant 0.95 3 0.4) ;;; DOESN'T RETURN
430 (binomial-quant 0 3 0.4) ;;; -2147483648
431 (binomial-cdf 1 3 0.4) ;;0.6479999999965776
432 (binomial-pmf 1 3 0.4) ;;0.4320000000226171
433 (binomial-rand 5 3 0.4) ;;(2 2 0 1 2)
435 ;;;; OBJECT SYSTEM
437 (in-package :ls-user)
438 (defproto *test-proto*)
439 *test-proto*
440 (defmeth *test-proto* :make-data (&rest args) nil)
442 (defparameter my-proto-instance nil)
443 (setf my-proto-instance (send *test-proto* :new))
444 (send *test-proto* :own-slots)
445 (lsos::ls-object-slots *test-proto*)
446 (lsos::ls-object-methods *test-proto*)
447 (lsos::ls-object-parents *test-proto*)
448 (lsos::ls-object-preclist *test-proto*)
449 ;;; The following fail and I do not know why?
450 (send *test-proto* :has-slot 'proto-name)
451 (send *test-proto* :has-slot 'PROTO-NAME)
452 (send *test-proto* :has-slot 'make-data)
453 (send *test-proto* :has-slot 'MAKE-DATA)
454 (send *test-proto* :has-method 'make-data)
455 (send *test-proto* :has-method 'MAKE-DATA)
458 (defproto2 *test-proto3* (list) (list) (list) "test doc" t)
459 (defproto2 *test-proto4*)
460 *test-proto2*
461 (defmeth *test-proto* :make-data (&rest args) nil)
463 (defparameter my-proto-instance nil)
464 (setf my-proto-instance (send *test-proto* :new))
465 (send *test-proto* :own-slots)
466 (send *test-proto* :has-slot 'proto-name)
467 (send *test-proto* :has-slot 'PROTO-NAME)
470 ;;;; Testing
472 (in-package :lisp-stat-unittests)
473 (testsuites)
474 (print-tests)
475 (run-tests)
476 (last-test-status)
477 ;;(failures)
479 (describe (run-tests :suite 'lisp-stat-ut-testsupport))
480 (describe (run-tests :suite 'lisp-stat-ut-testsupport2))
482 (testsuite-tests 'lisp-stat-ut)
483 (run-tests :suite 'lisp-stat-ut)
484 (describe (run-tests :suite 'lisp-stat-ut))
486 (run-tests :suite 'lisp-stat-ut-probdistn)
487 (describe (run-tests :suite 'lisp-stat-ut-probdistn))
488 (run-tests :suite 'lisp-stat-ut-spec-fns)
489 (describe (run-tests :suite 'lisp-stat-ut-spec-fns))
491 (find-testsuite 'lisp-stat-ut-lin-alg)
492 (testsuite-tests 'lisp-stat-ut-lin-alg)
493 (run-tests :suite 'lisp-stat-ut-lin-alg)
494 (describe (run-tests :suite 'lisp-stat-ut-lin-alg))
496 ;;;; Data Analysis test
498 (in-package :ls-user)
500 ;; LispStat 1 approach to variables
502 (progn
503 (def iron (list 61 175 111 124 130 173 169 169 160 224 257 333 199))
504 iron
505 (def aluminum (list 13 21 24 23 64 38 33 61 39 71 112 88 54))
506 aluminum
507 (def absorbtion (list 4 18 14 18 26 26 21 30 28 36 65 62 40))
508 absorbtion
510 ;; LispStat 1 approach to data frames... (list of lists).
512 (DEF DIABETES
513 (QUOTE ((80 97 105 90 90 86 100 85 97 97 91 87 78 90 86 80 90 99 85 90 90 88 95 90 92 74 98 100 86 98 70 99 75 90 85 99 100 78 106 98 102 90 94 80 93 86 85 96 88 87 94 93 86 86 96 86 89 83 98 100 110 88 100 80 89 91 96 95 82 84 90 100 86 93 107 112 94 93 93 90 99 93 85 89 96 111 107 114 101 108 112 105 103 99 102 110 102 96 95 112 110 92 104 75 92 92 92 93 112 88 114 103 300 303 125 280 216 190 151 303 173 203 195 140 151 275 260 149 233 146 124 213 330 123 130 120 138 188 339 265 353 180 213 328 346)
514 (356 289 319 356 323 381 350 301 379 296 353 306 290 371 312 393 364 359 296 345 378 304 347 327 386 365 365 352 325 321 360 336 352 353 373 376 367 335 396 277 378 360 291 269 318 328 334 356 291 360 313 306 319 349 332 323 323 351 478 398 426 439 429 333 472 436 418 391 390 416 413 385 393 376 403 414 426 364 391 356 398 393 425 318 465 558 503 540 469 486 568 527 537 466 599 477 472 456 517 503 522 476 472 455 442 541 580 472 562 423 643 533 1468 1487 714 1470 1113 972 854 1364 832 967 920 613 857 1373 1133 849 1183 847 538 1001 1520 557 670 636 741 958 1354 1263 1428 923 1025 1246 1568)
515 (124 117 143 199 240 157 221 186 142 131 221 178 136 200 208 202 152 185 116 123 136 134 184 192 279 228 145 172 179 222 134 143 169 263 174 134 182 241 128 222 165 282 94 121 73 106 118 112 157 292 200 220 144 109 151 158 73 81 151 122 117 208 201 131 162 148 130 137 375 146 344 192 115 195 267 281 213 156 221 199 76 490 143 73 237 748 320 188 607 297 232 480 622 287 266 124 297 326 564 408 325 433 180 392 109 313 132 285 139 212 155 120 28 23 232 54 81 87 76 42 102 138 160 131 145 45 118 159 73 103 460 42 13 130 44 314 219 100 10 83 41 77 29 124 15)
516 (3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 2 2 3 2 2 3 3 3 3 2 3 3 3 3 3 2 3 3 3 3 3 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1))))
519 (DEF DLABS (QUOTE ("GLUFAST" "GLUTEST" "INSTEST" "CCLASS")))
520 (format t "loaded data.~%")
521 ) ;; eval at this point.
523 ;; Simple univariate variable-specific descriptions.
524 (fivnum absorbtion)
525 (median absorbtion)
526 (sort-data absorbtion)
527 (rank absorbtion)
528 (standard-deviation absorbtion)
529 (interquartile-range absorbtion)
531 (lisp-stat-matrix::bind-columns aluminum iron)
532 (bind-columns aluminum iron)
533 (apply #'bind-columns (list aluminum iron))
534 (lisp-stat-matrix::bind-columns #2a((1 2)(3 4)) #(5 6))
535 (bind-columns #2a((1 2)(3 4)) #(5 6))
538 (defparameter fit1 nil)
539 (setf fit1 (regression-model absorbtion iron))
540 (send fit1 :display)
541 (send fit1 :residuals)
543 iron
544 (defparameter fit1a nil)
545 (setf fit1a (regression-model absorbtion iron :print nil))
546 (send fit1a :doc)
547 ;; (setf (send fit1a :doc) "this") ;; FIXME: this error...
548 (send fit1a :doc "this") ;; FIXME: this is a more natural
549 (send fit1a :doc)
550 (send fit1a :x)
551 (send fit1a :y)
552 (send fit1a :compute)
553 (send fit1a :sweep-matrix)
554 (send fit1a :basis)
555 (send fit1a :residuals)
556 (send fit1a :display)
558 #+nil(progn
559 ;; syntax example
560 (array-dimension #2A ((1)) 0)
563 ;;; FIXME: need to get multiple-linear regression working -- clearly
564 ;;; simple linear is working above!
565 (defvar m nil "holding variable.")
566 (def m (regression-model (list iron aluminum) absorbtion :print nil))
567 (send m :compute)
568 (send m :sweep-matrix)
569 (format t "~%~A~%" (send m :sweep-matrix))
571 ;; ERROR... FIX-ME!!
572 (send m :basis) ;; this should be positive?
573 (send m :coef-estimates)
575 (send m :display)
576 (def m (regression-model (bind-columns iron aluminum) absorbtion))
577 (send m :help)
578 (send m :help :display)
579 (send m :help :basis)
580 ;; No graphics! But handle the error gracefully...
581 (send m :plot-residuals)
584 (typep aluminum 'sequence)
585 (typep iron 'sequence)
586 (matrixp iron)
588 *variables*
590 (variables)
591 (undef 'iron)
592 (variables)
594 ;;; Plotting!
596 (asdf:oos 'asdf:compile-op 'cl-cairo2 :force t)
597 (asdf:oos 'asdf:load-op 'cl-cairo2)
599 ;; The above can be used to generate PDF, PS, PNG, and X11/Microsoft
600 ;; displays (the latter being a proof of concept, of limited use for
601 ;; "real work".
603 ;; and this below, as well.
604 (asdf:oos 'asdf:load-op 'cl-plplot)
606 ;;; Using R!
608 (asdf:oos 'asdf:compile-op 'rclg :force t)
609 (asdf:oos 'asdf:load-op 'rclg)
612 (in-package :rclg-user)
614 ;; rclg-init::*r-started*
616 ;;;#3 Start R within Lisp
618 (start-rclg)
619 ;; rclg-init::*r-started*
620 (rclg-init::check-stack)
621 (r "Cstack_info")
622 (defparameter *x* (r seq 1 10))
623 (defparameter *y* (r rnorm 10))
625 (r plot *x* *y*)
628 (defparameter *r-version* (r "version"))
630 ;; This is for illustrative purposes only. It is not a "good" use of rnbi.
631 ;; Really, you'll want rnbi to hold anonymous intermeditae results, like:
632 (r plot *x* (rnbi rnorm 10))
634 (r "Sys.getenv" "LD_LIBRARY_PATH")
635 (r "Sys.getenv" "LD_PRELOAD")
637 (r "ls")
638 (r ls)
639 (r "search")
641 (r "geterrmessage")
643 (r "library" "stats")
644 (r library "MASS")
645 (r "library" "Biobase")
647 (setf my.lib "Biobase")
648 my.lib
649 (r library my.lib)
651 (r "ls")
653 (r "print.default" 3)
654 (r "rnorm" 10)
656 ;; Working in the R space
658 (r assign "x" 5)
659 (r assign "x2" (list 1 2 3 5))
661 (r assign "x2" #(1 2 3 5 3 4 5))
662 (r assign "z" "y") ;; unlike the above, this assigns character data
663 (r "ls")
664 (r ls)
666 (setf my.r.x2 (r get "x2")) ;; moving data from R to CL
667 (r assign "x2" my.r.x2) ;; moving data from CL to R
669 ;; The following is not the smartest thing to do!
670 ;;(r q)
674 ;;; How might we do statistics with Common Lisp?
675 ;;; How might we work with a data.frame?
676 ;;; What could the structures be?
677 ;;; How much hinting, and of what type, should drive the data
678 ;;; analysis?
680 (defpackage :my-data-analysis-example
681 (:documentation "Example work-package for a data analysis")
682 (:use :common-lisp :lisp-stat)
683 (:export results figures report))
685 (in-package :my-data-analysis-example)
687 (defvar my-dataset1 (read-file "data/test1.lisp"))
688 ;; or
689 (defvar my-dataset2 (read-file "data/test1.csv" :type 'csv))
691 ;;; manipulate
693 (setf my-dataset2 (set-description my-datasets2
694 :dependent-variables (list of symbols)))
695 (setf my-dataset2 (set-description my-datasets2
696 :independent-variables (list of symbols)))
698 ;; the following could be true in many cases.
699 (assert
700 (list-intersection (get-description my-datasets2 :independent-variables)
701 (get-description my-datasets2 :dependent-variables)))
703 ;; but we could phrase better,i.e.
705 (get-description
706 my-datasets2
707 :predicate-list-on-variable-metadata (list (and 'independent-variables
708 'dependent-variables)))
711 ;; statistical relations re: input/output, as done above, is one
712 ;; issue, another one is getting the right approach for statistical
713 ;; typing, i.e.
714 (get-description
715 my-datasets2
716 :predicate-list-on-variable-metadata (list 'ordinal-variables))
719 ;; so we could use a set of logical ops to selection from variable
720 ;; metadata, i.e.
721 ;; and, or, not
722 ;; do we really need the simplifying extensions?
725 ;;; output to REPL
727 (report my-dataset1 :style 'five-num)
728 (report my-dataset1 :style 'univariate)
729 (report my-dataset1 :style 'bivariate)
730 (report my-dataset1 :style 'metadata)
732 ;;; to file?
734 (report my-dataset1
735 :style 'five-num
736 :format 'pdf
737 :stream (filename-as-stream "my-dataset1-5num.pdf"))
738 (report my-dataset1 :style 'univariate)
739 (report my-dataset1 :style 'bivariate)
740 (report my-dataset1 :style 'metadata)
742 ;;; so report could handle datasets... and models?
744 (report my-model :style 'formula)
745 (report my-model :style 'simulate
746 (list :parameters (:eta 5 :mu 4 :sigma (list 2 1 0.5))
747 :number-of-reps 10))
748 ;; should return a list of parameters along with range information,
749 ;; useful for auto-building the above. Note that there are 3 types
750 ;; of parameters that can be considered -- we can have values which
751 ;; define ddata, we can have values which define fixed values and some
752 ;; could be things tht we estimate.
755 (defgeneric report (object &optional style format stream)
756 (:documentation "method for reporting on data"))
758 (defmethod report ((object dataset)
759 (style report-dataset-style-type)
760 (format output-format-type)
761 ((stream *repl*) output-stream-type))
762 "dataset reporting")
765 (defmethod report ((object model)
766 (style report-model-style-type)
767 (format output-format-type)
768 ((stream *repl*) output-stream-type))
769 "model reporting")
771 (defmethod report ((object analysis-instance)
772 (style report-analysis-style-type)
773 (format output-format-type)
774 ((stream *repl*) output-stream-type))
775 "model + dataset reporting")
778 ;; parameters are just things which get filled with values, repeatedly
779 ;; with data, or by considering to need estimation.
780 (parameters my-model)
781 (parameters my-model :type 'data)
782 (parameters my-model :type 'fixed)
783 (parameters my-model :type 'estimate)
784 (parameters my-model :type '(estimate fixed))
785 (parameters my-model :list-types) ;; useful for list-based extraction
786 ;; of particular types
788 (setf my-model-data-instance
789 (compute model data :specification (list :spec 'linear-model
790 :depvar y
791 :indepvar (list x1 x2))))
792 (report my-model-data-instance)
795 ;;; So how might we use this? Probably need to consider the
796 ;;; serialization of any lisp objects generated, perhaps via some form
797 ;;; of memoization...?
798 (in-package :cl-user)
800 (my-data-analysis-example:report :type 'full)
801 (my-data-analysis-example:report :type 'summary)
802 (my-data-analysis-example:figures :type 'pdf :file "results-figs.pdf")
804 (my-data-analysis-example:report)
806 ;;; more stuff
808 (send m :display)
809 (def m (regression-model (bind-columns iron aluminum) absorbtion))
810 (send m :help)
811 (send m :help :display)
812 (send m :help :basis)
814 (send m :plot-residuals)
816 (progn
817 ;; General Lisp, there is also a need to add, remove symbols from the
818 ;; workspace/namespace. This is a fundamental skill, similar to
819 ;; stopping, which is critical.
821 ;; boundp, fboundp
822 ;; makunbound, fmakunbound
826 (progn
827 ;;; A study in array vs list access
828 (defparameter *x* (list 1 2 3))
829 (defparameter *y* #(1 2 3))
830 (defparameter *z* (list 1 (list 2 3) (list 4 5 (list 6 7)) ))
831 (length *x*)
832 (length *y*)
833 (length *z*) ; => need a means to make this 7.
834 (length (reduce #'cons *z*)) ; => not quite -- missing iterative
836 (nelts *x*)
837 (nth 1 *x*)
838 (aref *y* 1)
839 (setf (nth 1 *x*) 6)
841 (setf (aref *y* 1) 6)
845 (in-package :ls-user)
847 (progn
848 (defparameter *x* (make-vector 5 :initial-contents '((1d0 2d0 3d0 4d0 5d0))))
849 ;; estimating a mean, simple way.
850 (/ (loop for i from 0 to (- (nelts *x*) 1)
851 summing (vref *x* i))
852 (nelts *x*))
854 (defun mean (x)
855 (checktype x 'vector-like)
856 (/ (loop for i from 0 to (- (nelts *x*) 1)
857 summing (vref *x* i))
858 (nelts *x*)))
860 ;; estimating variance, Moments
861 (let ((meanx (mean *x*))
862 (n (nelts *x*)))
863 (/ (loop for i from 0 to (1- n)
864 summing (* (- (vref *x* i) meanx)
865 (- (vref *x* i) meanx)))
868 ;; estimating variance, Moments
869 (let ((meanx (mean *x*))
870 (nm1 (1- (nelts *x*))))
871 (/ (loop for i from 0 to nm1
872 summing (* (- (vref *x* i) meanx)
873 (- (vref *x* i) meanx) ))
874 nm1))
878 ;;;;;;;;;;;;;;; Data stuff
880 (progn ;; Data setup
882 ;; Making data-frames (i.e. cases (rows) by variables (columns))
883 ;; takes a bit of getting used to. For this, it is important to
884 ;; realize that we can do the following:
885 ;; #1 - consider the possibility of having a row, and transposing
886 ;; it, so the list-of-lists is: ((1 2 3 4 5)) (1 row, 5 columns)
887 ;; #2 - naturally list-of-lists: ((1)(2)(3)(4)(5)) (5 rows, 1 column)
888 ;; see src/data/listoflist.lisp for code to process this particular
889 ;; data structure.
890 (defparameter *indep-vars-1-matrix*
891 (transpose (make-matrix 1 (length iron)
892 :initial-contents
893 (list (mapcar #'(lambda (x) (coerce x 'double-float))
894 iron))))
895 "creating iron into double float, straightforward")
897 (documentation '*indep-vars-1-matrix* 'variable)
898 ;; *indep-vars-1-matrix*
900 ;; or directly:
901 (defparameter *indep-vars-1a-matrix*
902 (make-matrix (length iron) 1
903 :initial-contents
904 (mapcar #'(lambda (x) (list (coerce x 'double-float)))
905 iron)))
906 ;; *indep-vars-1a-matrix*
908 ;; and mathematically, they seem equal:
909 (m= *indep-vars-1-matrix* *indep-vars-1a-matrix*) ; => T
910 ;; but of course not completely...
911 (eql *indep-vars-1-matrix* *indep-vars-1a-matrix*) ; => NIL
912 (eq *indep-vars-1-matrix* *indep-vars-1a-matrix*) ; => NIL
914 ;; and verify...
915 (print *indep-vars-1-matrix*)
916 (print *indep-vars-1a-matrix*)
918 (documentation 'lisp-matrix:bind2 'function) ; by which we mean:
919 (documentation 'bind2 'function)
920 (bind2 *indep-vars-1-matrix* *indep-vars-1a-matrix* :by :column) ; 2 col
921 (bind2 *indep-vars-1-matrix* *indep-vars-1a-matrix* :by :row) ; 1 long col
923 ;; the weird way
924 (defparameter *indep-vars-2-matrix*
925 (transpose (make-matrix 2 (length iron)
926 :initial-contents
927 (list
928 (mapcar #'(lambda (x) (coerce x 'double-float))
929 iron)
930 (mapcar #'(lambda (x) (coerce x 'double-float))
931 aluminum)))))
932 ;; *indep-vars-2-matrix*
934 ;; the "right"? way
935 (defparameter *indep-vars-2-matrix*
936 (make-matrix (length iron) 2
937 :initial-contents
938 (mapcar #'(lambda (x y)
939 (list (coerce x 'double-float)
940 (coerce y 'double-float)))
941 iron aluminum)))
942 ;; *indep-vars-2-matrix*
945 ;; The below FAILS due to coercion issues; it just isn't lispy, it's R'y.
947 (defparameter *dep-var* (make-vector (length absorbtion)
948 :initial-contents (list absorbtion)))
950 ;; BUT below, this should be the right type.
951 (defparameter *dep-var*
952 (make-vector (length absorbtion)
953 :type :row
954 :initial-contents
955 (list
956 (mapcar #'(lambda (x) (coerce x 'double-float))
957 absorbtion))))
958 ;; *dep-var*
961 (defparameter *dep-var-int*
962 (make-vector (length absorbtion)
963 :type :row
964 :element-type 'integer
965 :initial-contents (list absorbtion)))
967 (typep *dep-var* 'matrix-like) ; => T
968 (typep *dep-var* 'vector-like) ; => T
970 (typep *indep-vars-1-matrix* 'matrix-like) ; => T
971 (typep *indep-vars-1-matrix* 'vector-like) ; => T
972 (typep *indep-vars-2-matrix* 'matrix-like) ; => T
973 (typep *indep-vars-2-matrix* 'vector-like) ; => F
975 iron
976 ;; following fails, need to ensure that we work on list elts, not just
977 ;; elts within a list:
979 ;; (coerce iron 'real)
981 ;; the following is a general list-conversion coercion approach -- is
982 ;; there a more efficient way?
983 ;; (coerce 1 'real)
984 ;; (mapcar #'(lambda (x) (coerce x 'double-float)) iron)
986 (princ "Data Set up"))
991 (progn ;; Data setup
993 (describe 'make-matrix)
995 (defparameter *indep-vars-2-matrix*
996 (make-matrix (length iron) 2
997 :initial-contents
998 (mapcar #'(lambda (x y)
999 (list (coerce x 'double-float)
1000 (coerce y 'double-float)))
1001 iron aluminum)))
1004 (defparameter *dep-var*
1005 (make-vector (length absorbtion)
1006 :type :row
1007 :initial-contents
1008 (list
1009 (mapcar #'(lambda (x) (coerce x 'double-float))
1010 absorbtion))))
1012 (make-dataframe *dep-var*)
1013 (make-dataframe (transpose *dep-var*))
1015 (defparameter *dep-var-int*
1016 (make-vector (length absorbtion)
1017 :type :row
1018 :element-type 'integer
1019 :initial-contents (list absorbtion)))
1022 (defparameter *xv+1a*
1023 (make-matrix
1025 :initial-contents #2A((1d0 1d0)
1026 (1d0 3d0)
1027 (1d0 2d0)
1028 (1d0 4d0)
1029 (1d0 3d0)
1030 (1d0 5d0)
1031 (1d0 4d0)
1032 (1d0 6d0))))
1034 (defparameter *xv+1b*
1035 (bind2
1036 (ones 8 1)
1037 (make-matrix
1039 :initial-contents '((1d0)
1040 (3d0)
1041 (2d0)
1042 (4d0)
1043 (3d0)
1044 (5d0)
1045 (4d0)
1046 (6d0)))
1047 :by :column))
1049 (m= *xv+1a* *xv+1b*) ; => T
1051 (princ "Data Set up"))
1055 ;;;; LM
1057 (progn
1059 (defparameter *y*
1060 (make-vector
1062 :type :row
1063 :initial-contents '((1d0 2d0 3d0 4d0 5d0 6d0 7d0 8d0))))
1066 (defparameter *xv+1*
1067 (make-matrix
1069 :initial-contents '((1d0 1d0)
1070 (1d0 3d0)
1071 (1d0 2d0)
1072 (1d0 4d0)
1073 (1d0 3d0)
1074 (1d0 5d0)
1075 (1d0 4d0)
1076 (1d0 6d0))))
1079 ;; so something like (NOTE: matrices are transposed to begin with, hence the incongruety)
1080 (defparameter *xtx-2* (m* (transpose *xv+1*) *xv+1*))
1081 ;; #<LA-SIMPLE-MATRIX-DOUBLE 2 x 2
1082 ;; 8.0d0 28.0d0
1083 ;; 28.0d0 116.0d0>
1085 (defparameter *xty-2* (m* (transpose *xv+1*) (transpose *y*)))
1086 ;; #<LA-SIMPLE-VECTOR-DOUBLE (2 x 1)
1087 ;; 36.0d0
1088 ;; 150.0d0>
1090 (defparameter *rcond-2* 0.000001)
1091 (defparameter *betahat-2* (gelsy *xtx-2* *xty-2* *rcond-2*))
1092 ;; *xtx-2* => "details of complete orthogonal factorization"
1093 ;; according to man page:
1094 ;; #<LA-SIMPLE-MATRIX-DOUBLE 2 x 2
1095 ;; -119.33147112141039d0 -29.095426104883202d0
1096 ;; 0.7873402682880205d0 -1.20672274167718d0>
1098 ;; *xty-2* => output becomes solution:
1099 ;; #<LA-SIMPLE-VECTOR-DOUBLE (2 x 1)
1100 ;; -0.16666666666668312d0
1101 ;; 1.333333333333337d0>
1103 *betahat-2* ; which matches R, see below
1105 (documentation 'gelsy 'function)
1108 ;; (#<LA-SIMPLE-VECTOR-DOUBLE (2 x 1)
1109 ;; -0.16666666666668312 1.333333333333337>
1110 ;; 2)
1112 ;; ## Test case in R:
1113 ;; x <- c( 1.0, 3.0, 2.0, 4.0, 3.0, 5.0, 4.0, 6.0)
1114 ;; y <- c( 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0)
1115 ;; lm(y~x)
1116 ;; ## => Call: lm(formula = y ~ x)
1118 ;; Coefficients: (Intercept) x
1119 ;; -0.1667 1.3333
1121 ;; summary(lm(y~x))
1122 ;; ## =>
1124 ;; Call:
1125 ;; lm(formula = y ~ x)
1127 ;; Residuals:
1128 ;; Min 1Q Median 3Q Max
1129 ;; -1.833e+00 -6.667e-01 -3.886e-16 6.667e-01 1.833e+00
1131 ;; Coefficients:
1132 ;; Estimate Std. Error t value Pr(>|t|)
1133 ;; (Intercept) -0.1667 1.1587 -0.144 0.89034
1134 ;; x 1.3333 0.3043 4.382 0.00466 **
1135 ;; ---
1136 ;; Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
1138 ;; Residual standard error: 1.291 on 6 degrees of freedom
1139 ;; Multiple R-squared: 0.7619, Adjusted R-squared: 0.7222
1140 ;; F-statistic: 19.2 on 1 and 6 DF, p-value: 0.004659
1144 ;; which suggests one might do (modulo ensuring correct
1145 ;; orientations). When this is finalized, it should migrate to
1146 ;; CLS.
1150 (defparameter *n* 20) ; # rows = # obsns
1151 (defparameter *p* 10) ; # cols = # vars
1152 (defparameter *x-temp* (rand *n* *p*))
1153 (defparameter *b-temp* (rand *p* 1))
1154 (defparameter *y-temp* (m* *x-temp* *b-temp*))
1155 ;; so Y=Xb + \eps
1156 (defparameter *rcond* (* (coerce (expt 2 -52) 'double-float)
1157 (max (nrows *x-temp*) (ncols *y-temp*))))
1158 (defparameter *orig-x* (copy *x-temp*))
1159 (defparameter *orig-b* (copy *b-temp*))
1160 (defparameter *orig-y* (copy *y-temp*))
1162 (defparameter *lm-result* (lm *x-temp* *y-temp*))
1163 (princ (first *lm-result*))
1164 (princ (second *lm-result*))
1165 (princ (third *lm-result*))
1166 (v= (third *lm-result*)
1167 (v- (first (first *lm-result*))
1168 (first (second *lm-result*))))
1173 ;; Some issues exist in the LAPACK vs. LINPACK variants, hence R
1174 ;; uses LINPACK primarily, rather than LAPACK. See comments in R
1175 ;; source for issues.
1178 ;; Goal is to start from X, Y and then realize that if
1179 ;; Y = X \beta, then, i.e. 8x1 = 8xp px1 + 8x1
1180 ;; XtX \hat\beta = Xt Y
1181 ;; so that we can solve the equation W \beta = Z where W and Z
1182 ;; are known, to estimate \beta.
1184 ;; the above is known to be numerically instable -- some processing
1185 ;; of X is preferred and should be done prior. And most of the
1186 ;; transformation-based work does precisely that.
1188 ;; recall: Var[Y] = E[(Y - E[Y])(Y-E[Y])t]
1189 ;; = E[Y Yt] - 2 \mu \mut + \mu \mut
1190 ;; = E[Y Yt] - \mu \mut
1192 ;; Var Y = E[Y^2] - \mu^2
1195 ;; For initial estimates of covariance of \hat\beta:
1197 ;; \hat\beta = (Xt X)^-1 Xt Y
1198 ;; with E[ \hat\beta ]
1199 ;; = E[ (Xt X)^-1 Xt Y ]
1200 ;; = E[(Xt X)^-1 Xt (X\beta)]
1201 ;; = \beta
1203 ;; So Var[\hat\beta] = ...
1204 ;; (Xt X)
1205 ;; and this gives SE(\beta_i) = (* (sqrt (mref Var i i)) adjustment)
1208 ;; from docs:
1210 (setf *temp-result*
1211 (let ((*default-implementation* :foreign-array))
1212 (let* ((m 10)
1213 (n 10)
1214 (a (rand m n))
1215 (x (rand n 1))
1216 (b (m* a x))
1217 (rcond (* (coerce (expt 2 -52) 'double-float)
1218 (max (nrows a) (ncols a))))
1219 (orig-a (copy a))
1220 (orig-b (copy b))
1221 (orig-x (copy x)))
1222 (list x (gelsy a b rcond))
1223 ;; no applicable conversion?
1224 ;; (m- (#<FA-SIMPLE-VECTOR-DOUBLE (10 x 1))
1225 ;; (#<FA-SIMPLE-VECTOR-DOUBLE (10 x 1)) )
1226 (v- x (first (gelsy a b rcond))))))
1229 (princ *temp-result*)
1231 (setf *temp-result*
1232 (let ((*default-implementation* :lisp-array))
1233 (let* ((m 10)
1234 (n 10)
1235 (a (rand m n))
1236 (x (rand n 1))
1237 (b (m* a x))
1238 (rcond (* (coerce (expt 2 -52) 'double-float)
1239 (max (nrows a) (ncols a))))
1240 (orig-a (copy a))
1241 (orig-b (copy b))
1242 (orig-x (copy x)))
1243 (list x (gelsy a b rcond))
1244 (m- x (first (gelsy a b rcond)))
1246 (princ *temp-result*)
1249 (defparameter *xv*
1250 (make-vector
1252 :type :row ;; default, not usually needed!
1253 :initial-contents '((1d0 3d0 2d0 4d0 3d0 5d0 4d0 6d0))))
1255 (defparameter *y*
1256 (make-vector
1258 :type :row
1259 :initial-contents '((1d0 2d0 3d0 4d0 5d0 6d0 7d0 8d0))))
1261 ;; so something like (NOTE: matrices are transposed to begin with, hence the incongruety)
1262 (defparameter *xtx-1* (m* *xv* (transpose *xv*)))
1263 (defparameter *xty-1* (m* *xv* (transpose *y*)))
1264 (defparameter *rcond-in* (* (coerce (expt 2 -52) 'double-float)
1265 (max (nrows *xtx-1*)
1266 (ncols *xty-1*))))
1268 (defparameter *betahat* (gelsy *xtx-1* *xty-1* *rcond-in*))
1270 ;; (#<LA-SIMPLE-VECTOR-DOUBLE (1 x 1)
1271 ;; 1.293103448275862>
1272 ;; 1)
1274 ;; ## Test case in R:
1275 ;; x <- c( 1.0, 3.0, 2.0, 4.0, 3.0, 5.0, 4.0, 6.0)
1276 ;; y <- c( 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0)
1277 ;; lm(y~x-1)
1278 ;; ## =>
1279 ;; Call:
1280 ;; lm(formula = y ~ x - 1)
1282 ;; Coefficients:
1283 ;; x
1284 ;; 1.293
1286 (first *betahat*))
1291 (type-of #2A((1 2 3 4 5)
1292 (10 20 30 40 50)))
1294 (type-of (rand 10 20))
1296 (typep #2A((1 2 3 4 5)
1297 (10 20 30 40 50))
1298 'matrix-like)
1300 (typep (rand 10 20) 'matrix-like)
1302 (typep #2A((1 2 3 4 5)
1303 (10 20 30 40 50))
1304 'array)
1306 (typep (rand 10 20) 'array)
1309 ;;;;;;;;;;;;;;;;; ===========
1311 (defparameter *my-df-trees*
1312 (make-instance 'dataframe-array
1313 :storage
1314 (listoflist->array
1315 (transpose-listoflist
1316 (rsm.string:file->number-table
1317 (localized-pathto "Data/trees.csv"))))
1318 :doc "This is an interesting dataframe-array that currently fails"))
1320 ;; *my-df-trees*
1322 (defparameter *my-df-trees2*
1323 (make-instance 'dataframe-array
1324 :storage
1325 (listoflist->array
1326 (transpose-listoflist
1327 (rsm.string:file->number-table
1328 (localized-pathto "Data/trees.csv")
1329 :delims ",")))
1330 :doc "This is an interesting dataframe-array that currently fails"))
1331 ;; *my-df-trees2*
1332 ;; (dataset *my-df-trees2*)
1334 (defparameter *my-df-trees2a*
1335 (make-instance 'dataframe-array
1336 :storage
1337 (listoflist->array
1338 (rsm.string:file->number-table
1339 (localized-pathto "Data/trees.csv")
1340 :delims ","))
1341 :doc "This is an interesting dataframe-array that currently fails"))
1343 ;; *my-df-trees2a*
1344 ;; (dataset *my-df-trees2a*)