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

Teradata® R Package Function Reference

Product
Teradata R Package
Release Number
16.20
Published
February 2020
Language
English (United States)
Last Update
2020-02-28
dita:id
B700-4007
lifecycle
previous
Product Category
Teradata Vantage

Description

The generalized linear model (GLM) is an extension of the linear regression model that enables the linear equation to be related to the dependent variables by a link function. GLM performs linear regression analysis for distribution functions using a user-specified distribution family and link function. GLM selects the link function based upon the distribution family and the assumed nonlinear distribution of expected outcomes. The table in background describes the supported link function combinations.

Usage

  td_glm_mle (
      formula = NULL,
      family = "gaussian",
      linkfunction = "CANONICAL",
      data = NULL,
      weights = "1.0",
      threshold = 0.01,
      maxit = 25,
      step = FALSE,
      intercept = TRUE,
      data.sequence.column = NULL
  )

Arguments

formula

Required Argument.
An object of class "formula". Specifies the model to be fitted. Only basic formula of the (col1 ~ col2 + col3 +...) form are supported and all variables must be from the same Teradata tbl object. The response should be column of type real, numeric, integer or boolean.

family

Optional Argument.
Specifies the distribution exponential family Default Value: "gaussian"
Permitted Values: LOGISTIC, BINOMIAL, POISSON, GAUSSIAN, GAMMA, INVERSE_GAUSSIAN, NEGATIVE_BINOMIAL

linkfunction

Optional Argument.
The canonical link functions (default link functions) and the link functions that are allowed.
Default Value: "CANONICAL"
Permitted Values: CANONICAL, IDENTITY, INVERSE, LOG, COMPLEMENTARY_LOG_LOG, SQUARE_ROOT, INVERSE_MU_SQUARED, LOGIT, PROBIT, CAUCHIT

data

Required Argument.
Specifies the name of the table that contains the columns

weights

Optional Argument.
Specifies the name of an input table column that contains the weights to assign to responses. The default value is 1.You can use non-NULL weights to indicate that different observations have different dispersions (with the weights being inversely proportional to the dispersions). Equivalently, when the weights are positive integers wi, each response yi is the mean of wi unit-weight observations. A binomial GLM uses prior weights to give the number of trials when the response is the proportion of successes. A Poisson GLM rarely uses weights. If the weight is less than the response value, then the function throws an exception. Therefore, if the response value is greater than 1, then you must specify a weight that is greater than or equal to the response value.
Default Value: "1.0"

threshold

Optional Argument.
Specifies the convergence threshold.
Default Value: 0.01

maxit

Optional Argument.
Specifies the maximum number of iterations that the algorithm runs before quitting, if the convergence threshold is not met.
Default Value: 25

step

Optional Argument.
Specifies whether the function uses a step. If the function uses a step, then it runs with the GLM model that has the lowest Akaike information criterion (AIC) score, drops one predictor from the current predictor group, and repeats this process until no predictor remains.
Default Value: FALSE

intercept

Optional Argument.
Specifies whether the function uses an intercept. For example, in ?0+?1*X1+?2*X2+ ....+?pXp, the intercept is ?0.
Default Value: TRUE

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.

Value

Function returns an object of class "td_glm_mle" which is a named list containing Teradata tbl objects.
Named list members can be referenced directly with the "$" operator using following names:

  1. coefficients

  2. output

Examples

    # Get the current context/connection
    con <- td_get_context()$connection
    
    # Load example data.
    loadExampleData("glm_example", "admissions_train", "housing_train")
    
    # Create remote tibble objects.
    admissions_train <- tbl(con, "admissions_train")
    housing_train <- tbl(con, "housing_train")
    
    # Example 1 -
    td_glm_out1 <- 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
                     )
    
    # Example 2 -
    td_glm_out2 <- td_glm_mle(formula = (admitted ~ stats + masters + gpa + programming),
                     family = "LOGISTIC",
                     linkfunction = "LOGIT",
                     data = admissions_train,
                     weights = "1",
                     threshold = 0.01,
                     maxit = 25,
                     step = TRUE,
                     intercept = TRUE
                     )
    
    # Example 3 -
    td_glm_out3 <- 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
                     )