Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sébastien Villemot
antik
Commits
8f1a649c
Commit
8f1a649c
authored
Mar 29, 2013
by
Liam M. Healy
Browse files
Add linear-least-squares-1d for one dimensional linear least squares
parent
d33a1414
Changes
2
Hide whitespace changes
Inline
Side-by-side
antik.asd
View file @
8f1a649c
;; Antik system definition
;; Liam Healy 2010-12-24 09:43:28EST antik.asd
;; Time-stamp: <2013-0
1
-2
1 18:24:57ES
T antik.asd>
;; Time-stamp: <2013-0
3
-2
9 14:18:40ED
T antik.asd>
;; Copyright 2010, 2011, 2012, 2013 Liam M. Healy
;; Distributed under the terms of the GNU General Public License
...
...
@@ -204,7 +204,8 @@
:components
((
:module
optimize
:components
((
:file
"one-dim"
)))
((
:file
"one-dim"
)
(
:file
"least-squares"
)))
(
:module
linear-algebra
:components
((
:file
"linear-algebra"
)))
...
...
optimize/least-squares.lisp
0 → 100644
View file @
8f1a649c
;; 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
)))))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment