Creates one slider control for each of the given sequence bindings.
Each slider calls the given expression when manipulated.
Examples:
(use '(incanter core stats charts))
;; manipulate a normal pdf
(let [x (range -3 3 0.1)]
(def pdf-chart (xy-plot))
(view pdf-chart)
(sliders [mean (range -3 3 0.1)
stdev (range 0.1 10 0.1)]
(set-data pdf-chart [x (pdf-normal x :mean mean :sd stdev)])))
;; manipulate a gamma pdf
(let [x (range 0 20 0.1)]
(def pdf-chart (xy-plot))
(view pdf-chart)
(sliders [rate (range 0.1 10 0.1)
shape (range 0.1 10 0.1)]
(set-data pdf-chart [x (pdf-gamma x :rate rate :shape shape)])))
;; find the start values of a non-linear model function
(use '(incanter core charts datasets))
;; create model function used in the following data-sorcery post:
;; http://data-sorcery.org/2009/06/06/fitting-non-linear-models/
(defn f [theta x]
(let [[b1 b2 b3] theta]
(div (exp (mult (minus b1) x)) (plus b2 (mult b3 x)))))
(with-data (get-dataset :chwirut)
(view $data)
(def chart (scatter-plot ($ :x) ($ :y)))
(view chart)
(add-lines chart ($ :x) (f [0 0.01 0] ($ :x)))
;; manipulate the model line to find some good start values.
;; give the index of the line data (i.e. 1) to set-data.
(let [x ($ :x)]
(sliders [b1 (range 0 2 0.01)
b2 (range 0.01 2 0.01)
b3 (range 0 2 0.01)]
(set-data chart [x (f [b1 b2 b3] x)] 1))))
Comments top
No comments for sliders. Log in to add a comment.