Updated March 31, 2023
Introduction to Statsmodels API
statsmodels API are the models that are called by using Application Programming Interface also called as APIs. There are various categories into which the statsmodel APIs can be classified that we will have a look at in this session. Along with that, we will also get a general overview of statsmodels API, regression, linear models, count models, TSA.API, formula.API and tome series models.
Overview of Statsmodels API
The most crucial statsmodels API are categorized into the following models –
- Statsmodels.TSA.API – This involves the methods and models that are related to the time series and can be imported canonically by using the statement “import statsmodel.TSA.API as educba_tsa”.
- Statsmodels.API – These are the methods and models involving the cross-sectional details and can be imported in our program canonically by simply adding the package using “import statsmodels.API as educba_sm”.
- Statsmodels.formula.API – This is the interface that conveniently provides us the facility to specify different models by using the data frames and the formula strings. The API that is most supported by the formula API is directly exposed by a method named from_formula method of class which can be imported in our program canonically by using the statement “import statsmodel.formula.API as educba_smf”.
The use of the API is mainly focused on various models and along with that, they are used for implementing the statistical tools and the tests. The structure and the paths of import help us to understand and define the design of the two API models. Along with that they also help us to understand the difference between importing the functionalities from the API if statsmodels and direct import the functionality from the module where its definition resides.
Statsmodels API Regression
Let us have a look at some of the functionalities of the statsmodel api regression. The below table explains us the names and the arguments related to the methods available for regression and also the definition or long form of the same which is quite self-explanatory.
Method |
Long Form |
RecursiveLS (endog, exog [, conditions or constraints]) | RecursiveLS stands for Recursive Least Square |
RollingOLS ( endog, exog[, min_nobs, windows, …]) | RollingOLS means that Rolling Ordinary Least |
GLS (endog, [exog. Hasconst, missing, rho]) | This method helps in calculating generalized least square. |
RollingWLS (endog, exog[, weights, window, …]) | This functionality is responsible for articulating the value of rolling weighted least square. |
GLSAR (endog, exog[, rho, has constant]) | The method will help us to find out the generalized least squares along with the consideration of the covariance structure. |
WLS (endog, exog[,has constant, missing, weights]) | This has the long form of weighted Least Squares. |
OLS (endog, [,exog, missing, has constant]) | This is the most basic functionality that calculates the ordinary least square value. |
Statsmodels API Linear Models
The linear models also involve various methods provided to inculcate linear model functionality ins statistical analysis and testing. The basic functionalities and their description are summarized in the below table –
Functionality | Description |
BinomialBayesMixedGLM (endog, exog, exog_vc, …) | This functionality enables the user to calculate the generalized Linear Mixed Model along with the estimation based on Bayesian’s structure. |
GLM (endog, exog[, family, exposure, offset,…]) | This helps in constructing the models that are of generalized Linear structure. |
PoissonBayesMixedGLM(endog, exog_vc, exog, ident) | This functionality enables the user to calculate the generalized Linear Mixed Model along with the estimation based on Bayesian’s structure. |
GLMGam (endog, [exog, alpha, smoother, …]) | This is used for the calculation of GAM that stands for Generalized Additive Models. |
Statsmodels API Count Models
The Count models involve various methods provided to count and discrete model functionality ins statistical analysis and testing. The basic functionalities and their description are summarized in the below table –
Method |
Description |
Probit (endog, exog[,rank checking]) | This method is used to implement the probit model and create an instance of the same. |
Logit (endog, [exog [, rant checking]]) | This method is used to implement the logit model and create an instance of the same. |
Poisson (endog, [exog [, offset, exposure]]) | This method is used to implement the Poisson model and create an instance of the same. |
MNLogit (endog, [exog [, offset, exposure]]) | This method is used to implement the Multinomial Logit model and create an instance of the same. |
NegativeBinomial (endog, [exog, …]) | This method is used to implement the Negative Binomial and create an instance of the same. |
GeneralizedPoisson (endog, [exog [, p, offset, exposure, …]]) | This method is used to implement the generalized Poisson model and creating an instance of the same. |
ZeroInflatedPoisson (endog, [exog ,…]]) | This method is used to implement the poisson zero inflated model and creating an instance of the same. |
NegativeBinomialP (endog, [exog, p, offset, …]) | This method is used to implement the generalized Negative Binomial model and creating an instance of the same. |
ZeroInflatedNegativeBinomialP (endog, [exog ,…]]) | This method is used to implement the zero inflated generalized Negative Binomial model and creating an instance of the same. |
ZeroInflatedNegativePoisson (endog, [exog ,…]]) | This method is used to implement the zero inflated generalized Negative Poisson model and creating an instance of the same. |
OrderedModel( endog, exog [distribution, offset]) | Normal distribution and logistic kind of functionality that is used for creating an ordered model. |
Statsmodels api tsa.api
tsa.api is the package that involves the model consisting of time series related manipulations. Below is the list of some of the tsa.api package methods used in statsmodels –
Method | Description |
Ccf(x,y[,adjusted,fft]) | This method enables us to perform cross sectional manipulations. |
Acf(x, [nlags, alpha, adjusted, fft, qstat….]) | This method enables us to perform automatic correlation manipulations. |
Bds (x, epsilon, distance, max dimensions) | In order to achieve independence between the time series, we can make use of BDS test statistics. |
Pacf(x, [nlags, alpha, method]) | It helps in calculating the estimation of autocorrelation that is partial in nature. |
Statsmodels api Time-Series Tools
Some of the methods related to the time series tools are as listed below –
Function | Description |
Detrend (x, [axis, order]) | Considering the 0 to 1 axis the derend of the array provided with the proposed order of an array can be done. |
Add_lag (x, [lags, insert, column, drop]) | The output of this function is an array involving the lags included in it as mentioned. |
DeterministicProcess (index, * [, period]) | This helps in creation of a class of containers for deterministic terms. |
Statsmodels api formula.API
It has a wide range of methods and functions provided for it. Some of them are listed below –
Method | Description |
Ols (formula, data, [drop_cols, subset]) | Using the supplied data frames and formulas create one model. |
Glmgam (formula, data, [drop columns, subset]) | Using the supplied data frames and formulas create one model. |
Phreg (formula, data [, entry, status, …]) | Using the supplied data frames and formulas create one regression model for proportional hazards. |
Conclusion
The statsmodels API involves various categories of models and help us execute various functionalities related to each of the domain of the model.
Recommended Articles
This is a guide to Statsmodels API. Here we discuss the Introduction, overviews, regression, linear models, count models, Time-Series Tools respectively. You may also have a look at the following articles to learn more –