(defn find-ranks [data] (let [idx-data (map #(vector %1 %2) (range 1 (+ 1 (count data))) (sort data)) compressed-data (compress (sort data)) ranks (loop [i 0 idx idx-data result []] (if (empty? idx) (apply vector (apply concat result)) (recur (inc i) (let [num (first (nth compressed-data i))] (drop num idx)) (conj result (let [nums (first (nth compressed-data i))] (repeat nums (/ (apply + (map first (take nums idx))) (* 1.0 nums))))))))] ranks)) (defn brittleness [testdata data model distance] (let [together (if (= (nrow model) 1) model (group-by model (- (ncol data) 1)))] (loop [td testdata results (transient [])] (if (empty? td) (persistent! results) (recur (rest td) (conj! results (let [together1 (if (= (nrow together) 1) (if (not= (last (first td)) (last together)) together [nil]) (filter #(not= (last (first td)) (last (first (if (= (nrow %) 1) [%] %)))) together)) all-test-nearest (if (= (first together1) nil) 2.5 (first (sort (map #(get-nearest-distance (first td) (if (= (nrow %) 1) [%] %) distance) together1))))] all-test-nearest)))))))