Salut Mircea
Linear regression assure that the sum of differences between a series of values (e.g. y) and the approximation line is minimum.
It is working good if data meet some criteria.
For example, set your points around a vertical line, then use simple linear regression (like Lee's lisp. BTW Lee, your code is amazing).
Here is my lisp, using a formula from another (surprisingly) domain.
(defun C:TEST ( / vxv ss i n l o d dx dy a)
(defun vxv (a b) (apply '+ (mapcar '* a b)))
(if
(setq ss (ssget '((0 . "POINT"))))
(progn
(repeat (setq i (sslength ss) n i)
(setq l (cons (cdr (assoc 10 (entget (ssname ss (setq i (1- i)))))) l))
)
(setq o (mapcar '/ (apply 'mapcar (cons '+ l)) (list n n))
d (mapcar '(lambda (a) (mapcar '- o a)) l)
dx (mapcar 'car d)
dy (mapcar 'cadr d)
a (* 0.5 (atan (* 2 (vxv dx dy)) (- (vxv dx dx) (vxv dy dy))))
)
(entmake
(list
'(0 . "XLINE")
'(100 . "AcDbEntity")
'(100 . "AcDbXline")
'(62 . 1)
(cons 10 o)
(list 11 (cos a) (sin a) 0.0)
)
)
)
)
(princ)
)