Ceci est une ancienne révision du document !
1
Spreadsheets are good for collecting data like temperatures, stock prices, and sports data. However, the data on its own does us little good. We need ways to analyze the data. LibreOffice Calc provides us with built-in functions to do this. In this article, we will look at a few of the simple statistical functions built into Calc. This is not meant as a thorough examination of all the functions, but more an exercise to get you comfortable using functions. Importing the Data For our data, I have collected a few months worth of stock prices on the mutual fund FFACX. You can find the data at http://pastebin.com/AeLcyM1t. The data is laid out as comma-delimited plain text. Copy the data from Pastebin. Make sure that you copy from the ”Raw Paste Data” text box. Create a new Calc document. Right-click on cell A1 and select Paste. The Text Import dialog will show. Under Separator Options, select “Separated by” and check Comma. Click OK. You now have two columns of data, the date and the price. Save the sheet.
2
Creating a Named Cell Range Throughout this article we will use the prices as our data range. Since we will use the range several times, we will name it to make the references easier. Select all the prices (cells B2:B82). The easiest way to select all the cells is to type the range B2:B82 into the cell name box on the formula toolbar and press Enter on the keyboard. Insert > Names > Define, and the “Define Name” dialog shows. Name the range “Prices”. Notice the absolute reference in the Range text box ($Sheet1.$B$2:$B$82). Names apply to a specific group of cells, so the reference is absolute. Under the Scope, we will restrict the use of this name to just Sheet1. Click Add to create the range name. Now, in any formula or function where we use the name “Prices”, it is the same as typing the cell range $Sheet1.$B$2:$B$82.
3
MAX and MIN The first two statistical functions we will look at are MAX and MIN. Both functions accept a list of values or range(s). MAX returns the maximum (or largest) value in the list. MIN does just the opposite, returning the minimum (or smallest) value in the list. Move your cursor to D4. Type in “Highest.” In the cell E4, type in the formula =MAX(Prices) You should get the result 14.16. If you look through the list of prices, you will discover this is the largest number in the list.
4
In D5 put “Lowest.” The formula for E5 is =MIN(Prices) The result is 13.57, the lowest number in the list. It is also possible to use these, or any Calc function, as an operand in a formula. For example, if we wanted to know the difference between the highest and lowest price, we could use the formula =MAX(Prices) – MIN(Prices) in cell E6. In the formula, the results of the functions are calculated first. MAX(Prices) becomes 14.16, and MIN(Prices) becomes 13.57. Then the result of 14.16-13.57 is placed in the cell E6. Place the text “Difference” in the cell D6 as a label.
5
AVERAGE, MEDIAN, and MODE In statistics there are many ways to determine just what is the typical value for a set of numbers. Among these are the arithmetic average, the median, and the mode. The arithmetic average, known to most people as simply the average, is the sum of a series of numbers divided by the number of items in the series. In Calc we use the AVERAGE function to get the arithmetic average. The median ranks the numbers from the lowest to the highest. If the number of items in the series is an odd number, it takes the one in the middle. If it is even, the median is the arithmetic average of the two center numbers. Calc uses the MEDIAN function to calculate the median for you. Mode is the number that repeats most often. If there is a tie, it uses the smallest number. Calc uses the MODE function to get the mode for you.
6
We can see the results of these three functions by putting the following formulas in the cells E7, E8, and E9. =AVERAGE(Prices) =MEDIAN(Prices) =MODE(Prices) You will notice that the results are within a few hundredths of each others. This is not true in all cases. Numbers that are much larger or much smaller than all the others can affect the average. In those cases, the mode or median might better suit your needs for a typical value. The Calc statistical functions help us to analyze the data in a Calc spreadsheet. We touched on only a few of the statistical functions. Calc has over 70 statistical functions. This is just one of many categories of functions available to us in Calc. You can get a list of all the Calc functions in the help documentation.
7
Conditional Formatting In our data set, the top and bottom are pretty close together, so the average will work good for us as the typical value for this data set. We can use conditional formatting to mark each of the prices as either above or below the average. Start by selecting all the prices in the B column (B2:B82). Since we named the range B2:B82, a quick way to select all the prices is by using the drop down arrow for the cell name box on the formula toolbar and selecting the name “Prices(Sheet1).” Format > Conditional Formatting > Condition will bring up the Conditional Formatting dialog. Select “Cell value is” from the left drop-down list. From the drop-down list in the center, select “less than.” Enter $E$7 in the text box to the right. If you want to use the median or mode for the comparison, you can use $E$8 or $E$9. We are using an absolute reference here because we want to reference the same cell regardless of what row we are formatting.
8
For the Apply Style, select “New Style” from the drop-down list. The Cell Style dialog will open. On the Organizer tab, name the style “Below Average.” Switch to the Background tab and select the Red color swatch. Click OK to close the dialog and save the new style. You will see “Below Average” is now selected as the Apply Style. Click Add to add a second condition. This time select “greater than” instead of “less than.” Use the same absolute reference, $E$7, $E$8, or $E$9, as you used in the less than condition. Once again select “New Style” for the Apply Style. Give the new style the name “Above Average”, and make the background green instead of red. OK to save the new style. OK in the Conditional Formatting dialog will save the settings. Prices that are over the average will highlight in green, and the prices below the average will highlight in red. NOTE: You can create your style for conditional formatting before creating the condition. In such a case, you would just select the style to use.
9
I hope this article has helped you to understand the use of the statistical functions demonstrated and functions in general. We saw how to use named ranges to identify cell ranges being used repeatedly. We used functions by themselves and as operands in a formula. Using conditional formatting, we highlighted certain cells to show visually the status of the cell's value. This eliminates the need to scroll back up the sheet to check the average value. Until next month, look up some functions in the help and put them to work for you. Also, play with some of the features of the conditional formatting and see what other visuals you can create. Next time, I will show you how to validate cell values.