Mathematica is a powerful tool for calculations and graphics.  However, the language of Mathematica can be very complex.  If you miss a comma or don't use a function that seems unwarranted, your calculation or graphics may not work.  Hours could be spent trying to understand and fix the problem.

I created a program that had practical applications in science.  A crucial part of scientific method is to analyze data.  There are several tools in the industry to assist scientists.  The software I have seen does not allow the scientist to understand the calculations he or she is making and creates graphics that have to be altered in other programs, such as Adobe Illustrator.

My program, barSimple[], allows scientists to extract and calculate their data in Mathematica and then insert that subdata into this program to ease the process in making a graph.  barSimple[] is only the first version and many improvements can be made in the future.

barSimple[] has several automatic functions such as, font and the size of the graph.  It asks the user five questions ranging from the title of the graph to the size of the ticks on the axes.  I don't like how I couldn't figure out how to "break" Mathematica's language and allow the user to not have to type in "Mathematica speak."  The questions also seem to get excessive, especially if you make a mistake, such as misspelling the title of the graph.  If I were to do another version of this, I would probably scrap the question idea and try something that presented a table or list of the questions, so that the user just needed to fill in the blanks.  It would be much easier to fix mistakes as well.  In a final version, I would like to bring in the pie and line graphs into the program, so that the user could see the data in several choices with inputting once.  

That seems to be a long way off right now.  In addition to the simple graphing program I have explored data extraction and more complex graphing.  I have initial ideas for a program that included easy extraction of data, transparent statistical analysis and user friendly graph input.

I have learned how to navigate the Mathematica Help Menu, and about the many nuances of graphing.  It is so much easier to use Mathematica than the other programs I have used.  (Joe Mazur would be proud).  My program and the graphics in Mathematica are not perfect, but they will cut down on my time spent on presenting my data in papers and posters.

Data

I will be using data from a survey taken from a statistical class throughout this project exploration.  My hope was with more time to look at some of my data from the summer to see how well parts of the program worked.

(*Download survey.csv from website*)
To best go through this document I would evaluate each cell as you go.

Off[General::spell1];
<< Graphics`Graphics`;
<< Graphics`Colors`;

Import Data

Directory[]

SetDirectory[
      DirectoryName[
        ToFileName["FileName" /. 
            NotebookInformation[SelectedNotebook[]]]]]

data = Import["survey.csv"];

TableForm[data]

Easy Stats and Data Extraction

My first sub-project, exploring options and how Mathematica worked, was to compare brown haired males with brown haired females.  I started even smaller looking at extracting brown haired females over 66in.  I got distracted with the difficulty of extracting words in mathemaica and had to move on before I got to the statistical analysis.  My second sub-project then became answering how to extract words from my data.

How many brown haired females over 66in?

This Do loop bins the brown haired females by height.  Beyond minute programming mistakes I saw that in later versions I would want to be able to find any part of a word. The example in this data came from a user wanting to group light brown hair with  brown.

bin = Table[0, {80}];
Do[
  
If[
          data[[row, 1]] == "f"  && 
            data[[row, 8]] == "brown", 
   bin[[Round[
                  data[[row, 
                      3]] ] ]]++ ], 
{row, 2, 
          87}
];
Print["Bins for women with brown hair are "];
Return[bin];

Usage::fBrownHair = "The bins of females with brown hair.";

fBrownHair = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 4, 
          4, 3, 3, 10, 1, 0, 2, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 
          0};

marker2 = Range[1, 80]

TableForm[Transpose[{marker2, fBrownHair}]]

There are 4 women who have brown hair and are over 66in.

Numerical Extraction (Simplified Do loop from above)

bin = Table[0, {80}];
Do[
If[
          data[[row, 1]] == "f"  && 
            data[[row, 8]] == "brown", 
   bin[[Round[
                  data[[row, 
                      3]] ] ]]++ ], 
{row, 2, 
          87}
];
Print["Bins for women with brown hair are "];
Return[bin];

Usage::domainfBrownHair = "Two more than the range of heights in \
the female population of survey.csv" ;

domainfBrownHair = Range[46, 74] ;

Word Extraction

I decided to work with a column of data that had few words, but some challenges.  I chose the handed column.  The program became too challengeing, so I chose to make up a small list of data, queFarm and then moveback to the survey data.

\(\(Usage::binHandF = "types of handedness in the female population";\)\)

Usage::binCountsHandF = "Number of types of handedness in the \
female population";

HandF = data[[All, 10]]

Length[
      HandF]

Position[data[[All, 10]], _String ]

Length[Position[data[[All, 10]], _String ] ]

FarmHouse Que

processData[subdata_]:=Module[{bin, binCounts, p, n},
bin = {};
binCounts = {};
Do[
p = Position[bin, subdata[[row]] ];   
  
If[p == {},
  
   AppendTo[bin, subdata[[row]] ]; 
                        AppendTo[binCounts, 1],
  
  n = 
                          p[[1, 1]]; binCounts[[n]]++ ;                               
  
],
{row, 1, Length[subdata]}
];
  
TableForm[Transpose[{bin, binCounts}]]                                           
];

queFarm = {"cat", "dog", "cat", "horse", "cow"}

processData[queFarm]

Female Handedness

processData[HandF]

Female Handedness 2.0

I then re-grouped to look at the bigger picture.  I needed general ways to extract numbers and word data for the first part of my program.  I decided to make some improvements on the word extraction program by making it more general--its title at least.  I really wanted a way to have it compare multiple columns and not count the first row.

processWordData[subdata_]:=Module[{bin, binCounts, p, n},
bin = {};
binCounts = {};
Do[
p = Position[bin, subdata[[row]] ];   
  
If[p == {},
  
   AppendTo[bin, subdata[[row]] ]; 
                        AppendTo[binCounts, 1],
(*Print["The bins are "<>ToString[bin] ];*)
  
  n = 
                          p[[1, 1]]; binCounts[[n]]++ ;                               
   
  
],
{row, 2, Length[subdata]}                                                                       
];
  
  
TableForm[
                Transpose[{bin, binCounts}]]                                           
];

processWordData[HandF]

My next version would ask the user about similar words, such as "r"and "right" in short lists and in all lists "right"and"right/ambi".  It would also look at two columns at once and include numbers.  I worked on this for a bit, called compareBinary (see "what worked" in Project Word Extraction); I thought that I should move on again.  I would have also liked to explore the Histogram Function.  I think these Loops and minni programs are good starts to the super program I intially visualized.

BarChart

My next mini project was to look at graphing data.  I explored Graphics and focused on the BarChart.  I pulled out some options that I wanted to play with.  Some options would be automatic while others would be input by the user through questions asked by the program.

Options[
      BarChart]

\({BarStyle -> Automatic, 
BarSpacing -> 
        Automatic, 
BarGroupSpacing -> 
        Automatic, 
BarLabels -> 
        Automatic, 
BarValues -> 
        False, 
BarEdges -> 
        True, 
BarEdgeStyle -> 
        GrayLevel[0], 
BarOrientation -> 
        Vertical, 
AspectRatio -> 
        1\/GoldenRatio, 
Axes -> 
        True, 
AxesLabel -> 
        None, 
AxesOrigin -> 
        Automatic, 
AxesStyle -> 
        Automatic, 
Background -> 
        Automatic, 
ColorOutput -> 
        Automatic, 
DefaultColor -> 
        Automatic, 
DefaultFont :> $DefaultFont, 
DisplayFunction :> $DisplayFunction, 
Epilog -> {}, 
      FormatType :> $FormatType, 
Frame -> 
        False, FrameLabel -> None, 
FrameStyle -> 
        Automatic, 
FrameTicks -> 
        Automatic, 
GridLines -> 
        None, 
ImageSize -> 
        Automatic, 
PlotLabel -> 
        None, 
PlotRange -> 
        Automatic, 
PlotRegion -> 
        Automatic, 
Prolog -> {}, 
RotateLabel -> 
        True, 
TextStyle :> $TextStyle, 
Ticks -> Automatic}\)

Simple Graph

simpleBar=BarChart[fBrownHair,
BarStyle->RGBColor[1, 0, 1],   
BarLabels -> Automatic,   
BarValues -> False,   
BarEdgeStyle -> GrayLevel[0],           
AxesLabel->{"Height (in)", "Bins"},   
AxesOrigin -> Automatic,   
ImageSize -> 72 10,
PlotLabel->StyleForm["Female Height (in)",FontSize -> 16,FontWeight -> "Bold"],
PlotRange->{{46, 74}, {0, 10}},
 (*TextStyle:>*)  TextStyle -> {FontFamily -> "Helvetica"} ,  
Ticks->{Range[46, 74],Table[2  x, {x, 0, 5}]}];

RGBColor

One of my explorations included how to have the user input color in the simplest way.  Hues was too complicated and I found this RGBColor function with many built in options.  To see the color easily I made a program called optionColor.

RGBColor[AllColors]

Usage::optionColor = "Input an RGBColor to see the color and \
RGBColor numerical quantity.";

optionColor[rgbcolor_] := 
      Module[{}, 
Print["rgbcolor"];    
color = 
          rgbcolor; 
Print[
          rgbcolor]; 
Show[
          Graphics[
{color, 
              Disk[{0, 0}, 1]}, 
ImageSize -> 
              50
]];
]

optionColor[PermanentGreen]

My BarChart program

I outlined my program into what I wanted the program to do automatically and what options I wanted the user to be asked (noted in yellow).

barSimple[subdata_]:=Module[{},
BarChart[subdata,

  
BarLabels -> Automatic, 
BarValues -> False, 
BarEdgeStyle -> 
                    GrayLevel[0],
AxesOrigin -> Automatic,
ImageSize -> 72 10,
\(TextStyle -> {FontFamily -> "Helvetica"}\),

  
BarStyle->RGBColor[1, 0, 1],
AxesLabel->{"Height (in)", "Bins"},
PlotLabel->StyleForm["Female Height (in)",FontSize -> 16,FontWeight -> "Bold"],
PlotRange->{{46, 74}, {0, 10}},
Ticks->{Range[46, 74],Table[2  x, {x, 0, 5}]}]

];

barSimple[fBrownHair]

Most recent versions

barSimple4[subdata_]:=Module[{barColor, axesLabel, plotLabel, plotRange, ticks},
  
barColor = 
                  Input["What color do you want the bars to be?"];
Print["The color of the bars is \
" <> ToString[barColor]];
axesLabel=Input["What do you want to call the x and y axes?  Form: {\"x-axis\",\"y-axis\"}"]; Print["The x and y axes are " <> 
                      ToString[axesLabel]];
plotLabel = 
                    Input["What do you want to title the graph? Use quotes.\
"]; 
Print["The title of the graph is " <> 
                      ToString[plotLabel]];
plotRange = 
                    Input["What do you want the x and y range to be of the \
graph? Form: {{xmin, xmax},{ymin,ymax}}"];
Print["The ranges of the x and y axes are " <> 
                      ToString[plotRange]];
ticks = 
                    Input["What incremental range do you want the axes to \
be?  Form: {x-axes,y-axes} with {xmin, xmax},{ymin,ymax} or Range[min,max] or \
Table[x,{x,min,max}] "]; 
Print["The increments of the axes are " <> 
                      ToString[ticks]];
BarChart[subdata,

BarLabels -> Automatic, 
BarValues -> False, 
BarEdgeStyle -> 
                      GrayLevel[0],
AxesOrigin -> Automatic, 
ImageSize -> 72 10,
\(TextStyle -> {FontFamily -> "Helvetica"}\) ,

BarStyle->barColor,
AxesLabel->axesLabel,
PlotLabel->StyleForm[plotLabel,FontSize -> 16,FontWeight -> "Bold"],
PlotRange->plotRange,
  
Ticks->ticks
];
];

barSimple4[fBrownHair]

I was not able, because of time, to program all the error checks for each question.  Some make errors from Mathematica iteself, imediately.  (Try it with axesLabel, the second question).  I would have to break down the program into smaller questions, something I don't want to do because I think it is asking too many questions already; or, I would have to figure out a way to override or incorporate Mathematica's error message into my program.  Since I want to scrap this model anyway because there isn't a easy way to correct user spelling mistakes, I see no logical reason to continue.

barSimple5[subdata_]:=Module[{barColor, barColorAnswer, axesLabel, plotLabel, 
                plotRange, ticks},
  
barColor = 
                  Input["What color do you want the bars to be?"];
barColorAnswer = True;
\(While[
                  barColorAnswer, 
\(If[\ 
                      Head[barColor] === 
                        RGBColor, 
Print["The color of the bars is " <> ToString[barColor]]; 
barColorAnswer = 
                        False, 
barColor = 
                        Input["Incorrect language.  Check spelling and use capitals.  What color do you want?"]
];\)
]\);
axesLabel=Input["What do you want to call the x and y axes?  Form: {\"x-axis\",\"y-axis\"}"]; Print["The x and y axes are " <> 
                      ToString[axesLabel]];
plotLabel = 
                    Input["What do you want to title the graph? Use quotes.\
"]; 
Print["The title of the graph is " <> 
                      ToString[plotLabel]];
plotRange = 
                    Input["What do you want the x and y range to be of the \
graph? Form: {{xmin, xmax},{ymin,ymax}}"];
Print["The ranges of the x and y axes are " <> 
                      ToString[plotRange]];
ticks = 
                    Input["What incremental range do you want the axes to \
be?  Form: {x-axes,y-axes} with {xmin, xmax},{ymin,ymax} or Range[min,max] or \
Table[x,{x,min,max}] "]; 
Print["The increments of the axes are " <> 
                      ToString[ticks]];
BarChart[subdata,

BarLabels -> Automatic, 
BarValues -> False, 
BarEdgeStyle -> 
                      GrayLevel[0],
AxesOrigin -> Automatic, 
ImageSize -> 72 10,
\(TextStyle -> {FontFamily -> "Helvetica"}\) ,

BarStyle->barColor,
AxesLabel->axesLabel,
PlotLabel->StyleForm[plotLabel,FontSize -> 16,FontWeight -> "Bold"],
PlotRange->plotRange,
  
Ticks->ticks
];
];

barSimple5[fBrownHair]

barSimpleExp[] is just where I experimented with parts of the program.  I was able to make more options automatic, so I would not have to abort the program when seeing how the program ran when working with one piece.

Off[General::spell1];
barSimpleExp[subdata_]:=Module[{barColor, axesLabel, plotLabel, plotRange, ticks},
  
Print["line one"];
barColor = 
                    Input["What color do you want the bars to be?"];
Print["line two"];

barColorAnswer = True;
\(While[
                    barColorAnswer, 
\(If[\ 
                        Head[barColor] === 
                          RGBColor, 
Print["The color of the bars is " <> ToString[barColor]]; 
barColorAnswer = 
                          False, 
barColor = 
                          Input["Incorrect language.  Check spelling and use capitals.  What color do you want?"]
];\)
]\);

(*  \(correct = 
                        If[\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \  (*Do\ loop\ don' 
                              t\ go\ back*) 
Print["Entered correct"]; 
Head[barColor] === 
                            RGBColor, 
Print["then correct"]; 
 (*then*) \ 
                          Print["The color of the bars is " <> 
                              ToString[
                                barColor]], 
Print["else correct"]; 
 (*else*) barColor = 
                            Input["Incorrect language.  Check spelling and use capitals.  What color do you want?"] && 
                              Do[tryAgain2]
]; 

tryAgain2 = 
                        If[Print["Entered tryAgain"]; 
Head[barColor] === 
                            RGBColor, 
Print["then tryAgain"]; 
Print["The color of the bars is " <> 
                              ToString[
                                barColor]], 
Print["else tryAgain"]; 
Do[correct]
];\)  *)


Print["line three"];
axesLabel=Input["What do you want to call the x and y axes?  Form: {x-axis,y-axis}"]; 
Print["line four"];
Print["The x and y axes are " <> 
                        ToString[axesLabel]];
  
BarChart[subdata,

BarLabels -> Automatic, 
BarValues -> False, 
BarEdgeStyle -> 
                        GrayLevel[0],
AxesOrigin -> Automatic, 
ImageSize -> 72 8,
\(TextStyle -> {FontFamily -> "Helvetica"}\) ,

BarStyle->barColor,
(* BarStyle->RGBColor[1, 0, 1], *)
AxesLabel->axesLabel,
(* AxesLabel->{"Height (in)", "Bins"}, *)
(* PlotLabel->StyleForm[plotLabel,FontSize -> 16,FontWeight -> "Bold"],*)
PlotLabel->StyleForm["Female Height (in)",FontSize -> 16,FontWeight -> "Bold"], 
(* PlotRange->plotRange,*)
PlotRange->{{46, 74}, {0, 10}}, 
  
(* Ticks->ticks*)
Ticks->{Range[46, 74],Table[2  x, {x, 0, 5}]}

];
];

barSimpleExp[fBrownHair]

Improvements

If I were Super Computer Programming Lisa, I would liked to have gotten a cohesive program to do all of the above plus have three graphing options.  The user would be able to input one set of data and then chose which graphs he or she would want to see.

BarChart

\(\(bar = 
        BarChart[
          fBrownHair, 
BarStyle -> 
            RGBColor[1, 0, 
              1], \  (*\ \ Does\ Color\ only\ apply?\ \ How\ do\ you\ change\ the\ \(\(barwidth\)\(?\)\)*) 
BarSpacing -> 
            1.75, \  (*\ \(changes\ barwidth ... \)\ 0\ same\ as\ \(\(automatic\)\(?\)\)\ *) 
BarGroupSpacing -> 
            0, 
BarLabels -> 
            Automatic, 
BarValues -> False, \  (*\ 
            True/False\ y\ value\ appears\ above\ bar\ *) 
BarEdges -> True, \  (*\ 
            Outlines\ bar\ in\ BarEdgeStyle*) 
BarEdgeStyle -> GrayLevel[0], \  (*\ 
            Graylevel\ 0 - Black\ to\ 1 - White\ *) \ \ \  (*\ 
            Can\ use\ RGBColor[0, 0, 
                0]\ *) 
BarOrientation -> 
            Vertical, \  (*\ \(Dependent\ on\ graph\ structure ... \)\ what\ you\ want*) 
AspectRatio -> 
            1\/GoldenRatio,  (*\ \(Perspective ... \) Don' t\ mess\ with; \ 
            it\ is\ golden*) 
Axes -> True, \  (*\ 
            Whether\ or\ not\ axes\ exist\ *) 
AxesLabel -> {"Height (in)", "Bins"}, 
AxesOrigin -> Automatic, 
AxesStyle -> 
            Automatic, 
Background -> 
            Automatic, 
ColorOutput -> 
            Automatic, 
DefaultColor -> 
            Automatic, 
DefaultFont :> $DefaultFont, 
DisplayFunction :> $DisplayFunction, 
Epilog -> {}, \  (*\ 
            Things\ to\ do\ after\ graph*) 
FormatType :> $FormatType, 
Frame -> 
            False, 
FrameLabel -> 
            None, 
FrameStyle -> 
            Automatic, 
FrameTicks -> 
            Automatic, 
GridLines -> 
            None, 
ImageSize -> 
            72\ 8, 
PlotLabel -> 
            StyleForm["Female Height (in)", FontSize -> 16, 
              FontWeight -> "Bold"], 
PlotRange -> {{46, 74}, {0, 10}}, 
PlotRegion -> 
            Automatic, 
Prolog -> {}, \  (*\ 
            Things\ to\ do\ before\ graph\ *) 
RotateLabel -> False, \  (*\ \(Rotates\ label ... \)\ May\ only\ apply\ to\ frame\ *) 
 (*\(TextStyle\)\(:>\)*) \ 
          TextStyle -> {FontFamily -> "Helvetica"}\ ,  (*Automatic : \ \ $TextStyle\ *) 
Ticks -> {domainfBrownHair, Automatic}];\)\)

PieChart

pie = PieChart[fBrownHair];

(*Change to distinct colors; Not include counts of zero...or decrease domain.  Put in y value*)

LineGraph

line = 
        ListPlot[fBrownHair,  PlotRange -> {{46, 74}, {0, 10}},  
          PlotJoined -> True ];

Buttons

BarChartPieChartDotGraph

Supplemental work can be found on my website in all the files begining with Project.