LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  adding 'group by' fields in R/PowerR

    Employee
    Posted 03-31-2015 12:56

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: ryeh

    This has come up a few times, so I thought it would be best shown with a simple example. Grouping by a field is easily done with Agg/Agg Ex nodes. To do something similar with R/PowerR, we use the SPLIT function. In this simple example, say I want to find a linear model relating the 'Amount' field to the 'Year' field. But with the added twist that I want to group by the 'Group' field.

    I've parameterized the R/Power R nodes so that you can specify the field to group by, the dependent variable (yVar), and independent variable (xVar).
    Attachments:
    groupBy_with_R_PowerR.brg


  • 2.  RE: adding 'group by' fields in R/PowerR

    Employee
    Posted 04-02-2015 13:40

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: ejones

    Thanks for this. Good to know that the split() function breaks up the input dataframe into multiple dataframes. And also good to see how to cycle through each of them.

    Usually I would want to do that type of data manipulation in LAE since it does it more clearly than the R script. But in this case it doesn't add much complexity and is considerably faster to use R. Of course if you wanted to reduce the amount of data being fed into the R or PowerR nodes to save on memory you would go back to LAE nodes to set up looping.

    I wondered if the same thing could be done with the new Power R based nodes so in the attachment I've added a "Linear Regression" node. And then tested the results in two ways: 1) by calculating the model parameters of one model from the model parameters of the other model. 2) by charting the results and visually seeing that they do the same thing.
    Attachments:
    groupBy_with_R_PowerR_2.brg


  • 3.  RE: adding 'group by' fields in R/PowerR

    Employee
    Posted 04-02-2015 15:19

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: ryeh

    This is brilliant, Ernest! The "Amount ~ Group*Year" (using * for grouping) trick is much more elegant than what I posted. And it also allows for easy use with the Linear Regression node.