Statistics and time-series analytics API
Gneralized Linear Model (GLM)

Gneralized Linear Model (GLM) More...

Enumerations

enum  GLM_LINK_FUNC {
  GLM_LVK_IDENTITY =1 , GLM_LVK_LOG =2 , GLM_LVK_LOGIT =3 , GLM_LVK_PROBIT =4 ,
  GLM_LVK_CLOGLOG =5
}
 

Functions

int __stdcall NDK_GLM_VALIDATE (double *betas, size_t nBetas, double phi, WORD Lvk)
 Examines the model's parameters for constraints (e.g., positive variance, etc.)
 
int __stdcall NDK_GLM_GOF (double *Y, size_t nSize, double **X, size_t nVars, double *betas, size_t nBetas, double phi, WORD Lvk, WORD retType, double *retVal)
 Calculates a measure for the goodness of fit (e.g., LLF, AIC, BIC, SBIC).
 
int __stdcall NDK_GLM_RESID (double *Y, size_t nSize, double **X, size_t nVars, double *betas, size_t nBetas, double phi, WORD Lvk, WORD retType)
 Returns the standardized residuals/errors of a given GLM.
 
int __stdcall NDK_GLM_PARAM (double *Y, size_t nSize, double **X, size_t nVars, double *betas, size_t nBetas, double *phi, WORD Lvk, WORD retType, size_t maxIter)
 Returns an array of cells for the initial (non-optimal), optimal or standard errors of the model's parameters

 
int __stdcall NDK_GLM_FORE (double *X, size_t nVars, double *betas, size_t nBetas, double phi, WORD Lvk, WORD retType, double alpha, double *retval)
 Returns an array of cells for the initial (non-optimal), optimal or standard errors of the model's parameters

 
int __stdcall NDK_GLM_FITTED (double *Y, size_t nSize, double **X, size_t nVars, double *betas, size_t nBetas, double phi, WORD Lvk, WORD retType)
 Returns an array of values for the fitted values of the conditional mean, volatility or residuals.
 

Detailed Description

The generalized linear model (GLM) is a flexible generalization of ordinary least squares regression. The GLM generalizes linear regression by allowing the linear model to be related to the response variable (i.e., \( Y \)) via a link function (i.e., \( g(.) \))and by allowing the magnitude of the variance of each measurement to be a function of its predicted value.

Enumeration Type Documentation

◆ GLM_LINK_FUNC

Supported Link function

See also
Enumerator
GLM_LVK_IDENTITY 

Identity (default)

GLM_LVK_LOG 

Log.

GLM_LVK_LOGIT 

Logit.

GLM_LVK_PROBIT 

Probit.

GLM_LVK_CLOGLOG 

Complementary log-log.

Function Documentation

◆ NDK_GLM_FITTED()

int __stdcall NDK_GLM_FITTED ( double * Y,
size_t nSize,
double ** X,
size_t nVars,
double * betas,
size_t nBetas,
double phi,
WORD Lvk,
WORD retType )

Returns an array of values for the fitted values of the conditional mean, volatility or residuals.

Parameters
[in,out]Y(Required) is the response or the dependent variable data array (one dimensional array).
[in]nSize(Required) is the number of observations.
[in]X(Required) is the independent variables data matrix, such that each column represents one variable.
[in]nVars(Required) is the number of independent variables (or columns in X).
[in]betas(Required) are the coefficients of the GLM model (a one dimensional array).
[in,out]nBetas(Required) is the number of the coefficients in betas. Note that nBetas must be equal to nVars+1.
[in]phi(Required) is the GLM dispersion paramter. Phi is only meaningful for Binomial (1/batch or trial size) and for Guassian (variance).
Distribution Phi
Binomial phi = Reciprocal of the batch/trial size.
Gaussion phi = variance.
Poisson phi = 1.0
[in]Lvk(Required) is the link function that describes how the mean depends on the linear predictor (see GLM_LINK_FUNC).
Value Link Function
1 Identity
2 Log
3 Logit
4 Probit
5 Complementary log-log
[in]retType(Required) is a switch to select a output type ( see FIT_RETVAL_FUNC)
Value Residuals Type
1 Fitted conditional mean
2 Fitted conditional volatility or standard deviation
3 Raw residuals (actual - fitted mean)
4 Standardized residuals - (actual - fitted mean)/fitted volatility.
Returns
status code of the function call: zero = success, positive = success with a warning, and negative = error occurred.
Return values
NDK_SUCCESSsuccess
NDK_INVALID_ARGfailed (see remarks)
NDK_LOW_LICENSE_ARG_LIMITfailed (see remarks)
NDK_FAILEDfailed
Remarks
  1. Missng values (i.e. NaN) are not allowed in the either response(Y) or the explanatory input arrays.
  2. The number of observations in response variable (Y) must be equal to number of observations of the explanatory variables (X).
  3. The residuals/innovations standard deviation (i.e. \(\sigma\)) should be greater than zero
  4. The number of betas must be equal to the number of explanatory variables (i.e. X) plus one (intercept).
  5. For GLM with Poisson distribution:
    • The values of the response variables must be non-negative integers.
    • The value of the dispersion factor (Phi) value must be either missing or equal to one. 6 For GLM with Binomial distribution,
    • The values of the response variable must be non-negative fractions between zero and one, inclusive.
    • The value of the dispersion factor (Phi) must be a positive fraction (greater than zero, and less than one).
  6. For GLM with Guassian distribution, the dispersion factor (Phi) value must be positive.
  7. In lite-license mode (e.g., expired license key), the size of the input data set is limited to a maximum of 25. If this limit is exceeded, the function will fail and return NDK_LOW_LICENSE_ARG_LIMIT.
  8. In lite-license mode (e.g., expired license key), the number of the independent variables is limited to a maximum of 5. If this limit is exceeded, the function will fail and return NDK_LOW_LICENSE_ARG_LIMIT.
Requirements
Requirement Value
Target Platform Windows
Header SFSDK.h (include Windows.h)
Library SFSDK.lib
DLL SFSDK.dll
Since
v1.68
See also

◆ NDK_GLM_FORE()

int __stdcall NDK_GLM_FORE ( double * X,
size_t nVars,
double * betas,
size_t nBetas,
double phi,
WORD Lvk,
WORD retType,
double alpha,
double * retval )

Calculates the expected response (e.g., mean, std. errors) value, given the GLM model and the values of the explanatory variables.

Parameters
[in]X(Required) is the independent variables data matrix, such that each column represents one variable.
[in]nVars(Required) is the number of independent variables (or columns in X).
[in]betas(Required) are the coefficients of the GLM model (a one dimensional array).
[in,out]nBetas(Required) is the number of the coefficients in betas. Note that nBetas must be equal to nVars+1.
[in]phi(Required) is the GLM dispersion paramter. Phi is only meaningful for Binomial (1/batch or trial size) and for Guassian (variance).
Distribution Phi
Binomial phi = Reciprocal of the batch/trial size.
Gaussion phi = variance.
Poisson phi = 1.0
[in]Lvk(Required) is the link function that describes how the mean depends on the linear predictor (see GLM_LINK_FUNC).
Value Link Function
1 Identity
2 Log
3 Logit
4 Probit
5 Complementary log-log
[in]retType(Required) is a switch to select the return output (1 = Mean Value (default), 2 = Std Error, 3 = Test Score, 4 = P-Value, 5 = Upper Value, 6 = Lower Value).
Value Return
1 Mean Value (default)
2 Standard Error.
3 Upper Limit.
4 Lower Limit.
[in]alpha(Required) is the statistical significance or confidence level (i.e. alpha). If missing or omitted, an alpha value of 5% is assumed.
[out]retval(Required) is a pointer to a variable to hold the calculated test statistics.
Returns
status code of the function call: zero = success, positive = success with a warning, and negative = error occurred.
Return values
NDK_SUCCESSsuccess
NDK_INVALID_ARGfailed (see remarks)
NDK_LOW_LICENSE_ARG_LIMITfailed (see remarks)
NDK_FAILEDfailed
Remarks
  1. Missng values (i.e. NaN) are not allowed in the either response(Y) or the explanatory input arrays.
  2. The number of observations in response variable (Y) must be equal to number of observations of the explanatory variables (X).
  3. The residuals/innovations standard deviation (i.e. \(\sigma\)) should be greater than zero
  4. The number of betas must be equal to the number of explanatory variables (i.e. X) plus one (intercept).
  5. For GLM with Poisson distribution:
    • The values of the response variables must be non-negative integers.
    • The value of the dispersion factor (Phi) value must be either missing or equal to one. 6 For GLM with Binomial distribution,
    • The values of the response variable must be non-negative fractions between zero and one, inclusive.
    • The value of the dispersion factor (Phi) must be a positive fraction (greater than zero, and less than one).
  6. For GLM with Guassian distribution, the dispersion factor (Phi) value must be positive.
  7. In lite-license mode (e.g., expired license key), the size of the input data set is limited to a maximum of 25. If this limit is exceeded, the function will fail and return NDK_LOW_LICENSE_ARG_LIMIT.
  8. In lite-license mode (e.g., expired license key), the number of the independent variables is limited to a maximum of 5. If this limit is exceeded, the function will fail and return NDK_LOW_LICENSE_ARG_LIMIT.
Requirements
Requirement Value
Target Platform Windows
Header SFSDK.h (include Windows.h)
Library SFSDK.lib
DLL SFSDK.dll
Since
v1.68
See also

◆ NDK_GLM_GOF()

int __stdcall NDK_GLM_GOF ( double * Y,
size_t nSize,
double ** X,
size_t nVars,
double * betas,
size_t nBetas,
double phi,
WORD Lvk,
WORD retType,
double * retVal )

Calculates a measure for the goodness of fit (e.g., LLF, AIC, BIC, SBIC).

Parameters
[in]Y(Required) is the response or the dependent variable data array (one dimensional array).
[in]nSize(Required) is the number of observations.
[in]X(Required) is the independent variables data matrix, such that each column represents one variable.
[in]nVars(Required) is the number of independent variables (or columns in X).
[in]betas(Required) are the coefficients of the GLM model (a one dimensional array).
[in]nBetas(Required) is the number of the coefficients in betas. Note that nBetas must be equal to nVars+1.
[in]phi(Required) is the GLM dispersion paramter. Phi is only meaningful for Binomial (1/batch or trial size) and for Guassian (variance).
Distribution Phi
Binomial phi = Reciprocal of the batch/trial size.
Gaussion phi = variance.
Poisson phi = 1.0
[in]Lvk(Required) is the link function that describes how the mean depends on the linear predictor (see GLM_LINK_FUNC).
Value Link Function
1 Identity
2 Log
3 Logit
4 Probit
5 Complementary log-log
[in]retType(Required) a switch to select a fitness measure ( see GOODNESS_OF_FIT_FUNC).
Value Return
1 Log-likelihood goodness of fit measure (LLF)
2 Akaike information criterion goodness of fit measure (AIC)
3 Bayesian or Schwartz information criterion goodness of fit measure (BIC)
4 Hannan-Quinn information criterion goodness of fit measure. (HQC)
5 R-squared goodness of fit measure (R^2)
6 Adjusted R-squared goodness of fit measure (Adj. R^2)
[out]retVal(Required) is a pointer to a variable to hold the calculated test statistics.
Returns
status code of the function call: zero = success, positive = success with a warning, and negative = error occurred.
Return values
NDK_SUCCESSsuccess
NDK_INVALID_ARGfailed (see remarks)
NDK_LOW_LICENSE_ARG_LIMITfailed (see remarks)
NDK_FAILEDfailed
Remarks
  1. Missng values (i.e. NaN) are not allowed in the either response(Y) or the explanatory input arrays.
  2. The number of rows in response variable (Y) must be equal to number of rows of the explanatory variables (X).
  3. The residuals/innovations standard deviation (i.e. \(\sigma\)) should be greater than zero
  4. The number of betas must be equal to the number of explanatory variables (i.e. X) plus one (intercept).
  5. For GLM with Poisson distribution:
    • The values of the response variables must be non-negative integers.
    • The value of the dispersion factor (Phi) value must be either missing or equal to one. 6 For GLM with Binomial distribution,
    • The values of the response variable must be non-negative fractions between zero and one, inclusive.
    • The value of the dispersion factor (Phi) must be a positive fraction (greater than zero, and less than one).
  6. For GLM with Guassian distribution, the dispersion factor (Phi) value must be positive.
  7. In lite-license mode (e.g., expired license key), the size of the input data set is limited to a maximum of 25. If this limit is exceeded, the function will fail and return NDK_LOW_LICENSE_ARG_LIMIT.
  8. In lite-license mode (e.g., expired license key), the number of the independent variables is limited to a maximum of 5. If this limit is exceeded, the function will fail and return NDK_LOW_LICENSE_ARG_LIMIT.
Requirements
Requirement Value
Target Platform Windows
Header SFSDK.h (include Windows.h)
Library SFSDK.lib
DLL SFSDK.dll
Since
v1.68
See also

◆ NDK_GLM_PARAM()

int __stdcall NDK_GLM_PARAM ( double * Y,
size_t nSize,
double ** X,
size_t nVars,
double * betas,
size_t nBetas,
double * phi,
WORD Lvk,
WORD retType,
size_t maxIter )

Returns an array of cells for the initial (non-optimal), optimal or standard errors of the model's parameters

Parameters
[in,out]Y(Required) is the response or the dependent variable data array (one dimensional array).
[in]nSize(Required) is the number of observations.
[in]X(Required) is the independent variables data matrix, such that each column represents one variable.
[in]nVars(Required) is the number of independent variables (or columns in X).
[in]betas(Required) are the coefficients of the GLM model (a one dimensional array).
[in,out]nBetas(Required) is the number of the coefficients in betas. Note that nBetas must be equal to nVars+1.
[in]phi(Required) is the GLM dispersion paramter. Phi is only meaningful for Binomial (1/batch or trial size) and for Guassian (variance).
Distribution Phi
Binomial phi = Reciprocal of the batch/trial size.
Gaussion phi = variance.
Poisson phi = 1.0
[in]Lvk(Required) is the link function that describes how the mean depends on the linear predictor (see GLM_LINK_FUNC).
Value Link Function
1 Identity
2 Log
3 Logit
4 Probit
5 Complementary log-log
[in]retType(Required) is a switch to select the type of value returned: 1= Quick Guess, 2=Calibrated, 3= Std. Errors ( see MODEL_RETVAL_FUNC).
Value Type
1 Quick guess (non-optimal) of parameters values
2 Run a calibration process to find optimal values for the model's parameters
3 Compute the standard error of the parameters' values
[in]maxIter(Required) is the maximum number of iterations used to calibrate the model. If none (i.e., 0), the default maximum of 100 is assumed.
Returns
status code of the function call: zero = success, positive = success with a warning, and negative = error occurred.
Return values
NDK_SUCCESSsuccess
NDK_INVALID_ARGfailed (see remarks)
NDK_LOW_LICENSE_ARG_LIMITfailed (see remarks)
NDK_FAILEDfailed
Remarks
  1. Missng values (i.e. NaN) are not allowed in the either response(Y) or the explanatory input arrays.
  2. The number of observations in response variable (Y) must be equal to number of observations of the explanatory variables (X).
  3. The residuals/innovations standard deviation (i.e. \(\sigma\)) should be greater than zero
  4. The number of betas must be equal to the number of explanatory variables (i.e. X) plus one (intercept).
  5. For GLM with Poisson distribution:
    • The values of the response variables must be non-negative integers.
    • The value of the dispersion factor (Phi) value must be either missing or equal to one. 6 For GLM with Binomial distribution,
    • The values of the response variable must be non-negative fractions between zero and one, inclusive.
    • The value of the dispersion factor (Phi) must be a positive fraction (greater than zero, and less than one).
  6. For GLM with Guassian distribution, the dispersion factor (Phi) value must be positive.
  7. In lite-license mode (e.g., expired license key), the size of the input data set is limited to a maximum of 25. If this limit is exceeded, the function will fail and return NDK_LOW_LICENSE_ARG_LIMIT.
  8. In lite-license mode (e.g., expired license key), the number of the independent variables is limited to a maximum of 5. If this limit is exceeded, the function will fail and return NDK_LOW_LICENSE_ARG_LIMIT.
Requirements
Requirement Value
Target Platform Windows
Header SFSDK.h (include Windows.h)
Library SFSDK.lib
DLL SFSDK.dll
Since
v1.68
See also

◆ NDK_GLM_RESID()

int __stdcall NDK_GLM_RESID ( double * Y,
size_t nSize,
double ** X,
size_t nVars,
double * betas,
size_t nBetas,
double phi,
WORD Lvk,
WORD retType )

Returns the standardized residuals/errors of a given GLM.

Parameters
[in,out]Y(Required) is the response or the dependent variable data array (one dimensional array).
[in]nSize(Required) is the number of observations.
[in]X(Required) is the independent variables data matrix, such that each column represents one variable.
[in]nVars(Required) is the number of independent variables (or columns in X).
[in]betas(Required) are the coefficients of the GLM model (a one dimensional array).
[in]nBetas(Required) is the number of the coefficients in betas. Note that nBetas must be equal to nVars+1.
[in]phi(Required) is the GLM dispersion paramter. Phi is only meaningful for Binomial (1/batch or trial size) and for Guassian (variance).
Distribution Phi
Binomial phi = Reciprocal of the batch/trial size.
Gaussion phi = variance.
Poisson phi = 1.0
[in]Lvk(Required) is the link function that describes how the mean depends on the linear predictor (see GLM_LINK_FUNC).
Value Link Function
1 Identity
2 Log
3 Logit
4 Probit
5 Complementary log-log
[in]retType(Required) is a switch to select a residuals-type:raw or standardized. see RESID_RETVAL_FUNC.
Value Residuals Type
0 Standardized residuals
1 Raw Residuals
Returns
status code of the function call: zero = success, positive = success with a warning, and negative = error occurred.
Return values
NDK_SUCCESSsuccess
NDK_INVALID_ARGfailed (see remarks)
NDK_LOW_LICENSE_ARG_LIMITfailed (see remarks)
NDK_FAILEDfailed
Remarks
  1. Missng values (i.e. NaN) are not allowed in the either response(Y) or the explanatory input arrays.
  2. The number of rows in response variable (Y) must be equal to number of rows of the explanatory variables (X).
  3. The residuals/innovations standard deviation (i.e. \(\sigma\)) should be greater than zero
  4. The number of betas must be equal to the number of explanatory variables (i.e. X) plus one (intercept).
  5. For GLM with Poisson distribution:
    • The values of the response variables must be non-negative integers.
    • The value of the dispersion factor (Phi) value must be either missing or equal to one. 6 For GLM with Binomial distribution,
    • The values of the response variable must be non-negative fractions between zero and one, inclusive.
    • The value of the dispersion factor (Phi) must be a positive fraction (greater than zero, and less than one).
  6. For GLM with Guassian distribution, the dispersion factor (Phi) value must be positive.
  7. In lite-license mode (e.g., expired license key), the size of the input data set is limited to a maximum of 25. If this limit is exceeded, the function will fail and return NDK_LOW_LICENSE_ARG_LIMIT.
  8. In lite-license mode (e.g., expired license key), the number of the independent variables is limited to a maximum of 5. If this limit is exceeded, the function will fail and return NDK_LOW_LICENSE_ARG_LIMIT.
Requirements
Requirement Value
Target Platform Windows
Header SFSDK.h (include Windows.h)
Library SFSDK.lib
DLL SFSDK.dll
Since
v1.68
See also

◆ NDK_GLM_VALIDATE()

int __stdcall NDK_GLM_VALIDATE ( double * betas,
size_t nBetas,
double phi,
WORD Lvk )

Examines the model's parameters for constraints (e.g., positive variance, etc.)

Parameters
[in]betas(Required) are the coefficients of the GLM model (a one dimensional array)
[in]nBetas(Required) is the number of the coefficients in betas. Note that nBetas must be equal to nVars+1
[in]phi(Required) is the GLM dispersion paramter. Phi is only meaningful for Binomial (1/batch or trial size) and for Guassian (variance).
Distribution Phi
Binomial phi = Reciprocal of the batch/trial size.
Gaussion phi = variance.
Poisson phi = 1.0
[in]Lvk(Required) is the link function that describes how the mean depends on the linear predictor (see GLM_LINK_FUNC).
Value Link Function
1 Identity
2 Log
3 Logit
4 Probit
5 Complementary log-log
Returns
status code of the function call: zero = success, positive = success with a warning, and negative = error occurred.
Return values
NDK_TRUEGLM model is valid
NDK_FALSEGLM model in invalid.
NDK_INVALID_ARGfailed (see remarks)
NDK_FAILEDfailed
Remarks
  1. The number of betas must be equal to the number of explanatory variables (i.e. X) plus one (intercept).
    • For GLM with Poisson distribution:
      • The values of the response variables must be non-negative integers.
      • The value of the dispersion factor (Phi) value must be either missing or equal to one.
    • For GLM with Binomial distribution,
      • The values of the response variable must be non-negative fractions between zero and one, inclusive.
      • The value of the dispersion factor (Phi) must be a positive fraction (greater than zero, and less than one).
  2. For GLM with Guassian distribution, the dispersion factor (Phi) value must be positive.
Requirements
Requirement Value
Target Platform Windows
Header SFSDK.h (include Windows.h)
Library SFSDK.lib
DLL SFSDK.dll
Since
v1.68
See also