Teradata Package for R Function Reference | 17.20 - GLMPredict - Teradata Package for R - Look here for syntax, methods and examples for the functions included in the Teradata Package for R.

Teradata® Package for R Function Reference

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Teradata Package for R
Release Number
17.20
Published
March 2024
ft:locale
en-US
ft:lastEdition
2024-05-03
dita:id
TeradataR_FxRef_Enterprise_1720
Product Category
Teradata Vantage

GLMPredict

Description

The td_glm_predict_mle_sqle() function uses the model generated by the function td_glm_mle() to perform generalized linear model prediction on new input data.

Usage

  td_glm_predict_mle_sqle (
      modeldata = NULL,
      newdata = NULL,
      terms = NULL,
      family = NULL,
      linkfunction = "CANONICAL",
      output.prob = FALSE,
      output.responses = NULL,
      ...
  )

Arguments

modeldata

Required Argument.
Specifies the tbl_teradata containing the model data
generated by td_glm_mle() function or an instance of td_glm_mle.
Types: tbl_teradata or td_glm_mle

newdata

Required Argument.
Specifies the tbl_teradata containing the input data.
Types: tbl_teradata

terms

Optional Argument.
Specifies the names of newdata 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 modeldata. 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.
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 Link 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.prob

Optional Argument.
Specifies whether to output probabilities.
Default Value: FALSE
Types: logical

output.responses

Optional Argument.
Specifies responses for which to output probabilities.
Types: character OR vector of Strings (character)

...

Specifies the generic keyword arguments SQLE functions accept.
Below are the generic keyword arguments:

persist:
Optional Argument.
Specifies whether to persist the results of the function in a table or not.
When set to TRUE, results are persisted in a table; otherwise, results are garbage collected at the end of the session.
Default Value: FALSE
Types: logical

volatile:
Optional Argument.
Specifies whether to put the results of the function in a volatile table or not.
When set to TRUE, results are stored in a volatile table, otherwise not.
Default Value: FALSE
Types: logical

Function allows the user to partition, hash, order or local order the input data. These generic arguments are available for each argument that accepts tbl_teradata as input and can be accessed as:

  • "<input.data.arg.name>.partition.column" accepts character OR vector of Strings (character) (Strings)

  • "<input.data.arg.name>.hash.column" accepts character OR vector of Strings (character) (Strings)

  • "<input.data.arg.name>.order.column" accepts character OR vector of Strings (character) (Strings)

  • "local.order.<input.data.arg.name>" accepts logical

Note:
These generic arguments are supported by tdplyr if the underlying SQL Engine function supports, else an exception is raised.

Value

Function returns an object of class "td_glm_predict_mle_sqle" which is a named list containing object of class "tbl_teradata".
Named list member(s) can be referenced directly with the "$" operator using the name(s):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 -
    # First train the data, i.e., create a GLM Model
    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
                            )

    # Run predict on the output of td_glm_mle() function.
    td_glm_predict_out1 <- td_glm_predict_mle_sqle(
                            modeldata = td_glm_out,
                            newdata = admissions_test,
                            terms = c("id","masters","gpa","stats","programming","admitted"),
                            family = "LOGISTIC",
                            linkfunction = "LOGIT"
                            )

    # Example 2 -
    # First train the data, i.e., create a GLM Model
    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
                               )

    # Run predict on the output of td_glm_mle() function by passing coefficients.
    td_glm_predict_out2 <- td_glm_predict_mle_sqle(
                            modeldata = td_glm_out_hs$coefficients,
                            newdata = housing_test,
                            terms = c("sn", "price"),
                            family = "GAUSSIAN",
                            linkfunction = "CANONICAL"
                            )