
BeginPackage["StatPlots`",{"Statistics`DescriptiveStatistics`"}]

StatPlots::usage = "StatPlots defines some statistical plots including RangePlot and QuartilePlot."

TriplePlot::usage = "TriplePlot[{{x1,y1,z1},...{xn,yn,zn}}] plots points yi with error bars going from xi to zi."

QuartilePlot::usage = "QuartilePlot[{{x1,...,xm},..,{z1,...,zm}}] the quartiles of each sublist."

RangePlot::usage = "RangePlot[{{x1,...,xm},...{z1,...,zm}}] the min, mean, and max of each sublist."

ReadData::usage = "ReadData[filename,nPlayers] reads in data from filename.  Returns {pay, choice, card} lists."

Begin["`Private`"]

(* auxiliary functions *)

MinMeanMax[data_] := {Min[data],Mean[data],Max[data]}               

(* exported functions *)

ReadData[filename_,nPlayers_] :=
  Module[{rawdata,tRawdata},
	rawdata=ReadList[filename,Number,RecordLists->True];
    tRawdata=Transpose[rawdata];           
    {Partition[tRawdata[[5]],nPlayers],
     Partition[tRawdata[[11]],nPlayers],
     Partition[tRawdata[[13]],nPlayers]}
        ]   


TriplePlot[l3:{{_, _, _}..}] :=
        Show[ Graphics[ { PointSize[0.015], Thickness[0.002],
                Module[ {i, y, up,dn} , 
                Table[ 
                        {i,up, y, dn} = Join[{i},l3[[i]]] ;
                        { Line[ {{i, dn}, {i, up}} ],
                        Point[ {i, y} ] } ,
                        {i, Length[l3]}
                ] ] } ], Axes -> Automatic,AxesOrigin->{0,0}]

QuartilePlot[data_] := TriplePlot[Map[Quartiles,data]]

RangePlot[data_] := TriplePlot[Map[MinMeanMax,data]]


End[] 
EndPackage[]
