docstring edit, and make a dummy store slot for dataframe-likes.
[CommonLispStat.git] / ls-demo.lisp
blob3e133231c986197e49dbaf766269a123a8c2b4d8
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-22 23:42:06 tony>
7 ;;; Creation: <2009-09-17 22:19:31 tony> (sometime earlier, but serious now)
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 CLS.
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.
18 ;; Start in the usual user-package for loading
19 (in-package :cl-user)
21 ;; You've configured CLS, right?
22 (asdf:oos 'asdf:load-op 'cls)
24 ;; Go somewhere so that you have the functions available.
25 (in-package :ls-user)
27 ;; we'll be loading from directories in the CLS homedir, so we want to
28 ;; make it easier to reach.
29 (defparameter *my-cls-homedir*
30 "/media/disk/Desktop/sandbox/CLS.git/" ; <- value with trailing
31 ; directory separator
32 "documentation: change this to localize") ; <- doc
33 ;; so
34 (concatenate 'string *my-cls-homedir* "Data/example.csv")
35 ;; implies
36 (defun localized-pathto (x)
37 "return a string denoting the complete path.
38 FIXME: UNIX-centric (though might work on Mac OSX). Might want to
39 return a pathspec, not a string/namespec"
40 (check-type x string)
41 (concatenate 'string *my-cls-homedir* x))
44 ;;; DataFrames
46 (defparameter *df-test*
47 (make-instance 'dataframe-array
48 :storage #2A (('a "test0" 0 0d0)
49 ('b "test1" 1 1d0)
50 ('c "test2" 2 2d0)
51 ('d "test3" 3 3d0)
52 ('e "test4" 4 4d0))
53 :doc "test reality"
54 :case-labels (list "0" "1" "2" "3" "4")
55 :var-labels (list "symb-var" "strng-var" "int-var" "dfloat-var")
56 :var-types (list 'symbol 'string 'integer 'double-float)))
58 *df-test* ; but with SBCL, ints become floats?
59 (caselabels *df-test*)
60 (varlabels *df-test*)
61 (vartypes *df-test*)
63 (setf (xref *df-test* 0 0) -1d0) ; for dataframes, we might want to do
64 ; some type checking to prevent what
65 ; I just did!
67 (setf (xref *df-test* 0 0) (quote 'a)) ; so that we can restore the
68 ; quoted value.
69 *df-test*
71 ;; Making from arrays and matrix-likes
72 (make-dataframe #2A((1 2 3 4 5)
73 (10 20 30 40 50)))
74 (make-dataframe (rand 4 3))
76 ;;; HERE#1
77 ;;; == READ DATA
79 ;;; read in a CSV dataframe...
81 ;; a better approach is:
82 (asdf:oos 'asdf:load-op 'rsm-string)
83 (listoflist->array
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 ",")
97 (rsm.string:file->number-table
98 (localized-pathto "Data/R-chickwts.csv")
99 :delims ",")
100 (rsm.string:file->string-table
101 (localized-pathto "Data/R-chickwts.csv")
102 :delims ",")
104 (defparameter *my-df-2*
105 (make-instance 'dataframe-array
106 :storage
107 (listoflist->array
108 (rsm.string:file->string-table
109 (localized-pathto "Data/example-mixed.csv")))
110 :doc "This is an interesting dataframe-array"))
111 ;; *my-df-2*
113 (defparameter *my-df-3*
114 (make-instance 'dataframe-array
115 :storage
116 (listoflist->array
117 (transpose-listoflist
118 (rsm.string:file->number-table
119 (localized-pathto "Data/example-numeric.csv"))))
120 :doc "This is an interesting dataframe-array"))
121 ;; *my-df-3*
124 (defparameter *my-df-4*
125 (make-instance 'dataframe-array
126 :storage
127 (listoflist->array
128 (rsm.string:file->number-table
129 (localized-pathto "Data/R-chickwts.csv")
130 :delims ","))
131 :doc "This is an interesting dataframe-array that currently fails"))
132 ;; *my-df-4*
134 (aref (dataset *my-df-4*) 0 1)
137 (defparameter *my-df-5*
138 (make-instance 'dataframe-array
139 :storage
140 (listoflist->array
141 (transpose-listoflist
142 (rsm.string:file->number-table
143 (localized-pathto "Data/R-swiss.csv"))))
144 :doc "This is an interesting dataframe-array that currently fails"))
145 ;; *my-df-5*
149 (defparameter *mat-1*
150 (make-matrix 3 3
151 :initial-contents #2A((2d0 3d0 4d0) (3d0 2d0 4d0) (4d0 4d0 5d0))))
153 (defparameter *mat-1*
154 (make-matrix 3 3
155 :initial-contents #2A((2d0 3d0 -4d0)
156 (3d0 2d0 -4d0)
157 (4d0 4d0 -5d0))))
158 (mref *mat-1* 2 0)
160 (defparameter *mat-2*
161 (let ((m (rand 3 3)))
162 (m* m (transpose m))))
164 (axpy 100.0d0 *mat-2* (eye 3 3))
166 (potrf (copy *mat-2*)) ;; factor
167 (potri (copy *mat-2*)) ;; invert
168 (minv-cholesky (copy *mat-2*))
169 (m* (minv-cholesky (copy *mat-2*)) *mat-2*)
171 (defparameter *mat-3*
172 (make-matrix
174 :initial-contents '((16d0 13d0 12d0)
175 (13d0 22d0 7d0)
176 (12d0 7d0 17d0))))
178 (potrf (copy *mat-3*)) ;; factor
181 *mat-3* =>
182 #<LA-SIMPLE-MATRIX-DOUBLE 3 x 3
183 16.0 13.0 12.0
184 13.0 22.0 7.0
185 12.0 7.0 17.0>
187 (potrf (copy *mat-3*)) =>
188 (#<LA-SIMPLE-MATRIX-DOUBLE 3 x 3
189 4.0 3.25 3.0
190 13.0 3.3819373146171707 -0.8131433980500301
191 12.0 7.0 2.7090215603069034>
192 "U" NIL)
194 ;; and compare with...
196 > testm <- matrix(data=c(16,13,12,13,22,7,12,7,17),nrow=3)
197 > chol(testm)
198 [,1] [,2] [,3]
199 [1,] 4 3.250000 3.0000000
200 [2,] 0 3.381937 -0.8131434
201 [3,] 0 0.000000 2.7090216
204 ;; which suggests that the major difference is that R zero's out the
205 ;; appropriate terms, and that CLS does not.
209 (potri (copy *mat-2*)) ;; invert
210 (minv-cholesky (copy *mat-2*))
211 (m* (minv-cholesky (copy *mat-2*)) *mat-2*)
215 (lu-decomp #2A((2 3 4) (1 2 4) (2 4 5)))
216 ;; => (#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)
217 (lu-solve
218 (lu-decomp #2A((2 3 4) (1 2 4) (2 4 5)))
219 #(2 3 4))
220 ;; => #(-2.333333333333333 1.3333333333333335 0.6666666666666666)
222 (getrf
223 (make-matrix 3 3
224 :initial-contents #2A((2d0 3d0 4d0) (1d0 2d0 4d0) (2d0 4d0 5d0))))
226 #| => ; so not so good for the vector, but matrix matches.
227 (#<LA-SIMPLE-MATRIX-DOUBLE 3 x 3
228 2.0 3.0 4.0
229 1.0 1.0 1.0
230 0.5 0.5 1.5>
231 #<FNV-INT32 (3) 1 3 3> NIL)
234 (msolve-lu
235 (make-matrix 3 3
236 :initial-contents #2A((2d0 3d0 4d0)
237 (1d0 2d0 4d0)
238 (2d0 4d0 5d0)))
239 (make-vector 3 :type :column
240 :initial-contents '((2d0)
241 (3d0)
242 (4d0))))
244 #| =>
245 #<LA-SIMPLE-VECTOR-DOUBLE (3 x 1)
246 -2.3333333333333335
247 1.3333333333333335
248 0.6666666666666666>
253 ;;; LU common applications
255 (defun minv-lu (a)
256 "invert A using LU Factorization"
257 (let ((a-fac (getrf (copy a))))
258 (first (getri (first a-fac) (second a-fac)))))
260 #+nil (progn
261 (let ((m1 (rand 3 3)))
262 (m* m1 (minv-lu m1))))
264 (defun msolve-lu (a b)
265 "Compute `x1' solving `A x = b', with LU factorization."
266 (let ((a-fac (getrf (copy a))))
267 (first (getrs (first a-fac) b (second a-fac)))))
271 ;; (inverse #2A((2 3 4) (1 2 4) (2 4 5)))
272 ;; #2A((2.0 -0.33333333333333326 -1.3333333333333335)
273 ;; (-1.0 -0.6666666666666666 1.3333333333333333)
274 ;; (0.0 0.6666666666666666 -0.3333333333333333))
276 (minv-lu
277 (make-matrix
279 :initial-contents #2A((2d0 3d0 4d0)
280 (1d0 2d0 4d0)
281 (2d0 4d0 5d0))))
285 #<LA-SIMPLE-MATRIX-DOUBLE 3 x 3
286 2.0 -0.3333333333333333 -1.3333333333333333
287 -1.0 -0.6666666666666666 1.3333333333333333
288 0.0 0.6666666666666666 -0.3333333333333333>
290 ;; so is correct.
294 ;;;;;HERE#2
296 (factorize
297 (make-matrix 3 3
298 :initial-contents #2A((2d0 3d0 4d0)
299 (1d0 2d0 4d0)
300 (2d0 4d0 5d0)))
301 :by :svd)
303 ;; (sv-decomp #2A((2 3 4) (1 2 4) (2 4 5)))
304 ;; (#2A((-0.5536537653489974 0.34181191712789266 -0.7593629708013371)
305 ;; (-0.4653437312661058 -0.8832095891230851 -0.05827549615722014)
306 ;; (-0.6905959164998124 0.3211003503429828 0.6480523475178517))
307 ;; #(9.699290438141343 0.8971681569301373 0.3447525123483081)
308 ;; #2A((-0.30454218417339873 0.49334669582252344 -0.8147779426198863)
309 ;; (-0.5520024849987308 0.6057035911404464 0.5730762743603965)
310 ;; (-0.7762392122368734 -0.6242853493399995 -0.08786630745236332))
311 ;; T)
315 (qr-decomp #2A((2 3 4) (1 2 4) (2 4 5)))
316 ;; (#2A((-0.6666666666666665 0.7453559924999298 5.551115123125783e-17)
317 ;; (-0.3333333333333333 -0.2981423969999719 -0.894427190999916)
318 ;; (-0.6666666666666666 -0.5962847939999439 0.44721359549995787))
319 ;; #2A((-3.0 -5.333333333333334 -7.333333333333332)
320 ;; (0.0 -0.7453559924999292 -1.1925695879998877)
321 ;; (0.0 0.0 -1.3416407864998738)))
323 (rcondest #2A((2 3 4) (1 2 4) (2 4 5)))
324 ;; 6.8157451e7
325 ;;; CURRENTLY FAILS!!
327 (eigen #2A((2 3 4) (1 2 4) (2 4 5)))
328 ;; (#(10.656854249492381 -0.6568542494923802 -0.9999999999999996)
329 ;; (#(0.4999999999999998 0.4999999999999997 0.7071067811865475)
330 ;; #(-0.49999999999999856 -0.5000000000000011 0.7071067811865474)
331 ;; #(0.7071067811865483 -0.7071067811865466 -1.2560739669470215e-15))
332 ;; NIL)
334 (spline #(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 6)
336 ;; ((1.0 1.3 1.6 1.9 2.2 2.5)
337 ;; (1.2 2.1 2.2750696543866313 1.6465231041904045 1.2186576148879609 2.8))
339 ;;; using KERNEL-SMOOTH-FRONT, not KERNEL-SMOOTH-CPORT
340 (kernel-smooth #(1.0 1.2 1.3 1.8 2.1 2.5)
341 #(1.2 2.0 2.1 2.0 1.1 2.8) :xvals 5)
342 ;; ((1.0 1.375 1.75 2.125 2.5)
343 ;; (1.6603277642110226 1.9471748095239771 1.7938127405752287
344 ;; 1.5871511322219498 2.518194783156392))
346 (kernel-dens #(1.0 1.2 2.5 2.1 1.8 1.2) :xvals 5)
347 ;; ((1.0 1.375 1.75 2.125 2.5)
348 ;; (0.7224150453621405 0.5820045548233707 0.38216411702854214
349 ;; 0.4829822708587095 0.3485939156929503))
351 (fft #(1.0 1.2 2.5 2.1 1.8))
352 ;; #(#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))
354 (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))
355 ;; (#(1.0 1.2 1.2 1.8 2.1 2.5))
359 ;;;; Special functions
361 ;; Log-gamma function
363 (log-gamma 3.4) ;;1.0923280596789584
367 ;;;; Probability functions
369 ;; looking at these a bit more, perhaps a more CLOSy style is needed, i.e.
370 ;; (quantile :list-or-cons loc :type type (one of 'empirical 'normal 'cauchy, etc...))
371 ;; similar for the cdf, density, and rand.
372 ;; Probably worth figuring out how to add a new distribution
373 ;; efficiently, i.e. by keeping some kind of list.
375 ;; Normal distribution
377 (normal-quant 0.95) ;;1.6448536279366268
378 (normal-cdf 1.3) ;;0.9031995154143897
379 (normal-dens 1.3) ;;0.17136859204780736
380 (normal-rand 2) ;;(-0.40502015f0 -0.8091404f0)
382 (bivnorm-cdf 0.2 0.4 0.6) ;;0.4736873734160288
384 ;; Cauchy distribution
386 (cauchy-quant 0.95) ;;6.313751514675031
387 (cauchy-cdf 1.3) ;;0.7912855998398473
388 (cauchy-dens 1.3) ;;0.1183308127104695
389 (cauchy-rand 2) ;;(-1.06224644160405 -0.4524695943939537)
391 ;; Gamma distribution
393 (gamma-quant 0.95 4.3) ;;8.178692439291645
394 (gamma-cdf 1.3 4.3) ;;0.028895150986674906
395 (gamma-dens 1.3 4.3) ;;0.0731517686447374
396 (gamma-rand 2 4.3) ;;(2.454918912880936 4.081365384357454)
398 ;; Chi-square distribution
400 (chisq-quant 0.95 3) ;;7.814727903379012
401 (chisq-cdf 1 5) ;;0.03743422675631789
402 (chisq-dens 1 5) ;;0.08065690818083521
403 (chisq-rand 2 4) ;;(1.968535826180572 2.9988646156942997)
405 ;; Beta distribution
407 (beta-quant 0.95 3 2) ;;0.9023885371149876
408 (beta-cdf 0.4 2 2.4) ;;0.4247997418541529
409 (beta-dens 0.4 2 2.4) ;;1.5964741858913518
410 (beta-rand 2 2 2.4) ;;(0.8014897077282279 0.6516371997922659)
412 ;; t distribution
414 (t-quant 0.95 3) ;;2.35336343484194
415 (t-cdf 1 2.3) ;;0.794733624298342
416 (t-dens 1 2.3) ;;0.1978163816318102
417 (t-rand 2 2.3) ;;(-0.34303672776089306 -1.142505872436518)
419 ;; F distribution
421 (f-quant 0.95 3 5) ;;5.409451318117459
422 (f-cdf 1 3.2 5.4) ;;0.5347130905510765
423 (f-dens 1 3.2 5.4) ;;0.37551128864591415
424 (f-rand 2 3 2) ;;(0.7939093442091963 0.07442694152491144)
426 ;; Poisson distribution
428 (poisson-quant 0.95 3.2) ;;6
429 (poisson-cdf 1 3.2) ;;0.17120125672252395
430 (poisson-pmf 1 3.2) ;;0.13043905274097067
431 (poisson-rand 5 3.2) ;;(2 1 2 0 3)
433 ;; Binomial distribution
435 (binomial-quant 0.95 3 0.4) ;;; DOESN'T RETURN
436 (binomial-quant 0 3 0.4) ;;; -2147483648
437 (binomial-cdf 1 3 0.4) ;;0.6479999999965776
438 (binomial-pmf 1 3 0.4) ;;0.4320000000226171
439 (binomial-rand 5 3 0.4) ;;(2 2 0 1 2)
441 ;;;; OBJECT SYSTEM
443 (in-package :ls-user)
444 (defproto *test-proto*)
445 *test-proto*
446 (defmeth *test-proto* :make-data (&rest args) nil)
448 (defparameter my-proto-instance nil)
449 (setf my-proto-instance (send *test-proto* :new))
450 (send *test-proto* :own-slots)
451 (lsos::ls-object-slots *test-proto*)
452 (lsos::ls-object-methods *test-proto*)
453 (lsos::ls-object-parents *test-proto*)
454 (lsos::ls-object-preclist *test-proto*)
455 ;;; The following fail and I do not know why?
456 (send *test-proto* :has-slot 'proto-name)
457 (send *test-proto* :has-slot 'PROTO-NAME)
458 (send *test-proto* :has-slot 'make-data)
459 (send *test-proto* :has-slot 'MAKE-DATA)
460 (send *test-proto* :has-method 'make-data)
461 (send *test-proto* :has-method 'MAKE-DATA)
464 (defproto2 *test-proto3* (list) (list) (list) "test doc" t)
465 (defproto2 *test-proto4*)
466 *test-proto2*
467 (defmeth *test-proto* :make-data (&rest args) nil)
469 (defparameter my-proto-instance nil)
470 (setf my-proto-instance (send *test-proto* :new))
471 (send *test-proto* :own-slots)
472 (send *test-proto* :has-slot 'proto-name)
473 (send *test-proto* :has-slot 'PROTO-NAME)
476 ;;;; Testing
478 (in-package :lisp-stat-unittests)
479 (testsuites)
480 (print-tests)
481 (run-tests)
482 (last-test-status)
483 ;;(failures)
485 (describe (run-tests :suite 'lisp-stat-ut-testsupport))
486 (describe (run-tests :suite 'lisp-stat-ut-testsupport2))
488 (testsuite-tests 'lisp-stat-ut)
489 (run-tests :suite 'lisp-stat-ut)
490 (describe (run-tests :suite 'lisp-stat-ut))
492 (run-tests :suite 'lisp-stat-ut-probdistn)
493 (describe (run-tests :suite 'lisp-stat-ut-probdistn))
494 (run-tests :suite 'lisp-stat-ut-spec-fns)
495 (describe (run-tests :suite 'lisp-stat-ut-spec-fns))
497 (find-testsuite 'lisp-stat-ut-lin-alg)
498 (testsuite-tests 'lisp-stat-ut-lin-alg)
499 (run-tests :suite 'lisp-stat-ut-lin-alg)
500 (describe (run-tests :suite 'lisp-stat-ut-lin-alg))
502 ;;;; Data Analysis test
504 (in-package :ls-user)
506 ;; LispStat 1 approach to variables
508 (progn
509 (def iron (list 61 175 111 124 130 173 169 169 160 224 257 333 199))
510 iron
511 (def aluminum (list 13 21 24 23 64 38 33 61 39 71 112 88 54))
512 aluminum
513 (def absorbtion (list 4 18 14 18 26 26 21 30 28 36 65 62 40))
514 absorbtion
516 ;; LispStat 1 approach to data frames... (list of lists).
518 (DEF DIABETES
519 (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)
520 (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)
521 (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)
522 (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))))
525 (DEF DLABS (QUOTE ("GLUFAST" "GLUTEST" "INSTEST" "CCLASS")))
526 (format t "loaded data.~%")
527 ) ;; eval at this point.
529 ;; Simple univariate variable-specific descriptions.
530 (fivnum absorbtion)
531 (median absorbtion)
532 (sort-data absorbtion)
533 (rank absorbtion)
534 (standard-deviation absorbtion)
535 (interquartile-range absorbtion)
537 (lisp-stat-matrix::bind-columns aluminum iron)
538 (bind-columns aluminum iron)
539 (apply #'bind-columns (list aluminum iron))
540 (lisp-stat-matrix::bind-columns #2a((1 2)(3 4)) #(5 6))
541 (bind-columns #2a((1 2)(3 4)) #(5 6))
544 (defparameter fit1 nil)
545 (setf fit1 (regression-model absorbtion iron))
546 (send fit1 :display)
547 (send fit1 :residuals)
549 iron
550 (defparameter fit1a nil)
551 (setf fit1a (regression-model absorbtion iron :print nil))
552 (send fit1a :doc)
553 ;; (setf (send fit1a :doc) "this") ;; FIXME: this error...
554 (send fit1a :doc "this") ;; FIXME: this is a more natural
555 (send fit1a :doc)
556 (send fit1a :x)
557 (send fit1a :y)
558 (send fit1a :compute)
559 (send fit1a :sweep-matrix)
560 (send fit1a :basis)
561 (send fit1a :residuals)
562 (send fit1a :display)
564 #+nil(progn
565 ;; syntax example
566 (array-dimension #2A ((1)) 0)
569 ;;; FIXME: need to get multiple-linear regression working -- clearly
570 ;;; simple linear is working above!
571 (defvar m nil "holding variable.")
572 (def m (regression-model (list iron aluminum) absorbtion :print nil))
573 (send m :compute)
574 (send m :sweep-matrix)
575 (format t "~%~A~%" (send m :sweep-matrix))
577 ;; ERROR... FIX-ME!!
578 (send m :basis) ;; this should be positive?
579 (send m :coef-estimates)
581 (send m :display)
582 (def m (regression-model (bind-columns iron aluminum) absorbtion))
583 (send m :help)
584 (send m :help :display)
585 (send m :help :basis)
586 ;; No graphics! But handle the error gracefully...
587 (send m :plot-residuals)
590 (typep aluminum 'sequence)
591 (typep iron 'sequence)
592 (matrixp iron)
594 *variables*
596 (variables)
597 (undef 'iron)
598 (variables)
600 ;;; Plotting!
602 (asdf:oos 'asdf:compile-op 'cl-cairo2 :force t)
603 (asdf:oos 'asdf:load-op 'cl-cairo2)
605 ;; The above can be used to generate PDF, PS, PNG, and X11/Microsoft
606 ;; displays (the latter being a proof of concept, of limited use for
607 ;; "real work".
609 ;; and this below, as well.
610 (asdf:oos 'asdf:load-op 'cl-plplot)
612 ;;; Using R!
614 (asdf:oos 'asdf:compile-op 'rclg :force t)
615 (asdf:oos 'asdf:load-op 'rclg)
618 (in-package :rclg-user)
620 ;; rclg-init::*r-started*
622 ;;;#3 Start R within Lisp
624 (start-rclg)
625 ;; rclg-init::*r-started*
626 (rclg-init::check-stack)
627 (r "Cstack_info")
628 (defparameter *x* (r seq 1 10))
629 (defparameter *y* (r rnorm 10))
631 (r plot *x* *y*)
634 (defparameter *r-version* (r "version"))
636 ;; This is for illustrative purposes only. It is not a "good" use of rnbi.
637 ;; Really, you'll want rnbi to hold anonymous intermeditae results, like:
638 (r plot *x* (rnbi rnorm 10))
640 (r "Sys.getenv" "LD_LIBRARY_PATH")
641 (r "Sys.getenv" "LD_PRELOAD")
643 (r "ls")
644 (r ls)
645 (r "search")
647 (r "geterrmessage")
649 (r "library" "stats")
650 (r library "MASS")
651 (r "library" "Biobase")
653 (setf my.lib "Biobase")
654 my.lib
655 (r library my.lib)
657 (r "ls")
659 (r "print.default" 3)
660 (r "rnorm" 10)
662 ;; Working in the R space
664 (r assign "x" 5)
665 (r assign "x2" (list 1 2 3 5))
667 (r assign "x2" #(1 2 3 5 3 4 5))
668 (r assign "z" "y") ;; unlike the above, this assigns character data
669 (r "ls")
670 (r ls)
672 (setf my.r.x2 (r get "x2")) ;; moving data from R to CL
673 (r assign "x2" my.r.x2) ;; moving data from CL to R
675 ;; The following is not the smartest thing to do!
676 ;;(r q)
680 ;;; How might we do statistics with Common Lisp?
681 ;;; How might we work with a data.frame?
682 ;;; What could the structures be?
683 ;;; How much hinting, and of what type, should drive the data
684 ;;; analysis?
686 (defpackage :my-data-analysis-example
687 (:documentation "Example work-package for a data analysis")
688 (:use :common-lisp :lisp-stat)
689 (:export results figures report))
691 (in-package :my-data-analysis-example)
693 (defvar my-dataset1 (read-file "data/test1.lisp"))
694 ;; or
695 (defvar my-dataset2 (read-file "data/test1.csv" :type 'csv))
697 ;;; manipulate
699 (setf my-dataset2 (set-description my-datasets2
700 :dependent-variables (list of symbols)))
701 (setf my-dataset2 (set-description my-datasets2
702 :independent-variables (list of symbols)))
704 ;; the following could be true in many cases.
705 (assert
706 (list-intersection (get-description my-datasets2 :independent-variables)
707 (get-description my-datasets2 :dependent-variables)))
709 ;; but we could phrase better,i.e.
711 (get-description
712 my-datasets2
713 :predicate-list-on-variable-metadata (list (and 'independent-variables
714 'dependent-variables)))
717 ;; statistical relations re: input/output, as done above, is one
718 ;; issue, another one is getting the right approach for statistical
719 ;; typing, i.e.
720 (get-description
721 my-datasets2
722 :predicate-list-on-variable-metadata (list 'ordinal-variables))
725 ;; so we could use a set of logical ops to selection from variable
726 ;; metadata, i.e.
727 ;; and, or, not
728 ;; do we really need the simplifying extensions?
731 ;;; output to REPL
733 (report my-dataset1 :style 'five-num)
734 (report my-dataset1 :style 'univariate)
735 (report my-dataset1 :style 'bivariate)
736 (report my-dataset1 :style 'metadata)
738 ;;; to file?
740 (report my-dataset1
741 :style 'five-num
742 :format 'pdf
743 :stream (filename-as-stream "my-dataset1-5num.pdf"))
744 (report my-dataset1 :style 'univariate)
745 (report my-dataset1 :style 'bivariate)
746 (report my-dataset1 :style 'metadata)
748 ;;; so report could handle datasets... and models?
750 (report my-model :style 'formula)
751 (report my-model :style 'simulate
752 (list :parameters (:eta 5 :mu 4 :sigma (list 2 1 0.5))
753 :number-of-reps 10))
754 ;; should return a list of parameters along with range information,
755 ;; useful for auto-building the above. Note that there are 3 types
756 ;; of parameters that can be considered -- we can have values which
757 ;; define ddata, we can have values which define fixed values and some
758 ;; could be things tht we estimate.
761 (defgeneric report (object &optional style format stream)
762 (:documentation "method for reporting on data"))
764 (defmethod report ((object dataset)
765 (style report-dataset-style-type)
766 (format output-format-type)
767 ((stream *repl*) output-stream-type))
768 "dataset reporting")
771 (defmethod report ((object model)
772 (style report-model-style-type)
773 (format output-format-type)
774 ((stream *repl*) output-stream-type))
775 "model reporting")
777 (defmethod report ((object analysis-instance)
778 (style report-analysis-style-type)
779 (format output-format-type)
780 ((stream *repl*) output-stream-type))
781 "model + dataset reporting")
784 ;; parameters are just things which get filled with values, repeatedly
785 ;; with data, or by considering to need estimation.
786 (parameters my-model)
787 (parameters my-model :type 'data)
788 (parameters my-model :type 'fixed)
789 (parameters my-model :type 'estimate)
790 (parameters my-model :type '(estimate fixed))
791 (parameters my-model :list-types) ;; useful for list-based extraction
792 ;; of particular types
794 (setf my-model-data-instance
795 (compute model data :specification (list :spec 'linear-model
796 :depvar y
797 :indepvar (list x1 x2))))
798 (report my-model-data-instance)
801 ;;; So how might we use this? Probably need to consider the
802 ;;; serialization of any lisp objects generated, perhaps via some form
803 ;;; of memoization...?
804 (in-package :cl-user)
806 (my-data-analysis-example:report :type 'full)
807 (my-data-analysis-example:report :type 'summary)
808 (my-data-analysis-example:figures :type 'pdf :file "results-figs.pdf")
810 (my-data-analysis-example:report)
812 ;;; more stuff
814 (send m :display)
815 (def m (regression-model (bind-columns iron aluminum) absorbtion))
816 (send m :help)
817 (send m :help :display)
818 (send m :help :basis)
820 (send m :plot-residuals)
822 (progn
823 ;; General Lisp, there is also a need to add, remove symbols from the
824 ;; workspace/namespace. This is a fundamental skill, similar to
825 ;; stopping, which is critical.
827 ;; boundp, fboundp
828 ;; makunbound, fmakunbound
832 (progn
833 ;;; A study in array vs list access
834 (defparameter *x* (list 1 2 3))
835 (defparameter *y* #(1 2 3))
836 (defparameter *z* (list 1 (list 2 3) (list 4 5 (list 6 7)) ))
837 (length *x*)
838 (length *y*)
839 (length *z*) ; => need a means to make this 7.
840 (length (reduce #'cons *z*)) ; => not quite -- missing iterative
842 (nelts *x*)
843 (nth 1 *x*)
844 (aref *y* 1)
845 (setf (nth 1 *x*) 6)
847 (setf (aref *y* 1) 6)
851 (in-package :ls-user)
853 (progn
854 (defparameter *x* (make-vector 5 :initial-contents '((1d0 2d0 3d0 4d0 5d0))))
855 ;; estimating a mean, simple way.
856 (/ (loop for i from 0 to (- (nelts *x*) 1)
857 summing (vref *x* i))
858 (nelts *x*))
860 (defun mean (x)
861 (checktype x 'vector-like)
862 (/ (loop for i from 0 to (- (nelts *x*) 1)
863 summing (vref *x* i))
864 (nelts *x*)))
866 ;; estimating variance, Moments
867 (let ((meanx (mean *x*))
868 (n (nelts *x*)))
869 (/ (loop for i from 0 to (1- n)
870 summing (* (- (vref *x* i) meanx)
871 (- (vref *x* i) meanx)))
874 ;; estimating variance, Moments
875 (let ((meanx (mean *x*))
876 (nm1 (1- (nelts *x*))))
877 (/ (loop for i from 0 to nm1
878 summing (* (- (vref *x* i) meanx)
879 (- (vref *x* i) meanx) ))
880 nm1))
884 ;;;;;;;;;;;;;;; Data stuff
886 (progn ;; Data setup
888 ;; Making data-frames (i.e. cases (rows) by variables (columns))
889 ;; takes a bit of getting used to. For this, it is important to
890 ;; realize that we can do the following:
891 ;; #1 - consider the possibility of having a row, and transposing
892 ;; it, so the list-of-lists is: ((1 2 3 4 5)) (1 row, 5 columns)
893 ;; #2 - naturally list-of-lists: ((1)(2)(3)(4)(5)) (5 rows, 1 column)
894 ;; see src/data/listoflist.lisp for code to process this particular
895 ;; data structure.
896 (defparameter *indep-vars-1-matrix*
897 (transpose (make-matrix 1 (length iron)
898 :initial-contents
899 (list (mapcar #'(lambda (x) (coerce x 'double-float))
900 iron))))
901 "creating iron into double float, straightforward")
903 (documentation '*indep-vars-1-matrix* 'variable)
904 ;; *indep-vars-1-matrix*
906 ;; or directly:
907 (defparameter *indep-vars-1a-matrix*
908 (make-matrix (length iron) 1
909 :initial-contents
910 (mapcar #'(lambda (x) (list (coerce x 'double-float)))
911 iron)))
912 ;; *indep-vars-1a-matrix*
914 ;; and mathematically, they seem equal:
915 (m= *indep-vars-1-matrix* *indep-vars-1a-matrix*) ; => T
916 ;; but of course not completely...
917 (eql *indep-vars-1-matrix* *indep-vars-1a-matrix*) ; => NIL
918 (eq *indep-vars-1-matrix* *indep-vars-1a-matrix*) ; => NIL
920 ;; and verify...
921 (print *indep-vars-1-matrix*)
922 (print *indep-vars-1a-matrix*)
924 (documentation 'lisp-matrix:bind2 'function) ; by which we mean:
925 (documentation 'bind2 'function)
926 (bind2 *indep-vars-1-matrix* *indep-vars-1a-matrix* :by :column) ; 2 col
927 (bind2 *indep-vars-1-matrix* *indep-vars-1a-matrix* :by :row) ; 1 long col
929 ;; the weird way
930 (defparameter *indep-vars-2-matrix*
931 (transpose (make-matrix 2 (length iron)
932 :initial-contents
933 (list
934 (mapcar #'(lambda (x) (coerce x 'double-float))
935 iron)
936 (mapcar #'(lambda (x) (coerce x 'double-float))
937 aluminum)))))
938 ;; *indep-vars-2-matrix*
940 ;; the "right"? way
941 (defparameter *indep-vars-2-matrix*
942 (make-matrix (length iron) 2
943 :initial-contents
944 (mapcar #'(lambda (x y)
945 (list (coerce x 'double-float)
946 (coerce y 'double-float)))
947 iron aluminum)))
948 ;; *indep-vars-2-matrix*
951 ;; The below FAILS due to coercion issues; it just isn't lispy, it's R'y.
953 (defparameter *dep-var* (make-vector (length absorbtion)
954 :initial-contents (list absorbtion)))
956 ;; BUT below, this should be the right type.
957 (defparameter *dep-var*
958 (make-vector (length absorbtion)
959 :type :row
960 :initial-contents
961 (list
962 (mapcar #'(lambda (x) (coerce x 'double-float))
963 absorbtion))))
964 ;; *dep-var*
967 (defparameter *dep-var-int*
968 (make-vector (length absorbtion)
969 :type :row
970 :element-type 'integer
971 :initial-contents (list absorbtion)))
973 (typep *dep-var* 'matrix-like) ; => T
974 (typep *dep-var* 'vector-like) ; => T
976 (typep *indep-vars-1-matrix* 'matrix-like) ; => T
977 (typep *indep-vars-1-matrix* 'vector-like) ; => T
978 (typep *indep-vars-2-matrix* 'matrix-like) ; => T
979 (typep *indep-vars-2-matrix* 'vector-like) ; => F
981 iron
982 ;; following fails, need to ensure that we work on list elts, not just
983 ;; elts within a list:
985 ;; (coerce iron 'real)
987 ;; the following is a general list-conversion coercion approach -- is
988 ;; there a more efficient way?
989 ;; (coerce 1 'real)
990 ;; (mapcar #'(lambda (x) (coerce x 'double-float)) iron)
992 (princ "Data Set up"))
997 (progn ;; Data setup
999 (describe 'make-matrix)
1001 (defparameter *indep-vars-2-matrix*
1002 (make-matrix (length iron) 2
1003 :initial-contents
1004 (mapcar #'(lambda (x y)
1005 (list (coerce x 'double-float)
1006 (coerce y 'double-float)))
1007 iron aluminum)))
1010 (defparameter *dep-var*
1011 (make-vector (length absorbtion)
1012 :type :row
1013 :initial-contents
1014 (list
1015 (mapcar #'(lambda (x) (coerce x 'double-float))
1016 absorbtion))))
1018 (make-dataframe *dep-var*)
1019 (make-dataframe (transpose *dep-var*))
1021 (defparameter *dep-var-int*
1022 (make-vector (length absorbtion)
1023 :type :row
1024 :element-type 'integer
1025 :initial-contents (list absorbtion)))
1028 (defparameter *xv+1a*
1029 (make-matrix
1031 :initial-contents #2A((1d0 1d0)
1032 (1d0 3d0)
1033 (1d0 2d0)
1034 (1d0 4d0)
1035 (1d0 3d0)
1036 (1d0 5d0)
1037 (1d0 4d0)
1038 (1d0 6d0))))
1040 (defparameter *xv+1b*
1041 (bind2
1042 (ones 8 1)
1043 (make-matrix
1045 :initial-contents '((1d0)
1046 (3d0)
1047 (2d0)
1048 (4d0)
1049 (3d0)
1050 (5d0)
1051 (4d0)
1052 (6d0)))
1053 :by :column))
1055 (m= *xv+1a* *xv+1b*) ; => T
1057 (princ "Data Set up"))
1061 ;;;; LM
1063 (progn
1065 (defparameter *y*
1066 (make-vector
1068 :type :row
1069 :initial-contents '((1d0 2d0 3d0 4d0 5d0 6d0 7d0 8d0))))
1072 (defparameter *xv+1*
1073 (make-matrix
1075 :initial-contents '((1d0 1d0)
1076 (1d0 3d0)
1077 (1d0 2d0)
1078 (1d0 4d0)
1079 (1d0 3d0)
1080 (1d0 5d0)
1081 (1d0 4d0)
1082 (1d0 6d0))))
1085 ;; so something like (NOTE: matrices are transposed to begin with, hence the incongruety)
1086 (defparameter *xtx-2* (m* (transpose *xv+1*) *xv+1*))
1087 ;; #<LA-SIMPLE-MATRIX-DOUBLE 2 x 2
1088 ;; 8.0d0 28.0d0
1089 ;; 28.0d0 116.0d0>
1091 (defparameter *xty-2* (m* (transpose *xv+1*) (transpose *y*)))
1092 ;; #<LA-SIMPLE-VECTOR-DOUBLE (2 x 1)
1093 ;; 36.0d0
1094 ;; 150.0d0>
1096 (defparameter *rcond-2* 0.000001)
1097 (defparameter *betahat-2* (gelsy *xtx-2* *xty-2* *rcond-2*))
1098 ;; *xtx-2* => "details of complete orthogonal factorization"
1099 ;; according to man page:
1100 ;; #<LA-SIMPLE-MATRIX-DOUBLE 2 x 2
1101 ;; -119.33147112141039d0 -29.095426104883202d0
1102 ;; 0.7873402682880205d0 -1.20672274167718d0>
1104 ;; *xty-2* => output becomes solution:
1105 ;; #<LA-SIMPLE-VECTOR-DOUBLE (2 x 1)
1106 ;; -0.16666666666668312d0
1107 ;; 1.333333333333337d0>
1109 *betahat-2* ; which matches R, see below
1111 (documentation 'gelsy 'function)
1114 ;; (#<LA-SIMPLE-VECTOR-DOUBLE (2 x 1)
1115 ;; -0.16666666666668312 1.333333333333337>
1116 ;; 2)
1118 ;; ## Test case in R:
1119 ;; x <- c( 1.0, 3.0, 2.0, 4.0, 3.0, 5.0, 4.0, 6.0)
1120 ;; y <- c( 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0)
1121 ;; lm(y~x)
1122 ;; ## => Call: lm(formula = y ~ x)
1124 ;; Coefficients: (Intercept) x
1125 ;; -0.1667 1.3333
1127 ;; summary(lm(y~x))
1128 ;; ## =>
1130 ;; Call:
1131 ;; lm(formula = y ~ x)
1133 ;; Residuals:
1134 ;; Min 1Q Median 3Q Max
1135 ;; -1.833e+00 -6.667e-01 -3.886e-16 6.667e-01 1.833e+00
1137 ;; Coefficients:
1138 ;; Estimate Std. Error t value Pr(>|t|)
1139 ;; (Intercept) -0.1667 1.1587 -0.144 0.89034
1140 ;; x 1.3333 0.3043 4.382 0.00466 **
1141 ;; ---
1142 ;; Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
1144 ;; Residual standard error: 1.291 on 6 degrees of freedom
1145 ;; Multiple R-squared: 0.7619, Adjusted R-squared: 0.7222
1146 ;; F-statistic: 19.2 on 1 and 6 DF, p-value: 0.004659
1150 ;; which suggests one might do (modulo ensuring correct
1151 ;; orientations). When this is finalized, it should migrate to
1152 ;; CLS.
1156 (defparameter *n* 20) ; # rows = # obsns
1157 (defparameter *p* 10) ; # cols = # vars
1158 (defparameter *x-temp* (rand *n* *p*))
1159 (defparameter *b-temp* (rand *p* 1))
1160 (defparameter *y-temp* (m* *x-temp* *b-temp*))
1161 ;; so Y=Xb + \eps
1162 (defparameter *rcond* (* (coerce (expt 2 -52) 'double-float)
1163 (max (nrows *x-temp*) (ncols *y-temp*))))
1164 (defparameter *orig-x* (copy *x-temp*))
1165 (defparameter *orig-b* (copy *b-temp*))
1166 (defparameter *orig-y* (copy *y-temp*))
1168 (defparameter *lm-result* (lm *x-temp* *y-temp*))
1169 (princ (first *lm-result*))
1170 (princ (second *lm-result*))
1171 (princ (third *lm-result*))
1172 (v= (third *lm-result*)
1173 (v- (first (first *lm-result*))
1174 (first (second *lm-result*))))
1179 ;; Some issues exist in the LAPACK vs. LINPACK variants, hence R
1180 ;; uses LINPACK primarily, rather than LAPACK. See comments in R
1181 ;; source for issues.
1184 ;; Goal is to start from X, Y and then realize that if
1185 ;; Y = X \beta, then, i.e. 8x1 = 8xp px1 + 8x1
1186 ;; XtX \hat\beta = Xt Y
1187 ;; so that we can solve the equation W \beta = Z where W and Z
1188 ;; are known, to estimate \beta.
1190 ;; the above is known to be numerically instable -- some processing
1191 ;; of X is preferred and should be done prior. And most of the
1192 ;; transformation-based work does precisely that.
1194 ;; recall: Var[Y] = E[(Y - E[Y])(Y-E[Y])t]
1195 ;; = E[Y Yt] - 2 \mu \mut + \mu \mut
1196 ;; = E[Y Yt] - \mu \mut
1198 ;; Var Y = E[Y^2] - \mu^2
1201 ;; For initial estimates of covariance of \hat\beta:
1203 ;; \hat\beta = (Xt X)^-1 Xt Y
1204 ;; with E[ \hat\beta ]
1205 ;; = E[ (Xt X)^-1 Xt Y ]
1206 ;; = E[(Xt X)^-1 Xt (X\beta)]
1207 ;; = \beta
1209 ;; So Var[\hat\beta] = ...
1210 ;; (Xt X)
1211 ;; and this gives SE(\beta_i) = (* (sqrt (mref Var i i)) adjustment)
1214 ;; from docs:
1216 (setf *temp-result*
1217 (let ((*default-implementation* :foreign-array))
1218 (let* ((m 10)
1219 (n 10)
1220 (a (rand m n))
1221 (x (rand n 1))
1222 (b (m* a x))
1223 (rcond (* (coerce (expt 2 -52) 'double-float)
1224 (max (nrows a) (ncols a))))
1225 (orig-a (copy a))
1226 (orig-b (copy b))
1227 (orig-x (copy x)))
1228 (list x (gelsy a b rcond))
1229 ;; no applicable conversion?
1230 ;; (m- (#<FA-SIMPLE-VECTOR-DOUBLE (10 x 1))
1231 ;; (#<FA-SIMPLE-VECTOR-DOUBLE (10 x 1)) )
1232 (v- x (first (gelsy a b rcond))))))
1235 (princ *temp-result*)
1237 (setf *temp-result*
1238 (let ((*default-implementation* :lisp-array))
1239 (let* ((m 10)
1240 (n 10)
1241 (a (rand m n))
1242 (x (rand n 1))
1243 (b (m* a x))
1244 (rcond (* (coerce (expt 2 -52) 'double-float)
1245 (max (nrows a) (ncols a))))
1246 (orig-a (copy a))
1247 (orig-b (copy b))
1248 (orig-x (copy x)))
1249 (list x (gelsy a b rcond))
1250 (m- x (first (gelsy a b rcond)))
1252 (princ *temp-result*)
1255 (defparameter *xv*
1256 (make-vector
1258 :type :row ;; default, not usually needed!
1259 :initial-contents '((1d0 3d0 2d0 4d0 3d0 5d0 4d0 6d0))))
1261 (defparameter *y*
1262 (make-vector
1264 :type :row
1265 :initial-contents '((1d0 2d0 3d0 4d0 5d0 6d0 7d0 8d0))))
1267 ;; so something like (NOTE: matrices are transposed to begin with, hence the incongruety)
1268 (defparameter *xtx-1* (m* *xv* (transpose *xv*)))
1269 (defparameter *xty-1* (m* *xv* (transpose *y*)))
1270 (defparameter *rcond-in* (* (coerce (expt 2 -52) 'double-float)
1271 (max (nrows *xtx-1*)
1272 (ncols *xty-1*))))
1274 (defparameter *betahat* (gelsy *xtx-1* *xty-1* *rcond-in*))
1276 ;; (#<LA-SIMPLE-VECTOR-DOUBLE (1 x 1)
1277 ;; 1.293103448275862>
1278 ;; 1)
1280 ;; ## Test case in R:
1281 ;; x <- c( 1.0, 3.0, 2.0, 4.0, 3.0, 5.0, 4.0, 6.0)
1282 ;; y <- c( 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0)
1283 ;; lm(y~x-1)
1284 ;; ## =>
1285 ;; Call:
1286 ;; lm(formula = y ~ x - 1)
1288 ;; Coefficients:
1289 ;; x
1290 ;; 1.293
1292 (first *betahat*))
1297 (type-of #2A((1 2 3 4 5)
1298 (10 20 30 40 50)))
1300 (type-of (rand 10 20))
1302 (typep #2A((1 2 3 4 5)
1303 (10 20 30 40 50))
1304 'matrix-like)
1306 (typep (rand 10 20) 'matrix-like)
1308 (typep #2A((1 2 3 4 5)
1309 (10 20 30 40 50))
1310 'array)
1312 (typep (rand 10 20) 'array)
1315 ;;;;;;;;;;;;;;;;; ===========
1317 (defparameter *my-df-trees*
1318 (make-instance 'dataframe-array
1319 :storage
1320 (listoflist->array
1321 (transpose-listoflist
1322 (rsm.string:file->number-table
1323 (localized-pathto "Data/trees.csv"))))
1324 :doc "This is an interesting dataframe-array that currently fails"))
1326 ;; *my-df-trees*
1328 (defparameter *my-df-trees2*
1329 (make-instance 'dataframe-array
1330 :storage
1331 (listoflist->array
1332 (transpose-listoflist
1333 (rsm.string:file->number-table
1334 (localized-pathto "Data/trees.csv")
1335 :delims ",")))
1336 :doc "This is an interesting dataframe-array that currently fails"))
1337 ;; *my-df-trees2*
1338 ;; (dataset *my-df-trees2*)
1340 (defparameter *my-df-trees2a*
1341 (make-instance 'dataframe-array
1342 :storage
1343 (listoflist->array
1344 (rsm.string:file->number-table
1345 (localized-pathto "Data/trees.csv")
1346 :delims ","))
1347 :doc "This is an interesting dataframe-array that currently fails"))
1349 ;; *my-df-trees2a*
1350 ;; (dataset *my-df-trees2a*)