using MAT all_vars= matread("sampledata2.mat") d = all_vars["data"] # ----------------------- Q2 length(filter(x -> x > 5, d[:, 2])) / length(d[:, 2]) # 0.19, so first statement is false length(filter(x -> x > 50, d[:, 1])) # 56x over 50 length(filter(x -> x < 20, d[:, 1])) # 4x under 20 # second statement is true length(filter(x -> x < 5, d[:, 2])) # 243 length(filter(x -> x > 6, d[:, 2])) # 34 # third statement is false length(filter(x -> x > 0.5, d[:, 3])) / length(d[:, 3]) # 0.5233333333333333 # last statement is false # ----------------------- Q3 using Winston # TODO: this foldl business is ugly with_cancer = foldl(vcat, filter(x -> x[3] > 0.5, [d[row, :] for row = 1:size(d,1)])) without_cancer = foldl(vcat, filter(x -> x[3] < 0.5, [d[row, :] for row = 1:size(d,1)])) figure() p = FramedPlot() add(p, Histogram(hist(with_cancer[:, 1], 15:10:75)..., color="red")) # 1 NO (this is "without") # 2 yes # 3 NO # 4 NO # ----------------------- Q4 add(p, Histogram(hist(without_cancer[:, 1], 15:10:75)..., color="green")) # 1 YES # ----------------------- Q5 function fractional(f, d) return length(filter(f, d)) / length(d) end fractional(x -> x>55, without_cancer[:, 1]) #0.013986013986013986 fractional(x -> x<25, without_cancer[:, 1]) #0.08391608391608392 # FALSE fractional(x -> x<35, without_cancer[:, 1]) # FALSE fractional(x -> x<30, with_cancer[:, 1]) / fractional(x -> x>60, with_cancer[:, 1]) # TRUE! fractional(x -> x>45, with_cancer[:, 1]) # FALSE # ----------------------- Q6 fractional(x -> x>35, with_cancer[:, 1]) # 0.802547770700637 # ----------------------- Q7 fractional(x -> x<25, d[:, 1]) # 0.06 # ----------------------- Q8 drinkers = foldl(vcat, filter(x -> x[2] > 3, [d[row, :] for row = 1:size(d,1)])) fractional(x -> x >0.5, drinkers[:, 3]) # 0.6459627329192547