R Models

Insight gives the possibility to calculate and create R models based on the data from Insight.

R models in Insight have a similar structure as records.

  1. In Studio, on the Documents Tree, right-click R Models, and select New R Model.
  2. Assign a unique, descriptive name to the new model and click OK.
  3. Map the fields based on which the calculation is based and also the field to be calculated. In the sample screen below, three fields are mapped: Freight, OrderDate, and ShipCountry, which means that these three lines will be pulled from the source record and later used for the R model calculation.
  4. Open the User script tab and create the R script manually. For example, the following script to calculate the model predicts Freight by ShipCountry. OutputModel <- lm(Freight ~ ShipCountry, data = InputData). In the script, you can use any mapped field by the field ID.
    • InputData in this script is the data frame with three columns that are mapped on Mapping: Freight, OrderDate, and ShipCountry. In the example, only Freight and ShipCountry are used.

    • OutputModel is the created model.

    The OrderDate field that is mapped on the Mapping tab is used for the time filter that you can check and edit under the Filters tab, Time Filter section. You can also add the time/date filter without mapping any time field.
  5. In the Property Panel, find the Model variable name setting and name the variable that you want to use as a model in the script. In our example, we named it OutputModel.
  6. Save the R model.
  7. Open the Tools tab on the toolbar and click Generate R Model.
    The Select date time interval window appears.
  8. Define the time interval for generating the R model with the help of calendar controls and click OK.
    The R model is generated and can be used for R functions.