How to use the Rules Builder node to create new variables?

How to use the Rules Builder node to create new variables?

book

Article ID: KB0074126

calendar_today

Updated On:

Products Versions
Spotfire Statistica 14.0 and higher

Description

Description: This article shows an example of how to use the "Rules Builder" node to create new variables based on different conditions. The Activities.sta data from Statistica Example datasets folder will be used. For demonstration purpose, participants with Sleep score larger than 780 in this data will be classified as "Sleep_High" group. Otherwise, they will be classified as "Sleep_Low" group. And two new variables "Sleep_Group" and "FollowUp" will be created. 
 

Environment

OS:  Windows

Resolution

1. Under File|Open Examples|Datasets folder, select "Activities.sta" to open it in Statistica and click Home|Add to New Workspace.

2. Search "Rules" in "Feature Finder" box on top right and add it to the workspace.

image.png

3. Click "Edit Parameters" (the wheel icon) on top left of "Rules" node to open Rules edition dialog.

4. Click "Input Variables to Copy" to select variables you want to display in the final spreadsheet. In this example, select all.

image.png

5. Under "Input Variables to Copy", there are a few options selected by default. Make sure you understand each option and select them appropriately. Illustration of those options in the e-manual can be accessed by clicking "?" on top right. In this example, deselect "Treat Missing Data as Error" and "Output Error variable".

image.png

 

6. Click "Edit" button under Rules to open "Rules Builder" dialog. Note: To import rules you saved, lick "Linked".

image.png


7. Click "New Nodes..." to browse drill-down options and select "If()". When the "Edit If Condition" dialog is prompted, type: "Sleep" > 780.

image.png

 

image.png

8. Select the first child "New node..." under the "If" condition and select "Variable = Formula".

image.png

 

9. In the prompted "Edit Formula" dialog, specify the new variable name and its formula. In this example, enter "Sleep_Group" = "Sleep_High" and click "OK".

image.png

 

10. Similarly, select the second child "New Node..." under the same "If" condition and select "Variable = Formula" again for the second new variable. In this example, enter "FollowUp" = "No" and click "OK".

image.png

image.png

 

 

Note: The drill-down options for a [New Node...] contain other commands for different actions such as building a nested if condition, selecting an existing model for execution, import existing rules from a file or Enterprise and etc   Click "?" on top right to learn more about those command options in e-manual.

11. Click a new parent "New node..." and select "Else".

image.png

 

12. Under "Else", click the first child "New node..." and select "Variable = Formula" to enter "Sleep_Group"="Sleep_Low".Click "OK". After that, click the second child "New node..." and select "Variable = Formula" to enter "FollowUp" = "Yes"'. Click "OK'.
Note: After the rules are specified, you can click "Save" on the right panel to save the defined rules in Rules Builder file, text file or XML file, that can be inked/copied to other rules builder node. 

image.png

image.png

13. Click "OK" in the Rules dialog after all rules are defined. Run the "Rules" node through the "Run to the Node" button (the green arrow icon) in the workspace to generate the new spreadsheet. In the resulted spreadsheet, you will notice that two new variables are created in the last two columns depending on the value of "Sleep".

image.png

For more information regarding Rules Builder node, please click on the ? icon:


image.png

Issue/Introduction

How to use the Rules Builder node to create new variables?

Additional Information