Load the necessary Incanter libraries.
(use '(incanter core stats charts datasets))
Now load the plant-growth sample data set.
(def plant-growth (to-matrix (get-dataset :plant-growth)))
Break the first column of the data into three groups based on the treatment group variable (second column) using the group-by function,
(def groups (group-by plant-growth 1 :cols 0))
and print the means of the groups
(map mean groups) ;; returns (5.032 4.661 5.526)
View box-plots of the three groups.
(doto (box-plot (first groups)) (add-box-plot (second groups)) (add-box-plot (last groups)) view)
This plot can also be achieved using the :group-by option of the box-plot function.
(view (box-plot (sel plant-growth :cols 0) :group-by (sel plant-growth :cols 1)))
Create a vector of t-test results comparing the groups,
(def t-tests [(t-test (second groups) :y (first groups)) (t-test (last groups) :y (first groups)) (t-test (second groups) :y (last groups))])
Print the p-values of the three groups,
(map :p-value t-tests) ;; returns (0.250 0.048 0.009)
Based on these results the third group (treatment 2) is statistically significantly different from both the first group (control) and the second group (treatment 1). However, treatment 1 is not statistically significantly different than the control group.
The complete code for this example can be found here.
- Student’s t-test (Wikipedia)