Teradata R Package Function Reference | 17.00 - 17.00 - Attribution - Teradata R Package

Teradata® R Package Function Reference

prodname
Teradata R Package
vrm_release
17.00
created_date
September 2020
category
Programming Reference
featnum
B700-4007-090K

Description

The Attribution function is used in web page analysis, where it lets companies assign weights to pages before certain events, such as buying a product.
The function calculates attributions with a choice of distribution models and has two versions:

  • Multiple-input: Accepts one or more input tables and gets many parameters from other dimension tables.

  • Single-input: Accepts only one input table and gets all parameters from argments.

Note: This function is only available when tdplyr is connected to Vantage 1.1 or later versions.

Usage

  td_attribution_mle (
      data = NULL,
      data.optional = NULL,
      conversion.events = NULL,
      excluding.data = NULL,
      optional.data = NULL,
      model1.type = NULL,
      model2.type = NULL,
      model1.name = NULL,
      model2.name = NULL,
      event.column = NULL,
      timestamp.column = NULL,
      window.size = NULL,
      conversion.data = NULL,
      optional.events = NULL,
      exclude.events = NULL,
      data.sequence.column = NULL,
      data.optional.sequence.column = NULL,
      conversion.data.sequence.column = NULL,
      excluding.data.sequence.column = NULL,
      optional.data.sequence.column = NULL,
      model1.type.sequence.column = NULL,
      model2.type.sequence.column = NULL,
      data.partition.column = NULL,
      data.optional.partition.column = NULL,
      data.order.column = NULL,
      data.optional.order.column = NULL,
      conversion.data.order.column = NULL,
      excluding.data.order.column = NULL,
      optional.data.order.column = NULL,
      model1.type.order.column = NULL,
      model2.type.order.column = NULL
  )

Arguments

data

Required Argument.
Specifies the tbl_teradata that contains the click stream data to compute attributions.

data.partition.column

Required Argument.
Specifies Partition By columns for "data".
Values to this argument can be provided as a vector, if multiple columns are used for partition.
Types: character OR vector of Strings (character)

data.order.column

Required Argument.
Specifies Order By columns for "data".
Values to this argument can be provided as a vector, if multiple columns are used for ordering.
Types: character OR vector of Strings (character)

data.optional

Optional Argument.
Specifies the tbl_teradata that contains the click stream data, which cogroups attributes from all specified tbl_teradata.

data.optional.partition.column

Optional Argument. Required if "data.optional" is specified.
Specifies Partition By columns for "data.optional".
Values to this argument can be provided as a vector, if multiple columns are used for partition.
Types: character OR vector of Strings (character)

data.optional.order.column

Optional Argument. Required if "data.optional" is specified.
Specifies Order By columns for "data.optional".
Values to this argument can be provided as a vector, if multiple columns are used for ordering.
Types: character OR vector of Strings (character)

conversion.events

Optional Argument. "conversion.events" is a required argument if "conversion.data" is not provided.
Specifies the conversion events. Each "conversion.event" is a string or integer
Types: character OR vector of characters

excluding.data

Optional Argument.
Specifies the names of the input tbl_teradata that contains one varchar column (excluding_events) containing excluding cause event values.

excluding.data.order.column

Optional Argument.
Specifies Order By columns for "excluding.data".
Values to this argument can be provided as a vector, if multiple columns are used for ordering.
Types: character OR vector of Strings (character)

optional.data

Optional Argument.
Specifies the names of the input tbl_teradata contains one varchar column (optional_events) containing optional cause event values.

optional.data.order.column

Optional Argument.
Specifies Order By columns for "optional.data".
Values to this argument can be provided as a vector, if multiple columns are used for ordering.
Types: character OR vector of Strings (character)

model1.type

Optional Argument. "model1.type" is a required argument if "model1.name" is not provided.
Specifies the tbl_teradata that defines the type and distributions of the first model.
For example:
model1.data ("EVENT_REGULAR", "email:0.19:LAST_CLICK:NA", "impression:0.81:WEIGHTED:0.4,0.3,0.2,0.1")

model1.type.order.column

Optional Argument.
Specifies Order By columns for "model1.type".
Values to this argument can be provided as a vector, if multiple columns are used for ordering.
Types: character OR vector of Strings (character)

model2.type

Optional Argument.
Specifies the tbl_teradata that defines the type and distributions of the second model.
For example:
model2.data ("EVENT_OPTIONAL", "OrganicSearch:0.5:UNIFORM:NA", "Direct:0.3:UNIFORM:NA", "Referral:0.2:UNIFORM:NA")

model2.type.order.column

Optional Argument.
Specifies Order By columns for "model2.type".
Values to this argument can be provided as a vector, if multiple columns are used for ordering.
Types: character OR vector of Strings (character)

model1.name

Optional Argument. "model1.name" is a required argument if "model1.type" is not provided.
Specifies the type and specifcation of the first model.
For example:
Model1 ('EVENT_REGULAR', 'email:0.19:LAST_CLICK:NA', 'impression:0.81:WEIGHTED:0.4,0.3,0.2,0.1')
Types: character OR vector of characters

model2.name

Optional Argument.
Specifies the type and distributions of the second model.
For example:
Model2 ('EVENT_OPTIONAL', 'OrganicSearch:0.5:UNIFORM:NA', 'Direct:0.3:UNIFORM:NA', 'Referral:0.2:UNIFORM:NA')
Types: character OR vector of characters

event.column

Required Argument.
Specifies the name of the input column that contains the clickstream events.
Types: character

timestamp.column

Required Argument.
Specifies the name of the input column that contains the timestamps of the clickstream events.
Types: character

window.size

Required Argument.
Specifies how to determine the maximum window size for the attribution calculation:

  • rows:K: Considers the maximum number of events to be attributed, excluding events of types specified in excluding_event_table, which means assigning attributions to atmost K effective events before the current impact event.

  • seconds:K: Consider the maximum time difference between the current impact event and the earliest effective event to be attributed.

  • rows:K&seconds:K2: Consider both constraints and comply with the stricter one.

Types: character

conversion.data

Optional Argument."conversion.data" is a required argument if "conversion.events" is not provided.
Specifies the names of the input tbl_teradata that contains one varchar column (conversion_events) containing conversion event values.

conversion.data.order.column

Optional Argument.
Specifies Order By columns for "conversion.data".
Values to this argument can be provided as a vector, if multiple columns are used for ordering.
Types: character OR vector of Strings (character)

optional.events

Optional Argument.
Specifies the optional events. Each optional event is a string or integer. An "optional.event" cannot be a conversion event or exclude events. The function attributes a conversion event to an optional event only if it cannot attribute it to a regular event.
Types: character OR vector of characters

exclude.events

Optional Argument.
Specifies the events to exclude from the attribution calculation. Each "exclude.event" is a string or integer. An "exclude.event" cannot be a conversion event.
Types: character OR vector of characters

data.sequence.column

Optional Argument.
Specifies the vector of column(s) that uniquely identifies each row of the input argument "data". The argument is used to ensure deterministic results for functions which produce results that vary from run to run.
Types: character OR vector of Strings (character)

data.optional.sequence.column

Optional Argument.
Specifies the vector of column(s) that uniquely identifies each row of the input argument "data.optional". The argument is used to ensure deterministic results for functions which produce results that vary from run to run.
Types: character OR vector of Strings (character)

conversion.data.sequence.column

Optional Argument.
Specifies the vector of column(s) that uniquely identifies each row of the input argument "conversion.data". The argument is used to ensure deterministic results for functions which produce results that vary from run to run.
Types: character OR vector of Strings (character)

excluding.data.sequence.column

Optional Argument.
Specifies the vector of column(s) that uniquely identifies each row of the input argument "excluding.data". The argument is used to ensure deterministic results for functions which produce results that vary from run to run.
Types: character OR vector of Strings (character)

optional.data.sequence.column

Optional Argument.
Specifies the vector of column(s) that uniquely identifies each row of the input argument "optional.data". The argument is used to ensure deterministic results for functions which produce results that vary from run to run.
Types: character OR vector of Strings (character)

model1.type.sequence.column

Optional Argument.
Specifies the vector of column(s) that uniquely identifies each row of the input argument "model1.type". The argument is used to ensure deterministic results for functions which produce results that vary from run to run.
Types: character OR vector of Strings (character)

model2.type.sequence.column

Optional Argument.
Specifies the vector of column(s) that uniquely identifies each row of the input argument "model2.type". The argument is used to ensure deterministic results for functions which produce results that vary from run to run.
Types: character OR vector of Strings (character)

Value

Function returns an object of class "td_attribution_mle" which is a named list containing object of class "tbl_teradata".
Named list member can be referenced directly with the "$" operator using the name: result.

Note

  • The Multiple-input Attribution takes data from multiple tbl_teradata ("data.optional", "conversion.data", "excluding.data", "optional.data", "model1.type" and "model2.type").
    The arguments "data.optional", "conversion.data", "excluding.data", "optional.data", "model1.type" and "model2.type" should be mentioned together and should not be used with arguments "conversion.events", "model1.name", "optional.events", "exclude.events" and "model2.name".
    For example,
    attribution <- Attribution(data = < table | view | (query) >,
    data.partition.column = 'partition_column',
    data.order.column = 'order_column',
    data.optional = < table | view | (query) >,
    conversion.data = < table | view | (query) >,
    excluding.data = < table | view | (query) >,
    optional.data = < table | view | (query) >,
    model1.type = < table | view | (query) >,
    model2.type = < table | view | (query) >,
    event.column = 'event_column',
    timestamp.column = 'timestamp_column',
    window.size = 'rows:K | seconds:K | rows:K&seconds:K'
    )

  • The Single-input Attribution takes data from single tbl_teradata ("data") and parameters come from arguments ("conversion.events", "model1.name", "optional.events", "exclude.events" and "model2.name"), not input tbl_teradata.
    The arguments "conversion.events", "model1.name", "optional.events", "exclude.events" and "model2.name" should be used together and should not be used with arguments "data.optional", "conversion.data", "excluding.data", "optional.data", "model1.type" and "model2.type".
    For example,
    attribution <- Attribution(data = < table | view | (query) >,
    conversion.events = c('conversion_event', ...),
    timestamp.column = ”timestamp_column”,
    model1.name = c('type', 'K' | 'EVENT:WEIGHT:MODEL:PARAMETERS', ...),
    model2.name = c('type', 'K' | 'EVENT:WEIGHT:MODEL:PARAMETERS', ...),
    event.column = "event_column"
    window.size = 'rows:K | seconds:K | rows:K&seconds:K',
    optional.events = c("organicsearch", "direct", "referral"),
    data.order.column = 'order_by_column'
    )

Examples

    # Get the current context/connection
    con <- td_get_context()$connection
    
    # Load the data to run the example
    loadExampleData("attribution_example", "attribution_sample_table", "attribution_sample_table1", "attribution_sample_table2", "conversion_event_table", "optional_event_table", "model1_table", "model2_table", "excluding_event_table")
    
    # Create object(s) of class "tbl_teradata".
    attribution_sample_table <- tbl(con, "attribution_sample_table")
    attribution_sample_table1 <- tbl(con, "attribution_sample_table1")
    attribution_sample_table2 <- tbl(con, "attribution_sample_table2")
    conversion_event_table <- tbl(con, "conversion_event_table")
    optional_event_table <- tbl(con, "optional_event_table")
    model1_table <- tbl(con, "model1_table")
    model2_table <- tbl(con, "model2_table")
    excluding_event_table <- tbl(con, "excluding_event_table")
    
    # Example 1 - One Regular Model, Multiple Optional Models.
    # This example specifes one distribution model for regular events 
    # and one distribution model for each type of optional event.
    attribution_out1 <- td_attribution_mle(data = attribution_sample_table,
                                 data.partition.column = 'user_id',
                                 data.order.column = 'time_stamp',
                                 event.column = 'event',
                                 timestamp.column = 'time_stamp',
                                 window.size = 'rows:10&seconds:20',
                                 exclude.events = 'Email',
                                 conversion.events = c('SocialNetwork','PaidSearch'),
                                 model1.name = c('SEGMENT_ROWS', '3:0.5:EXPONENTIAL:0.5,ROW','4:0.3:WEIGHTED:0.4,0.3,0.2,0.1', '3:0.2:FIRST_CLICK:NA'),
                                 model2.name = c('SEGMENT_SECONDS','6:0.5:UNIFORM:NA','8:0.3:LAST_CLICK:NA','6:0.2:FIRST_CLICK:NA'),
                                 optional.events = c('OrganicSearch','Direct','Referral')
  )
  
  # Example 2 - Multiple Regular Models, One Optional Model.
  # This example specifes one distribution model for each type of regular 
  # event and one distribution model for optional events.
  attribution_out2 <- td_attribution_mle(data = attribution_sample_table,
                                         data.partition.column = 'user_id',
                                         conversion.events = c('SocialNetwork','PaidSearch'),
                                         timestamp.column = 'time_stamp',
                                         model1.name = c('EVENT_REGULAR',
                                         'email:0.19:LAST_CLICK:NA','impression:0.81:UNIFORM:NA'),
                                         model2.name = c('EVENT_OPTIONAL', 'ALL:1:EXPONENTIAL:0.5,ROW'),
                                         event.column = 'event',
                                         window.size = 'rows:10&seconds:20',
                                         optional.events = c('OrganicSearch','Direct','Referral'),
                                         data.order.column = 'time_stamp'
                                         )
                                         
  # Example 3 - # This example uses Dynamic Weighted Distribution Models Input.
  attribution_out3 <- td_attribution_mle(data = attribution_sample_table,
                                         data.partition.column = 'user_id',
                                         conversion.events = c('SocialNetwork','PaidSearch'),
                                         timestamp.column = 'time_stamp',
                                         model1.name = c('EVENT_REGULAR',
                                          'email:0.19:LAST_CLICK:NA','impression:0.81:WEIGHTED:0.4,0.3,0.2,0.1'),
                                         model2.name = c('EVENT_OPTIONAL', 'ALL:1:WEIGHTED:0.4,0.3,0.2,0.1'),
                                         event.column = 'event',
                                         window.size = 'rows:10&seconds:20',
                                         optional.events = c('OrganicSearch','Direct','Referral'),
                                         data.order.column = 'time_stamp'
                                         )
                                         
  # Example 4 - This example uses Window Models.
  attribution_out4 <- td_attribution_mle(data = attribution_sample_table,
                                         data.partition.column = 'user_id',      
                                         conversion.events = c('SocialNetwork','PaidSearch'),
                                         timestamp.column = 'time_stamp',
                                         model1.name = c('SEGMENT_ROWS','3:0.5:EXPONENTIAL:0.5,ROW','4:0.3:WEIGHTED:0.4,0.3,0.2,0.1','3:0.2:FIRST_CLICK:NA'),
                                         model2.name = c('SEGMENT_SECONDS', '6:0.5:UNIFORM:NA',
                                          '8:0.3:LAST_CLICK:NA','6:0.2:FIRST_CLICK:NA'),
                                         event.column = 'event',
                                         window.size = 'rows:10&seconds:20',
                                         optional.events = c('OrganicSearch','Direct','Referral'),
                                         exclude.events  = 'Email',
                                         data.order.column = 'time_stamp'
                                         )
                                         
  # Example 5 - This example uses Single-Window Model.
  attribution_out5 <- td_attribution_mle(data = attribution_sample_table,
                                         data.partition.column = 'user_id',    
                                         conversion.events = c('SocialNetwork','PaidSearch'),
                                         timestamp.column = 'time_stamp',
                                         model1.name = c('SIMPLE', 'UNIFORM:NA'),
                                         event.column = 'event',
                                         window.size = 'rows:10&seconds:20',
                                         exclude.events  = 'Email',
                                         data.order.column = 'time_stamp'
                                         )
                                         
  # Example 6 - This example uses Unused Segment Windows.
  attribution_out6 <- td_attribution_mle(data = attribution_sample_table,
                                         data.partition.column = 'user_id',  
                                         conversion.events = c('SocialNetwork','PaidSearch'),
                                         timestamp.column = 'time_stamp',
                                         model1.name = c('SEGMENT_ROWS','3:0.5:EXPONENTIAL:0.5,ROW','4:0.3:WEIGHTED:0.4,0.3,0.2,0.1','3:0.2:FIRST_CLICK:NA'),
                                          model2.name = c('SEGMENT_SECONDS','6:0.5:UNIFORM:NA','8:0.3:LAST_CLICK:NA', '6:0.2:FIRST_CLICK:NA'),
                                         event.column = 'event',
                                         window.size = 'rows:10&seconds:20',
                                         exclude.events  = 'Email',
                                         data.order.column = 'time_stamp'
                                         )

  # Example 7 - This example uses Multiple Inputs which takes data 
  # and parameters from multiple tables and outputs attributions.
  attribution_out7 <- td_attribution_mle(data = attribution_sample_table1,
                               data.partition.column = 'user_id',
                               data.optional = attribution_sample_table2,
                               data.optional.partition.column = 'user_id',
                               data.order.column = 'time_stamp',
                               conversion.data = conversion_event_table,
                               excluding.data = excluding_event_table,
                               optional.data = optional_event_table,
                               model1.type = model1_table,
                               model2.type = model2_table,
                               event.column = 'event',
                               timestamp.column = 'time_stamp',
                               window.size = 'rows:10&seconds:20'
                               )