clean up, checkpointing.
[CommonLispStat.git] / ls-demo.lisp
blobc569fc52bf9352c96c317dd6c57f70f69deed4a1
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-17 22:19:31 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)
19 ;; (asdf:oos 'asdf:compile-op 'cls :force t)
20 (asdf:oos 'asdf:load-op 'cls)
22 (in-package :ls-user)
24 ;; a bit of infrastructure for beginners
25 (defparameter *my-cls-homedir*
26 "/media/disk/Desktop/sandbox/CLS.git/") ;; CHANGE THIS TO LOCALIZE!!
27 (concatenate 'string *my-cls-homedir* "Data/example.csv")
28 ;; implies
29 (defun localized-pathto (x)
30 (check-type x string)
31 (concatenate 'string *my-cls-homedir* x))
34 ;;; DataFrames
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))
54 (defparameter *my-df-2*
55 (make-dataframe #2A((1 2 3 4 5)
56 (10 20 30 40 50))
57 :caselabels (list "x" "y")
58 :varlabels (list "a" "b" "c" "d" "e")
59 :doc "This is another boring dataframe-array"))
61 (caselabels *my-df-1*)
62 (varlabels *my-df-1*)
66 (defparameter *my-df-2*
67 (make-dataframe #2A((a 2 T 4 5)
68 (b 20 nil 40 50))
69 :caselabels (list "x" "y")
70 :varlabels (list "a" "b" "c" "d" "e")
71 :doc "This is another boring dataframe-array"))
73 ;; *my-df-2*
76 ;;; HERE#1
77 ;;; == READ DATA
79 ;;; read in a CSV dataframe...
82 ;; a better approach is:
83 (asdf:oos 'asdf:load-op 'rsm-string)
84 (rsm.string:file->string-table
85 (localized-pathto "Data/example-mixed.csv")
86 :delims ",")
88 (rsm.string:file->number-table
89 (localized-pathto "Data/example-numeric.csv")
90 :delims ",")
92 (rsm.string:file->number-table
93 (localized-pathto "Data/R-chickwts.csv")
94 :delims ",")
95 (rsm.string:file->string-table
96 (localized-pathto "Data/R-chickwts.csv")
97 :delims ",")
99 (defparameter *my-df-2*
100 (make-instance 'dataframe-array
101 :storage
102 (listoflist->array
103 (rsm.string:file->string-table
104 (localized-pathto "Data/example-mixed.csv")))
105 :doc "This is an interesting dataframe-array"))
106 ;; *my-df-2*
108 (defparameter *my-df-3*
109 (make-instance 'dataframe-array
110 :storage
111 (listoflist->array
112 (transpose-listoflist
113 (rsm.string:file->number-table
114 (localized-pathto "Data/example-numeric.csv"))))
115 :doc "This is an interesting dataframe-array"))
116 ;; *my-df-3*
119 (defparameter *my-df-4*
120 (make-instance 'dataframe-array
121 :storage
122 (listoflist->array
123 (rsm.string:file->number-table
124 (localized-pathto "Data/R-chickwts.csv")
125 :delims ","))
126 :doc "This is an interesting dataframe-array that currently fails"))
127 ;; *my-df-4*
129 (aref (dataset *my-df-4*) 0 1)
132 (defparameter *my-df-5*
133 (make-instance 'dataframe-array
134 :storage
135 (listoflist->array
136 (transpose-listoflist
137 (rsm.string:file->number-table
138 (localized-pathto "Data/R-swiss.csv"))))
139 :doc "This is an interesting dataframe-array that currently fails"))
140 ;; *my-df-5*
144 (defparameter *mat-1*
145 (make-matrix 3 3
146 :initial-contents #2A((2d0 3d0 4d0) (3d0 2d0 4d0) (4d0 4d0 5d0))))
148 (defparameter *mat-1*
149 (make-matrix 3 3
150 :initial-contents #2A((2d0 3d0 -4d0)
151 (3d0 2d0 -4d0)
152 (4d0 4d0 -5d0))))
153 (mref *mat-1* 2 0)
155 (defparameter *mat-2*
156 (let ((m (rand 3 3)))
157 (m* m (transpose m))))
159 (axpy 100.0d0 *mat-2* (eye 3 3))
161 (potrf (copy *mat-2*)) ;; factor
162 (potri (copy *mat-2*)) ;; invert
163 (minv-cholesky (copy *mat-2*))
164 (m* (minv-cholesky (copy *mat-2*)) *mat-2*)
166 (defparameter *mat-3*
167 (make-matrix
169 :initial-contents '((16d0 13d0 12d0)
170 (13d0 22d0 7d0)
171 (12d0 7d0 17d0))))
173 (potrf (copy *mat-3*)) ;; factor
176 *mat-3* =>
177 #<LA-SIMPLE-MATRIX-DOUBLE 3 x 3
178 16.0 13.0 12.0
179 13.0 22.0 7.0
180 12.0 7.0 17.0>
182 (potrf (copy *mat-3*)) =>
183 (#<LA-SIMPLE-MATRIX-DOUBLE 3 x 3
184 4.0 3.25 3.0
185 13.0 3.3819373146171707 -0.8131433980500301
186 12.0 7.0 2.7090215603069034>
187 "U" NIL)
189 ;; and compare with...
191 > testm <- matrix(data=c(16,13,12,13,22,7,12,7,17),nrow=3)
192 > chol(testm)
193 [,1] [,2] [,3]
194 [1,] 4 3.250000 3.0000000
195 [2,] 0 3.381937 -0.8131434
196 [3,] 0 0.000000 2.7090216
199 ;; which suggests that the major difference is that R zero's out the
200 ;; appropriate terms, and that CLS does not.
204 (potri (copy *mat-2*)) ;; invert
205 (minv-cholesky (copy *mat-2*))
206 (m* (minv-cholesky (copy *mat-2*)) *mat-2*)
210 (lu-decomp #2A((2 3 4) (1 2 4) (2 4 5)))
211 ;; => (#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)
212 (lu-solve
213 (lu-decomp #2A((2 3 4) (1 2 4) (2 4 5)))
214 #(2 3 4))
215 ;; => #(-2.333333333333333 1.3333333333333335 0.6666666666666666)
217 (getrf
218 (make-matrix 3 3
219 :initial-contents #2A((2d0 3d0 4d0) (1d0 2d0 4d0) (2d0 4d0 5d0))))
221 #| => ; so not so good for the vector, but matrix matches.
222 (#<LA-SIMPLE-MATRIX-DOUBLE 3 x 3
223 2.0 3.0 4.0
224 1.0 1.0 1.0
225 0.5 0.5 1.5>
226 #<FNV-INT32 (3) 1 3 3> NIL)
229 (msolve-lu
230 (make-matrix 3 3
231 :initial-contents #2A((2d0 3d0 4d0)
232 (1d0 2d0 4d0)
233 (2d0 4d0 5d0)))
234 (make-vector 3 :type :column
235 :initial-contents '((2d0)
236 (3d0)
237 (4d0))))
239 #| =>
240 #<LA-SIMPLE-VECTOR-DOUBLE (3 x 1)
241 -2.3333333333333335
242 1.3333333333333335
243 0.6666666666666666>
248 ;;; LU common applications
250 (defun minv-lu (a)
251 "invert A using LU Factorization"
252 (let ((a-fac (getrf (copy a))))
253 (first (getri (first a-fac) (second a-fac)))))
255 #+nil (progn
256 (let ((m1 (rand 3 3)))
257 (m* m1 (minv-lu m1))))
259 (defun msolve-lu (a b)
260 "Compute `x1' solving `A x = b', with LU factorization."
261 (let ((a-fac (getrf (copy a))))
262 (first (getrs (first a-fac) b (second a-fac)))))
266 ;; (inverse #2A((2 3 4) (1 2 4) (2 4 5)))
267 ;; #2A((2.0 -0.33333333333333326 -1.3333333333333335)
268 ;; (-1.0 -0.6666666666666666 1.3333333333333333)
269 ;; (0.0 0.6666666666666666 -0.3333333333333333))
271 (minv-lu
272 (make-matrix
274 :initial-contents #2A((2d0 3d0 4d0)
275 (1d0 2d0 4d0)
276 (2d0 4d0 5d0))))
280 #<LA-SIMPLE-MATRIX-DOUBLE 3 x 3
281 2.0 -0.3333333333333333 -1.3333333333333333
282 -1.0 -0.6666666666666666 1.3333333333333333
283 0.0 0.6666666666666666 -0.3333333333333333>
285 ;; so is correct.
289 ;;;;;HERE#2
291 (factorize
292 (make-matrix 3 3
293 :initial-contents #2A((2d0 3d0 4d0)
294 (1d0 2d0 4d0)
295 (2d0 4d0 5d0)))
296 :by :svd)
298 ;; (sv-decomp #2A((2 3 4) (1 2 4) (2 4 5)))
299 ;; (#2A((-0.5536537653489974 0.34181191712789266 -0.7593629708013371)
300 ;; (-0.4653437312661058 -0.8832095891230851 -0.05827549615722014)
301 ;; (-0.6905959164998124 0.3211003503429828 0.6480523475178517))
302 ;; #(9.699290438141343 0.8971681569301373 0.3447525123483081)
303 ;; #2A((-0.30454218417339873 0.49334669582252344 -0.8147779426198863)
304 ;; (-0.5520024849987308 0.6057035911404464 0.5730762743603965)
305 ;; (-0.7762392122368734 -0.6242853493399995 -0.08786630745236332))
306 ;; T)
310 (qr-decomp #2A((2 3 4) (1 2 4) (2 4 5)))
311 ;; (#2A((-0.6666666666666665 0.7453559924999298 5.551115123125783e-17)
312 ;; (-0.3333333333333333 -0.2981423969999719 -0.894427190999916)
313 ;; (-0.6666666666666666 -0.5962847939999439 0.44721359549995787))
314 ;; #2A((-3.0 -5.333333333333334 -7.333333333333332)
315 ;; (0.0 -0.7453559924999292 -1.1925695879998877)
316 ;; (0.0 0.0 -1.3416407864998738)))
318 (rcondest #2A((2 3 4) (1 2 4) (2 4 5)))
319 ;; 6.8157451e7
320 ;;; CURRENTLY FAILS!!
322 (eigen #2A((2 3 4) (1 2 4) (2 4 5)))
323 ;; (#(10.656854249492381 -0.6568542494923802 -0.9999999999999996)
324 ;; (#(0.4999999999999998 0.4999999999999997 0.7071067811865475)
325 ;; #(-0.49999999999999856 -0.5000000000000011 0.7071067811865474)
326 ;; #(0.7071067811865483 -0.7071067811865466 -1.2560739669470215e-15))
327 ;; NIL)
329 (spline #(1.0 1.2 1.3 1.8 2.1 2.5)
330 #(1.2 2.0 2.1 2.0 1.1 2.8) :xvals 6)
331 ;; ((1.0 1.3 1.6 1.9 2.2 2.5)
332 ;; (1.2 2.1 2.2750696543866313 1.6465231041904045 1.2186576148879609 2.8))
334 ;;; using KERNEL-SMOOTH-FRONT, not KERNEL-SMOOTH-CPORT
335 (kernel-smooth #(1.0 1.2 1.3 1.8 2.1 2.5)
336 #(1.2 2.0 2.1 2.0 1.1 2.8) :xvals 5)
337 ;; ((1.0 1.375 1.75 2.125 2.5)
338 ;; (1.6603277642110226 1.9471748095239771 1.7938127405752287
339 ;; 1.5871511322219498 2.518194783156392))
341 (kernel-dens #(1.0 1.2 2.5 2.1 1.8 1.2) :xvals 5)
342 ;; ((1.0 1.375 1.75 2.125 2.5)
343 ;; (0.7224150453621405 0.5820045548233707 0.38216411702854214
344 ;; 0.4829822708587095 0.3485939156929503))
346 (fft #(1.0 1.2 2.5 2.1 1.8))
347 ;; #(#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))
349 (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))
350 ;; (#(1.0 1.2 1.2 1.8 2.1 2.5))
354 ;;;; Special functions
356 ;; Log-gamma function
358 (log-gamma 3.4) ;;1.0923280596789584
362 ;;;; Probability functions
364 ;; looking at these a bit more, perhaps a more CLOSy style is needed, i.e.
365 ;; (quantile :list-or-cons loc :type type (one of 'empirical 'normal 'cauchy, etc...))
366 ;; similar for the cdf, density, and rand.
367 ;; Probably worth figuring out how to add a new distribution
368 ;; efficiently, i.e. by keeping some kind of list.
370 ;; Normal distribution
372 (normal-quant 0.95) ;;1.6448536279366268
373 (normal-cdf 1.3) ;;0.9031995154143897
374 (normal-dens 1.3) ;;0.17136859204780736
375 (normal-rand 2) ;;(-0.40502015f0 -0.8091404f0)
377 (bivnorm-cdf 0.2 0.4 0.6) ;;0.4736873734160288
379 ;; Cauchy distribution
381 (cauchy-quant 0.95) ;;6.313751514675031
382 (cauchy-cdf 1.3) ;;0.7912855998398473
383 (cauchy-dens 1.3) ;;0.1183308127104695
384 (cauchy-rand 2) ;;(-1.06224644160405 -0.4524695943939537)
386 ;; Gamma distribution
388 (gamma-quant 0.95 4.3) ;;8.178692439291645
389 (gamma-cdf 1.3 4.3) ;;0.028895150986674906
390 (gamma-dens 1.3 4.3) ;;0.0731517686447374
391 (gamma-rand 2 4.3) ;;(2.454918912880936 4.081365384357454)
393 ;; Chi-square distribution
395 (chisq-quant 0.95 3) ;;7.814727903379012
396 (chisq-cdf 1 5) ;;0.03743422675631789
397 (chisq-dens 1 5) ;;0.08065690818083521
398 (chisq-rand 2 4) ;;(1.968535826180572 2.9988646156942997)
400 ;; Beta distribution
402 (beta-quant 0.95 3 2) ;;0.9023885371149876
403 (beta-cdf 0.4 2 2.4) ;;0.4247997418541529
404 (beta-dens 0.4 2 2.4) ;;1.5964741858913518
405 (beta-rand 2 2 2.4) ;;(0.8014897077282279 0.6516371997922659)
407 ;; t distribution
409 (t-quant 0.95 3) ;;2.35336343484194
410 (t-cdf 1 2.3) ;;0.794733624298342
411 (t-dens 1 2.3) ;;0.1978163816318102
412 (t-rand 2 2.3) ;;(-0.34303672776089306 -1.142505872436518)
414 ;; F distribution
416 (f-quant 0.95 3 5) ;;5.409451318117459
417 (f-cdf 1 3.2 5.4) ;;0.5347130905510765
418 (f-dens 1 3.2 5.4) ;;0.37551128864591415
419 (f-rand 2 3 2) ;;(0.7939093442091963 0.07442694152491144)
421 ;; Poisson distribution
423 (poisson-quant 0.95 3.2) ;;6
424 (poisson-cdf 1 3.2) ;;0.17120125672252395
425 (poisson-pmf 1 3.2) ;;0.13043905274097067
426 (poisson-rand 5 3.2) ;;(2 1 2 0 3)
428 ;; Binomial distribution
430 (binomial-quant 0.95 3 0.4) ;;; DOESN'T RETURN
431 (binomial-quant 0 3 0.4) ;;; -2147483648
432 (binomial-cdf 1 3 0.4) ;;0.6479999999965776
433 (binomial-pmf 1 3 0.4) ;;0.4320000000226171
434 (binomial-rand 5 3 0.4) ;;(2 2 0 1 2)
436 ;;;; OBJECT SYSTEM
438 (in-package :ls-user)
439 (defproto *test-proto*)
440 *test-proto*
441 (defmeth *test-proto* :make-data (&rest args) nil)
443 (defparameter my-proto-instance nil)
444 (setf my-proto-instance (send *test-proto* :new))
445 (send *test-proto* :own-slots)
446 (lsos::ls-object-slots *test-proto*)
447 (lsos::ls-object-methods *test-proto*)
448 (lsos::ls-object-parents *test-proto*)
449 (lsos::ls-object-preclist *test-proto*)
450 ;;; The following fail and I do not know why?
451 (send *test-proto* :has-slot 'proto-name)
452 (send *test-proto* :has-slot 'PROTO-NAME)
453 (send *test-proto* :has-slot 'make-data)
454 (send *test-proto* :has-slot 'MAKE-DATA)
455 (send *test-proto* :has-method 'make-data)
456 (send *test-proto* :has-method 'MAKE-DATA)
459 (defproto2 *test-proto3* (list) (list) (list) "test doc" t)
460 (defproto2 *test-proto4*)
461 *test-proto2*
462 (defmeth *test-proto* :make-data (&rest args) nil)
464 (defparameter my-proto-instance nil)
465 (setf my-proto-instance (send *test-proto* :new))
466 (send *test-proto* :own-slots)
467 (send *test-proto* :has-slot 'proto-name)
468 (send *test-proto* :has-slot 'PROTO-NAME)
471 ;;;; Testing
473 (in-package :lisp-stat-unittests)
474 (testsuites)
475 (print-tests)
476 (run-tests)
477 (last-test-status)
478 ;;(failures)
480 (describe (run-tests :suite 'lisp-stat-ut-testsupport))
481 (describe (run-tests :suite 'lisp-stat-ut-testsupport2))
483 (testsuite-tests 'lisp-stat-ut)
484 (run-tests :suite 'lisp-stat-ut)
485 (describe (run-tests :suite 'lisp-stat-ut))
487 (run-tests :suite 'lisp-stat-ut-probdistn)
488 (describe (run-tests :suite 'lisp-stat-ut-probdistn))
489 (run-tests :suite 'lisp-stat-ut-spec-fns)
490 (describe (run-tests :suite 'lisp-stat-ut-spec-fns))
492 (find-testsuite 'lisp-stat-ut-lin-alg)
493 (testsuite-tests 'lisp-stat-ut-lin-alg)
494 (run-tests :suite 'lisp-stat-ut-lin-alg)
495 (describe (run-tests :suite 'lisp-stat-ut-lin-alg))
497 ;;;; Data Analysis test
499 (in-package :ls-user)
501 ;; LispStat 1 approach to variables
503 (progn
504 (def iron (list 61 175 111 124 130 173 169 169 160 224 257 333 199))
505 iron
506 (def aluminum (list 13 21 24 23 64 38 33 61 39 71 112 88 54))
507 aluminum
508 (def absorbtion (list 4 18 14 18 26 26 21 30 28 36 65 62 40))
509 absorbtion
511 ;; LispStat 1 approach to data frames... (list of lists).
513 (DEF DIABETES
514 (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)
515 (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)
516 (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)
517 (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))))
520 (DEF DLABS (QUOTE ("GLUFAST" "GLUTEST" "INSTEST" "CCLASS")))
521 (format t "loaded data.~%")
522 ) ;; eval at this point.
524 ;; Simple univariate variable-specific descriptions.
525 (fivnum absorbtion)
526 (median absorbtion)
527 (sort-data absorbtion)
528 (rank absorbtion)
529 (standard-deviation absorbtion)
530 (interquartile-range absorbtion)
532 (lisp-stat-matrix::bind-columns aluminum iron)
533 (bind-columns aluminum iron)
534 (apply #'bind-columns (list aluminum iron))
535 (lisp-stat-matrix::bind-columns #2a((1 2)(3 4)) #(5 6))
536 (bind-columns #2a((1 2)(3 4)) #(5 6))
539 (defparameter fit1 nil)
540 (setf fit1 (regression-model absorbtion iron))
541 (send fit1 :display)
542 (send fit1 :residuals)
544 iron
545 (defparameter fit1a nil)
546 (setf fit1a (regression-model absorbtion iron :print nil))
547 (send fit1a :doc)
548 ;; (setf (send fit1a :doc) "this") ;; FIXME: this error...
549 (send fit1a :doc "this") ;; FIXME: this is a more natural
550 (send fit1a :doc)
551 (send fit1a :x)
552 (send fit1a :y)
553 (send fit1a :compute)
554 (send fit1a :sweep-matrix)
555 (send fit1a :basis)
556 (send fit1a :residuals)
557 (send fit1a :display)
559 #+nil(progn
560 ;; syntax example
561 (array-dimension #2A ((1)) 0)
564 ;;; FIXME: need to get multiple-linear regression working -- clearly
565 ;;; simple linear is working above!
566 (defvar m nil "holding variable.")
567 (def m (regression-model (list iron aluminum) absorbtion :print nil))
568 (send m :compute)
569 (send m :sweep-matrix)
570 (format t "~%~A~%" (send m :sweep-matrix))
572 ;; ERROR... FIX-ME!!
573 (send m :basis) ;; this should be positive?
574 (send m :coef-estimates)
576 (send m :display)
577 (def m (regression-model (bind-columns iron aluminum) absorbtion))
578 (send m :help)
579 (send m :help :display)
580 (send m :help :basis)
581 ;; No graphics! But handle the error gracefully...
582 (send m :plot-residuals)
585 (typep aluminum 'sequence)
586 (typep iron 'sequence)
587 (matrixp iron)
589 *variables*
591 (variables)
592 (undef 'iron)
593 (variables)
595 ;;; Plotting!
597 (asdf:oos 'asdf:compile-op 'cl-cairo2 :force t)
598 (asdf:oos 'asdf:load-op 'cl-cairo2)
600 ;; The above can be used to generate PDF, PS, PNG, and X11/Microsoft
601 ;; displays (the latter being a proof of concept, of limited use for
602 ;; "real work".
604 ;; and this below, as well.
605 (asdf:oos 'asdf:load-op 'cl-plplot)
607 ;;; Using R!
609 (asdf:oos 'asdf:compile-op 'rclg :force t)
610 (asdf:oos 'asdf:load-op 'rclg)
613 (in-package :rclg-user)
615 ;; rclg-init::*r-started*
617 ;;;#3 Start R within Lisp
619 (start-rclg)
620 ;; rclg-init::*r-started*
621 (rclg-init::check-stack)
622 (r "Cstack_info")
623 (defparameter *x* (r seq 1 10))
624 (defparameter *y* (r rnorm 10))
626 (r plot *x* *y*)
629 (defparameter *r-version* (r "version"))
631 ;; This is for illustrative purposes only. It is not a "good" use of rnbi.
632 ;; Really, you'll want rnbi to hold anonymous intermeditae results, like:
633 (r plot *x* (rnbi rnorm 10))
635 (r "Sys.getenv" "LD_LIBRARY_PATH")
636 (r "Sys.getenv" "LD_PRELOAD")
638 (r "ls")
639 (r ls)
640 (r "search")
642 (r "geterrmessage")
644 (r "library" "stats")
645 (r library "MASS")
646 (r "library" "Biobase")
648 (setf my.lib "Biobase")
649 my.lib
650 (r library my.lib)
652 (r "ls")
654 (r "print.default" 3)
655 (r "rnorm" 10)
657 ;; Working in the R space
659 (r assign "x" 5)
660 (r assign "x2" (list 1 2 3 5))
662 (r assign "x2" #(1 2 3 5 3 4 5))
663 (r assign "z" "y") ;; unlike the above, this assigns character data
664 (r "ls")
665 (r ls)
667 (setf my.r.x2 (r get "x2")) ;; moving data from R to CL
668 (r assign "x2" my.r.x2) ;; moving data from CL to R
670 ;; The following is not the smartest thing to do!
671 ;;(r q)
675 ;;; How might we do statistics with Common Lisp?
676 ;;; How might we work with a data.frame?
677 ;;; What could the structures be?
678 ;;; How much hinting, and of what type, should drive the data
679 ;;; analysis?
681 (defpackage :my-data-analysis-example
682 (:documentation "Example work-package for a data analysis")
683 (:use :common-lisp :lisp-stat)
684 (:export results figures report))
686 (in-package :my-data-analysis-example)
688 (defvar my-dataset1 (read-file "data/test1.lisp"))
689 ;; or
690 (defvar my-dataset2 (read-file "data/test1.csv" :type 'csv))
692 ;;; manipulate
694 (setf my-dataset2 (set-description my-datasets2
695 :dependent-variables (list of symbols)))
696 (setf my-dataset2 (set-description my-datasets2
697 :independent-variables (list of symbols)))
699 ;; the following could be true in many cases.
700 (assert
701 (list-intersection (get-description my-datasets2 :independent-variables)
702 (get-description my-datasets2 :dependent-variables)))
704 ;; but we could phrase better,i.e.
706 (get-description
707 my-datasets2
708 :predicate-list-on-variable-metadata (list (and 'independent-variables
709 'dependent-variables)))
712 ;; statistical relations re: input/output, as done above, is one
713 ;; issue, another one is getting the right approach for statistical
714 ;; typing, i.e.
715 (get-description
716 my-datasets2
717 :predicate-list-on-variable-metadata (list 'ordinal-variables))
720 ;; so we could use a set of logical ops to selection from variable
721 ;; metadata, i.e.
722 ;; and, or, not
723 ;; do we really need the simplifying extensions?
726 ;;; output to REPL
728 (report my-dataset1 :style 'five-num)
729 (report my-dataset1 :style 'univariate)
730 (report my-dataset1 :style 'bivariate)
731 (report my-dataset1 :style 'metadata)
733 ;;; to file?
735 (report my-dataset1
736 :style 'five-num
737 :format 'pdf
738 :stream (filename-as-stream "my-dataset1-5num.pdf"))
739 (report my-dataset1 :style 'univariate)
740 (report my-dataset1 :style 'bivariate)
741 (report my-dataset1 :style 'metadata)
743 ;;; so report could handle datasets... and models?
745 (report my-model :style 'formula)
746 (report my-model :style 'simulate
747 (list :parameters (:eta 5 :mu 4 :sigma (list 2 1 0.5))
748 :number-of-reps 10))
749 ;; should return a list of parameters along with range information,
750 ;; useful for auto-building the above. Note that there are 3 types
751 ;; of parameters that can be considered -- we can have values which
752 ;; define ddata, we can have values which define fixed values and some
753 ;; could be things tht we estimate.
756 (defgeneric report (object &optional style format stream)
757 (:documentation "method for reporting on data"))
759 (defmethod report ((object dataset)
760 (style report-dataset-style-type)
761 (format output-format-type)
762 ((stream *repl*) output-stream-type))
763 "dataset reporting")
766 (defmethod report ((object model)
767 (style report-model-style-type)
768 (format output-format-type)
769 ((stream *repl*) output-stream-type))
770 "model reporting")
772 (defmethod report ((object analysis-instance)
773 (style report-analysis-style-type)
774 (format output-format-type)
775 ((stream *repl*) output-stream-type))
776 "model + dataset reporting")
779 ;; parameters are just things which get filled with values, repeatedly
780 ;; with data, or by considering to need estimation.
781 (parameters my-model)
782 (parameters my-model :type 'data)
783 (parameters my-model :type 'fixed)
784 (parameters my-model :type 'estimate)
785 (parameters my-model :type '(estimate fixed))
786 (parameters my-model :list-types) ;; useful for list-based extraction
787 ;; of particular types
789 (setf my-model-data-instance
790 (compute model data :specification (list :spec 'linear-model
791 :depvar y
792 :indepvar (list x1 x2))))
793 (report my-model-data-instance)
796 ;;; So how might we use this? Probably need to consider the
797 ;;; serialization of any lisp objects generated, perhaps via some form
798 ;;; of memoization...?
799 (in-package :cl-user)
801 (my-data-analysis-example:report :type 'full)
802 (my-data-analysis-example:report :type 'summary)
803 (my-data-analysis-example:figures :type 'pdf :file "results-figs.pdf")
805 (my-data-analysis-example:report)
807 ;;; more stuff
809 (send m :display)
810 (def m (regression-model (bind-columns iron aluminum) absorbtion))
811 (send m :help)
812 (send m :help :display)
813 (send m :help :basis)
815 (send m :plot-residuals)
817 (progn
818 ;; General Lisp, there is also a need to add, remove symbols from the
819 ;; workspace/namespace. This is a fundamental skill, similar to
820 ;; stopping, which is critical.
822 ;; boundp, fboundp
823 ;; makunbound, fmakunbound
827 (progn
828 ;;; A study in array vs list access
829 (defparameter *x* (list 1 2 3))
830 (defparameter *y* #(1 2 3))
831 (defparameter *z* (list 1 (list 2 3) (list 4 5 (list 6 7)) ))
832 (length *x*)
833 (length *y*)
834 (length *z*) ; => need a means to make this 7.
835 (length (reduce #'cons *z*)) ; => not quite -- missing iterative
837 (nelts *x*)
838 (nth 1 *x*)
839 (aref *y* 1)
840 (setf (nth 1 *x*) 6)
842 (setf (aref *y* 1) 6)
846 (in-package :ls-user)
848 (progn
849 (defparameter *x* (make-vector 5 :initial-contents '((1d0 2d0 3d0 4d0 5d0))))
850 ;; estimating a mean, simple way.
851 (/ (loop for i from 0 to (- (nelts *x*) 1)
852 summing (vref *x* i))
853 (nelts *x*))
855 (defun mean (x)
856 (checktype x 'vector-like)
857 (/ (loop for i from 0 to (- (nelts *x*) 1)
858 summing (vref *x* i))
859 (nelts *x*)))
861 ;; estimating variance, Moments
862 (let ((meanx (mean *x*))
863 (n (nelts *x*)))
864 (/ (loop for i from 0 to (1- n)
865 summing (* (- (vref *x* i) meanx)
866 (- (vref *x* i) meanx)))
869 ;; estimating variance, Moments
870 (let ((meanx (mean *x*))
871 (nm1 (1- (nelts *x*))))
872 (/ (loop for i from 0 to nm1
873 summing (* (- (vref *x* i) meanx)
874 (- (vref *x* i) meanx) ))
875 nm1))
879 ;;;;;;;;;;;;;;; Data stuff
881 (progn ;; Data setup
883 ;; Making data-frames (i.e. cases (rows) by variables (columns))
884 ;; takes a bit of getting used to. For this, it is important to
885 ;; realize that we can do the following:
886 ;; #1 - consider the possibility of having a row, and transposing
887 ;; it, so the list-of-lists is: ((1 2 3 4 5)) (1 row, 5 columns)
888 ;; #2 - naturally list-of-lists: ((1)(2)(3)(4)(5)) (5 rows, 1 column)
889 ;; see src/data/listoflist.lisp for code to process this particular
890 ;; data structure.
891 (defparameter *indep-vars-1-matrix*
892 (transpose (make-matrix 1 (length iron)
893 :initial-contents
894 (list (mapcar #'(lambda (x) (coerce x 'double-float))
895 iron))))
896 "creating iron into double float, straightforward")
898 (documentation '*indep-vars-1-matrix* 'variable)
899 ;; *indep-vars-1-matrix*
901 ;; or directly:
902 (defparameter *indep-vars-1a-matrix*
903 (make-matrix (length iron) 1
904 :initial-contents
905 (mapcar #'(lambda (x) (list (coerce x 'double-float)))
906 iron)))
907 ;; *indep-vars-1a-matrix*
909 ;; and mathematically, they seem equal:
910 (m= *indep-vars-1-matrix* *indep-vars-1a-matrix*) ; => T
911 ;; but of course not completely...
912 (eql *indep-vars-1-matrix* *indep-vars-1a-matrix*) ; => NIL
913 (eq *indep-vars-1-matrix* *indep-vars-1a-matrix*) ; => NIL
915 ;; and verify...
916 (print *indep-vars-1-matrix*)
917 (print *indep-vars-1a-matrix*)
919 (documentation 'lisp-matrix:bind2 'function) ; by which we mean:
920 (documentation 'bind2 'function)
921 (bind2 *indep-vars-1-matrix* *indep-vars-1a-matrix* :by :column) ; 2 col
922 (bind2 *indep-vars-1-matrix* *indep-vars-1a-matrix* :by :row) ; 1 long col
924 ;; the weird way
925 (defparameter *indep-vars-2-matrix*
926 (transpose (make-matrix 2 (length iron)
927 :initial-contents
928 (list
929 (mapcar #'(lambda (x) (coerce x 'double-float))
930 iron)
931 (mapcar #'(lambda (x) (coerce x 'double-float))
932 aluminum)))))
933 ;; *indep-vars-2-matrix*
935 ;; the "right"? way
936 (defparameter *indep-vars-2-matrix*
937 (make-matrix (length iron) 2
938 :initial-contents
939 (mapcar #'(lambda (x y)
940 (list (coerce x 'double-float)
941 (coerce y 'double-float)))
942 iron aluminum)))
943 ;; *indep-vars-2-matrix*
946 ;; The below FAILS due to coercion issues; it just isn't lispy, it's R'y.
948 (defparameter *dep-var* (make-vector (length absorbtion)
949 :initial-contents (list absorbtion)))
951 ;; BUT below, this should be the right type.
952 (defparameter *dep-var*
953 (make-vector (length absorbtion)
954 :type :row
955 :initial-contents
956 (list
957 (mapcar #'(lambda (x) (coerce x 'double-float))
958 absorbtion))))
959 ;; *dep-var*
962 (defparameter *dep-var-int*
963 (make-vector (length absorbtion)
964 :type :row
965 :element-type 'integer
966 :initial-contents (list absorbtion)))
968 (typep *dep-var* 'matrix-like) ; => T
969 (typep *dep-var* 'vector-like) ; => T
971 (typep *indep-vars-1-matrix* 'matrix-like) ; => T
972 (typep *indep-vars-1-matrix* 'vector-like) ; => T
973 (typep *indep-vars-2-matrix* 'matrix-like) ; => T
974 (typep *indep-vars-2-matrix* 'vector-like) ; => F
976 iron
977 ;; following fails, need to ensure that we work on list elts, not just
978 ;; elts within a list:
980 ;; (coerce iron 'real)
982 ;; the following is a general list-conversion coercion approach -- is
983 ;; there a more efficient way?
984 ;; (coerce 1 'real)
985 ;; (mapcar #'(lambda (x) (coerce x 'double-float)) iron)
987 (princ "Data Set up"))
992 (progn ;; Data setup
994 (describe 'make-matrix)
996 (defparameter *indep-vars-2-matrix*
997 (make-matrix (length iron) 2
998 :initial-contents
999 (mapcar #'(lambda (x y)
1000 (list (coerce x 'double-float)
1001 (coerce y 'double-float)))
1002 iron aluminum)))
1005 (defparameter *dep-var*
1006 (make-vector (length absorbtion)
1007 :type :row
1008 :initial-contents
1009 (list
1010 (mapcar #'(lambda (x) (coerce x 'double-float))
1011 absorbtion))))
1013 (make-dataframe *dep-var*)
1014 (make-dataframe (transpose *dep-var*))
1016 (defparameter *dep-var-int*
1017 (make-vector (length absorbtion)
1018 :type :row
1019 :element-type 'integer
1020 :initial-contents (list absorbtion)))
1023 (defparameter *xv+1a*
1024 (make-matrix
1026 :initial-contents #2A((1d0 1d0)
1027 (1d0 3d0)
1028 (1d0 2d0)
1029 (1d0 4d0)
1030 (1d0 3d0)
1031 (1d0 5d0)
1032 (1d0 4d0)
1033 (1d0 6d0))))
1035 (defparameter *xv+1b*
1036 (bind2
1037 (ones 8 1)
1038 (make-matrix
1040 :initial-contents '((1d0)
1041 (3d0)
1042 (2d0)
1043 (4d0)
1044 (3d0)
1045 (5d0)
1046 (4d0)
1047 (6d0)))
1048 :by :column))
1050 (m= *xv+1a* *xv+1b*) ; => T
1052 (princ "Data Set up"))
1056 ;;;; LM
1058 (progn
1060 (defparameter *y*
1061 (make-vector
1063 :type :row
1064 :initial-contents '((1d0 2d0 3d0 4d0 5d0 6d0 7d0 8d0))))
1067 (defparameter *xv+1*
1068 (make-matrix
1070 :initial-contents '((1d0 1d0)
1071 (1d0 3d0)
1072 (1d0 2d0)
1073 (1d0 4d0)
1074 (1d0 3d0)
1075 (1d0 5d0)
1076 (1d0 4d0)
1077 (1d0 6d0))))
1080 ;; so something like (NOTE: matrices are transposed to begin with, hence the incongruety)
1081 (defparameter *xtx-2* (m* (transpose *xv+1*) *xv+1*))
1082 ;; #<LA-SIMPLE-MATRIX-DOUBLE 2 x 2
1083 ;; 8.0d0 28.0d0
1084 ;; 28.0d0 116.0d0>
1086 (defparameter *xty-2* (m* (transpose *xv+1*) (transpose *y*)))
1087 ;; #<LA-SIMPLE-VECTOR-DOUBLE (2 x 1)
1088 ;; 36.0d0
1089 ;; 150.0d0>
1091 (defparameter *rcond-2* 0.000001)
1092 (defparameter *betahat-2* (gelsy *xtx-2* *xty-2* *rcond-2*))
1093 ;; *xtx-2* => "details of complete orthogonal factorization"
1094 ;; according to man page:
1095 ;; #<LA-SIMPLE-MATRIX-DOUBLE 2 x 2
1096 ;; -119.33147112141039d0 -29.095426104883202d0
1097 ;; 0.7873402682880205d0 -1.20672274167718d0>
1099 ;; *xty-2* => output becomes solution:
1100 ;; #<LA-SIMPLE-VECTOR-DOUBLE (2 x 1)
1101 ;; -0.16666666666668312d0
1102 ;; 1.333333333333337d0>
1104 *betahat-2* ; which matches R, see below
1106 (documentation 'gelsy 'function)
1109 ;; (#<LA-SIMPLE-VECTOR-DOUBLE (2 x 1)
1110 ;; -0.16666666666668312 1.333333333333337>
1111 ;; 2)
1113 ;; ## Test case in R:
1114 ;; x <- c( 1.0, 3.0, 2.0, 4.0, 3.0, 5.0, 4.0, 6.0)
1115 ;; y <- c( 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0)
1116 ;; lm(y~x)
1117 ;; ## => Call: lm(formula = y ~ x)
1119 ;; Coefficients: (Intercept) x
1120 ;; -0.1667 1.3333
1122 ;; summary(lm(y~x))
1123 ;; ## =>
1125 ;; Call:
1126 ;; lm(formula = y ~ x)
1128 ;; Residuals:
1129 ;; Min 1Q Median 3Q Max
1130 ;; -1.833e+00 -6.667e-01 -3.886e-16 6.667e-01 1.833e+00
1132 ;; Coefficients:
1133 ;; Estimate Std. Error t value Pr(>|t|)
1134 ;; (Intercept) -0.1667 1.1587 -0.144 0.89034
1135 ;; x 1.3333 0.3043 4.382 0.00466 **
1136 ;; ---
1137 ;; Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
1139 ;; Residual standard error: 1.291 on 6 degrees of freedom
1140 ;; Multiple R-squared: 0.7619, Adjusted R-squared: 0.7222
1141 ;; F-statistic: 19.2 on 1 and 6 DF, p-value: 0.004659
1145 ;; which suggests one might do (modulo ensuring correct
1146 ;; orientations). When this is finalized, it should migrate to
1147 ;; CLS.
1151 (defparameter *n* 20) ; # rows = # obsns
1152 (defparameter *p* 10) ; # cols = # vars
1153 (defparameter *x-temp* (rand *n* *p*))
1154 (defparameter *b-temp* (rand *p* 1))
1155 (defparameter *y-temp* (m* *x-temp* *b-temp*))
1156 ;; so Y=Xb + \eps
1157 (defparameter *rcond* (* (coerce (expt 2 -52) 'double-float)
1158 (max (nrows *x-temp*) (ncols *y-temp*))))
1159 (defparameter *orig-x* (copy *x-temp*))
1160 (defparameter *orig-b* (copy *b-temp*))
1161 (defparameter *orig-y* (copy *y-temp*))
1163 (defparameter *lm-result* (lm *x-temp* *y-temp*))
1164 (princ (first *lm-result*))
1165 (princ (second *lm-result*))
1166 (princ (third *lm-result*))
1167 (v= (third *lm-result*)
1168 (v- (first (first *lm-result*))
1169 (first (second *lm-result*))))
1174 ;; Some issues exist in the LAPACK vs. LINPACK variants, hence R
1175 ;; uses LINPACK primarily, rather than LAPACK. See comments in R
1176 ;; source for issues.
1179 ;; Goal is to start from X, Y and then realize that if
1180 ;; Y = X \beta, then, i.e. 8x1 = 8xp px1 + 8x1
1181 ;; XtX \hat\beta = Xt Y
1182 ;; so that we can solve the equation W \beta = Z where W and Z
1183 ;; are known, to estimate \beta.
1185 ;; the above is known to be numerically instable -- some processing
1186 ;; of X is preferred and should be done prior. And most of the
1187 ;; transformation-based work does precisely that.
1189 ;; recall: Var[Y] = E[(Y - E[Y])(Y-E[Y])t]
1190 ;; = E[Y Yt] - 2 \mu \mut + \mu \mut
1191 ;; = E[Y Yt] - \mu \mut
1193 ;; Var Y = E[Y^2] - \mu^2
1196 ;; For initial estimates of covariance of \hat\beta:
1198 ;; \hat\beta = (Xt X)^-1 Xt Y
1199 ;; with E[ \hat\beta ]
1200 ;; = E[ (Xt X)^-1 Xt Y ]
1201 ;; = E[(Xt X)^-1 Xt (X\beta)]
1202 ;; = \beta
1204 ;; So Var[\hat\beta] = ...
1205 ;; (Xt X)
1206 ;; and this gives SE(\beta_i) = (* (sqrt (mref Var i i)) adjustment)
1209 ;; from docs:
1211 (setf *temp-result*
1212 (let ((*default-implementation* :foreign-array))
1213 (let* ((m 10)
1214 (n 10)
1215 (a (rand m n))
1216 (x (rand n 1))
1217 (b (m* a x))
1218 (rcond (* (coerce (expt 2 -52) 'double-float)
1219 (max (nrows a) (ncols a))))
1220 (orig-a (copy a))
1221 (orig-b (copy b))
1222 (orig-x (copy x)))
1223 (list x (gelsy a b rcond))
1224 ;; no applicable conversion?
1225 ;; (m- (#<FA-SIMPLE-VECTOR-DOUBLE (10 x 1))
1226 ;; (#<FA-SIMPLE-VECTOR-DOUBLE (10 x 1)) )
1227 (v- x (first (gelsy a b rcond))))))
1230 (princ *temp-result*)
1232 (setf *temp-result*
1233 (let ((*default-implementation* :lisp-array))
1234 (let* ((m 10)
1235 (n 10)
1236 (a (rand m n))
1237 (x (rand n 1))
1238 (b (m* a x))
1239 (rcond (* (coerce (expt 2 -52) 'double-float)
1240 (max (nrows a) (ncols a))))
1241 (orig-a (copy a))
1242 (orig-b (copy b))
1243 (orig-x (copy x)))
1244 (list x (gelsy a b rcond))
1245 (m- x (first (gelsy a b rcond)))
1247 (princ *temp-result*)
1250 (defparameter *xv*
1251 (make-vector
1253 :type :row ;; default, not usually needed!
1254 :initial-contents '((1d0 3d0 2d0 4d0 3d0 5d0 4d0 6d0))))
1256 (defparameter *y*
1257 (make-vector
1259 :type :row
1260 :initial-contents '((1d0 2d0 3d0 4d0 5d0 6d0 7d0 8d0))))
1262 ;; so something like (NOTE: matrices are transposed to begin with, hence the incongruety)
1263 (defparameter *xtx-1* (m* *xv* (transpose *xv*)))
1264 (defparameter *xty-1* (m* *xv* (transpose *y*)))
1265 (defparameter *rcond-in* (* (coerce (expt 2 -52) 'double-float)
1266 (max (nrows *xtx-1*)
1267 (ncols *xty-1*))))
1269 (defparameter *betahat* (gelsy *xtx-1* *xty-1* *rcond-in*))
1271 ;; (#<LA-SIMPLE-VECTOR-DOUBLE (1 x 1)
1272 ;; 1.293103448275862>
1273 ;; 1)
1275 ;; ## Test case in R:
1276 ;; x <- c( 1.0, 3.0, 2.0, 4.0, 3.0, 5.0, 4.0, 6.0)
1277 ;; y <- c( 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0)
1278 ;; lm(y~x-1)
1279 ;; ## =>
1280 ;; Call:
1281 ;; lm(formula = y ~ x - 1)
1283 ;; Coefficients:
1284 ;; x
1285 ;; 1.293
1287 (first *betahat*))
1292 (type-of #2A((1 2 3 4 5)
1293 (10 20 30 40 50)))
1295 (type-of (rand 10 20))
1297 (typep #2A((1 2 3 4 5)
1298 (10 20 30 40 50))
1299 'matrix-like)
1301 (typep (rand 10 20) 'matrix-like)
1303 (typep #2A((1 2 3 4 5)
1304 (10 20 30 40 50))
1305 'array)
1307 (typep (rand 10 20) 'array)
1310 ;;;;;;;;;;;;;;;;; ===========
1312 (defparameter *my-df-trees*
1313 (make-instance 'dataframe-array
1314 :storage
1315 (listoflist->array
1316 (transpose-listoflist
1317 (rsm.string:file->number-table
1318 (localized-pathto "Data/trees.csv"))))
1319 :doc "This is an interesting dataframe-array that currently fails"))
1321 ;; *my-df-trees*
1323 (defparameter *my-df-trees2*
1324 (make-instance 'dataframe-array
1325 :storage
1326 (listoflist->array
1327 (transpose-listoflist
1328 (rsm.string:file->number-table
1329 (localized-pathto "Data/trees.csv")
1330 :delims ",")))
1331 :doc "This is an interesting dataframe-array that currently fails"))
1332 ;; *my-df-trees2*
1333 ;; (dataset *my-df-trees2*)
1335 (defparameter *my-df-trees2a*
1336 (make-instance 'dataframe-array
1337 :storage
1338 (listoflist->array
1339 (rsm.string:file->number-table
1340 (localized-pathto "Data/trees.csv")
1341 :delims ","))
1342 :doc "This is an interesting dataframe-array that currently fails"))
1344 ;; *my-df-trees2a*
1345 ;; (dataset *my-df-trees2a*)