Commit 42b2dc4e authored by Liam M. Healy's avatar Liam M. Healy
Browse files

Merge branch 'new-feature' into system-of-units

Conflicts:
	antik.asd
parents 250eedb5 8f1a649c
;; Antik system definition
;; Liam Healy 2010-12-24 09:43:28EST antik.asd
;; Time-stamp: <2013-03-24 18:32:30EDT antik.asd>
;; Time-stamp: <2013-04-01 09:16:12EDT antik.asd>
;; Copyright 2010, 2011, 2012, 2013 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
......@@ -178,7 +178,8 @@
:components
((:module optimize
:components
((:file "one-dim")))
((:file "one-dim")
(:file "least-squares")))
(:module linear-algebra
:components
((:file "linear-algebra")))
......
;; Least squares estimation
;; Liam Healy 2013-03-29 14:16:21EDT least-squares.lisp
;; Time-stamp: <2013-03-29 15:50:57EDT least-squares.lisp>
;; Copyright 2013 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; This requires GSLL
(in-package :antik)
(export '(linear-least-squares-1d))
;;;;****************************************************************************
;;;; Linear least squares solver
;;;;****************************************************************************
;;; This should be consistent: now, 'observations is expected to be a list, 'times a grid
(defun linear-least-squares-1d (observations &optional (times #m(0.0 10.0 20.0 30.0 40.0)))
"Find the one dimensional least squares (linear regression) solution of slope and intercept.
Values returned: slope, intercept, and their standard errors."
(metabang-bind:bind
(((:values intercept slope intercept-variance covariance slope-variance sum-square-of-residuals)
(gsl:linear-fit times (grid:make-simple-grid :grid-type 'grid:foreign-array :initial-contents observations)))
(sample-variance (/ (sqrt sum-square-of-residuals) (- (grid:dim0 observations) 2))))
(declare (ignore covariance))
(values slope intercept
(* sample-variance (sqrt slope-variance))
(* sample-variance (sqrt intercept-variance)))))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment