A stripped version of linear-model that returns a map containing only
the coefficients.
(defn simple-regression
"A stripped version of linear-model that returns a map containing only
the coefficients."
([y x & options]
(let [opts (when options (apply assoc {} options))
intercept? (if (false? (:intercept opts)) false true)
_x (if intercept? (bind-columns (replicate (nrow x) 1) x) x)
xtx (mmult (trans _x) _x)
xtxi (if (number? xtx) (/ 1 xtx) (solve xtx))
xty (mmult (trans _x) y)
coefs (if (and (number? xtxi) (number? xty))
(* xtxi xty)
(to-list (if (or (number? xtxi) (number? xty))
(mult xtxi xty)
(mmult xtxi xty))))]
{:coefs coefs})))
Comments top
No comments for simple-regression. Log in to add a comment.