The following example uses the Big sample data table to walk you through using the basic features of the Formula Editor. You can find Big in the sample data folder, which was installed when you installed JMP.
Big has a column called weight. Suppose you want a new column that computes standardized weight values.
Open Big
Select Cols > New Column.
Type the new name, Standard Weight, in the box beside Column Name.
Select Formula from the Column Properties menu.
When you create a formula and Show Boxing is checked, the selected portion of the formula is outlined with a thin red line. See Hide and Show Boxing. All terms within the smallest nesting box relative to the place that you clicked become selected, and the subsequent action applies to those combined elements.
While the initial missing term is selected, click weight in the formula element browser column selector list.
Click weight again.
Select Col Mean from the Statistical list.
Click weight again from the column selector list.
Select Col Std Dev from the Statistical list.
Building a Formula
In the data table, the new Standard Weight column fills with values. When a weight value changes, the calculated Standard Weight value automatically recalculates.
Suppose you want to compute the slope in a simple linear regression of y on x using the standard formula shown in Local Variables in a Formula. One way to do this is to create two local variables, and name them XY and Xsqrd. (See Use Local Variables.) Then assign them to the numerator and the denominator calculations of the slope formula. Delimit each assignment with a semicolon, as shown in Local Variables in a Formula. (Statements in the Formula Editor are actually JSL programming statements. Multiple statements in a formula must be separated by a semicolons.) The slope computation is simplified to XY divided by Xsqrd.
Local Variables in a Formula
Note: You can also create local variables using the button on the on-screen keypad. Clicking this button creates a local variable with a default name in an expression and places a semicolon after it. The default name is t1, and additional local variables are named t2, t3, and so on. You can change these default names by double-clicking and editing the name. However, you must be careful to rename each instance of the variable to avoid errors.
The following examples show uses of the Munger function. In these examples, assume that there is a character column of names with “Veronica Layman” as one of its values. To simplify the examples, the literal name “Veronica Layman” is the search string instead of a column name.
This Munger example finds the blank between the first and last name, and inserts the middle initial “J.” The formula Munger("Veronica Layman", 1, " ", " J. ") inserts the middle initial J., and evaluates as Veronica J. Layman.
Double quotes are required by the Munger function for literal strings, including strings that consist of a blank or when leading or trailing blanks are part of a string.
Designate the characters to delete as the Find string in the Munger function.
Enter an empty Replace string: two quotation marks with nothing between them.
For example, the function, Munger("Veronica Layman", 1, "onic", "") removes the “onic” from Veronica and evaluates as Vera Layman.
Note: A Replace field with a null (no value) string enclosed in quotation marks is different from a Replace field with no value. If you delete the Replace string altogether, Munger shows the argument name (“Replace”) in the Formula Editor window and behaves as if that optional argument does not exist. The resulting data type can also change from character to numeric, depending on the value of the Find/Length argument.
When the Find/Length field contains characters, Munger behaves like an index function and returns the numeric position of the first instance of the search string if it exists. For example, Munger("Veronica Layman", 1, " ") searches for a single blank and finds it in position nine. If the search string is not found, Munger returns a zero. This use of Munger produces the same result as the Contains function, as shown in Character Functions in Formula Functions Reference.
Munger can extract substrings. For example, to extract only the first name, Munger("Veronica Layman", 1, 8,) starts at position one and reads through position eight. The remaining characters are ignored because the replace argument is not defined. This yields “Veronica” and produces the same result as the Substring, as shown in Character Functions in Formula Functions Reference.
An alternative way to find a substring is with a start value, any negative find value, and a no replace argument. Munger("Veronica Layman", 9, –1,) returns “Layman”.
Suppose that you want a Match conditional for the nominal variable Type from the Hot sample data table.
In the Formula Editor, select Type from the Table Columns list.
Select Conditional from the Functions list.
Select Match.
Select Add Arguments from Data.
Note: Rather than complete step 2 through step 4, hold down the SHIFT key, select Conditional from the Functions list, and then select Match.
Automatically Filling a Match Conditional Statement
If you do not want the values filled in for you, select Do Not Add from the Match list instead of Add Arguments from Data.