Teradata R Package Function Reference | 17.00 - 17.00 - GLMPredict - 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 GLMPredict function uses the model output by the function GLM to perform generalized linear model prediction on new input data.
Note: This function is only available when tdplyr is connected to Vantage 1.1 or later versions.

Usage

  td_glm_predict_mle (
      modeldata = NULL,
      newdata = NULL,
      terms = NULL,
      family = NULL,
      linkfunction = "CANONICAL",
      output.response.probdist = FALSE,
      output.responses = NULL,
      newdata.sequence.column = NULL,
      modeldata.sequence.column = NULL,
      newdata.order.column = NULL,
      modeldata.order.column = NULL
  )

Arguments

modeldata

Required Argument.
Specifies the model tbl_teradata generated by td_glm_mle.
This argument can accept either a tbl_teradata or an object of "td_glm_mle" class.

modeldata.order.column

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

newdata

Required Argument.
Specifies the tbl_teradata containing the input data.

newdata.order.column

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

terms

Optional Argument.
Specifies the names of input tbl_teradata columns to copy to the output tbl_teradata.
Types: character OR vector of Strings (character)

family

Optional Argument.
Specifies the distribution exponential family. The default value is read from model. If you specify this argument, you must give it the same value that you used for the "family" argument of the function when you generated the model.
Permitted Values: LOGISTIC, BINOMIAL, POISSON, GAUSSIAN, GAMMA, INVERSE_GAUSSIAN, NEGATIVE_BINOMIAL
Types: character

linkfunction

Optional Argument.
Specifies the canonical link functions (default link functions) and the link functions that are allowed for each exponential family.
Note: Use the same value that you used for the "linkfunction"" argument of the function when you generated the model.
Default Value: "CANONICAL"
Permitted Values: CANONICAL, IDENTITY, INVERSE, LOG, COMPLEMENTARY_LOG_LOG, SQUARE_ROOT, INVERSE_MU_SQUARED, LOGIT, PROBIT, CAUCHIT
Types: character

output.response.probdist

Optional Argument.
Specifies whether to output probabilities.
Note: "output.response.probdist" argument support is only available when tdplyr is connected to Vantage 1.1.1 or later versions.
Default Value: FALSE
Types: logical

output.responses

Optional Argument.
Specifies responses to output probability.
This argument can only be used when output.response.probdist is set to TRUE.
Note: "output.responses" argument support is only available when tdplyr is connected to Vantage 1.1.1 or later versions.
Permitted Values: 0, 1
Types: character OR vector of characters

newdata.sequence.column

Optional Argument.
Specifies the vector of column(s) that uniquely identifies each row of the input argument "newdata". 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)

modeldata.sequence.column

Optional Argument.
Specifies the vector of column(s) that uniquely identifies each row of the input argument "modeldata". 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_glm_predict_mle" which is a named list containing object of class "tbl_teradata".
Named list member can be referenced directly with the "$" operator using name: result.

Examples

    # Get the current context/connection
    con <- td_get_context()$connection
    
    # Load example data.
    loadExampleData("glm_example", "admissions_train", "housing_train")
    loadExampleData("glmpredict_example", "admissions_test", "housing_test")

    # Create object(s) of class "tbl_teradata".
    admissions_test <- tbl(con, "admissions_test")
    admissions_train <- tbl(con, "admissions_train")
    housing_test <- tbl(con, "housing_test")
    housing_train <- tbl(con, "housing_train")

    # Example 1 -
    # Generate a model based on train data "admissions_train".
    td_glm_out <- td_glm_mle(formula = (admitted ~ stats + masters + gpa + programming),
                             family = "LOGISTIC",
                             linkfunction = "LOGIT",
                             data = admissions_train,
                             weights = "1",
                             threshold = 0.01,
                             maxit = 25,
                             step = FALSE,
                             intercept = TRUE
                             )

    # Use the generated model to predict the 'admissions' on the test data
    # "admissions_test" by using model generated by GLM.
    td_glm_predict_out1 <- td_glm_predict_mle(modeldata = td_glm_out,
                                  newdata = admissions_test,
                                  terms = c("id","masters","gpa","stats","programming","admitted"),
                                  family = "LOGISTIC",
                                  linkfunction = "LOGIT",
                                  output.response.probdist = TRUE
                                  )

    # Example 2 -
    # Generate a model based on train data "housing_train".
    td_glm_out_hs <- td_glm_mle(formula = (price  ~ recroom  + lotsize  + stories  + garagepl +
                                           gashw + bedrooms  + driveway  + airco  + homestyle +
                                           bathrms  + fullbase + prefarea),
                                family = "GAUSSIAN",
                                linkfunction = "IDENTITY",
                                data = housing_train,
                                weights = "1",
                                threshold = 0.01,
                                maxit = 25,
                                step = FALSE,
                                intercept = TRUE
                                )

    # Use the generated model to predict the 'price' on the test data
    # "housing_test" by using model generated by GLM.
    td_glm_predict_out2 <- td_glm_predict_mle(modeldata = td_glm_out_hs$coefficients,
                                              newdata = housing_test,
                                              terms = c("sn", "price"),
                                              family = "GAUSSIAN",
                                              linkfunction = "CANONICAL"
                                             )