1.3.2 Tables
A table is named columns. It can be an association list from names to columns, a hash, or a design matrix with column names, and a column can be a list, a vector, an flvector or an f64vector (see Tables). A column of numbers is a predictor or a numeric response, and a column of strings, symbols or booleans is a factor, as R’s character and logical columns are (see Categorical predictors). The formula front end fits from a table, and table->design-matrix takes numeric columns out of one:
> (define patients (list (cons "age" '(34 51 67 45)) (cons "site" '("Boston" "Portland" "Portland" "Boston")) (cons "dose" #(2.5 5.0 1.0 3.5)) (cons "response" '(3.1 5.2 1.9 4.0)))) > (table-column-names patients) '("age" "site" "dose" "response")
> (design-matrix->rows (table->design-matrix patients '("age" "dose"))) '((34.0 2.5) (51.0 5.0) (67.0 1.0) (45.0 3.5))
> (coef (formula-fit (response . ~ . age + dose + site) patients #:lambda 0.1))
'(("(Intercept)" . 1.2675630080533637)
("age" . 0.0)
("dose" . 0.7608123306488788)
("sitePortland" . 0.0))