Skip to content

Commit

Permalink
DOC: Continue fixing docstring formatting
Browse files Browse the repository at this point in the history
Fix more docstrings
  • Loading branch information
bashtage committed Aug 2, 2019
1 parent 6357444 commit 828eb2a
Show file tree
Hide file tree
Showing 22 changed files with 194 additions and 149 deletions.
2 changes: 1 addition & 1 deletion docs/themes/statsmodels/static/nature.css_t
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ div.searchformwrapper {
.dropdown:hover .dropdown-content {display: block;}

/* Change the background color of the dropdown button when the dropdown content is shown */
.dropdown:hover .dropbtn {background-color: #ecf1fb;}
.dropdown:hover .dropbtn {background-color: #4675f3;}

span.pre {
font-family: 'Roboto Mono', monospace;
Expand Down
3 changes: 2 additions & 1 deletion statsmodels/base/elastic_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ def fit_elasticnet(model, method="coord_descent", maxiter=100,
Returns
-------
A results object.
Results
A results object.
Notes
-----
Expand Down
51 changes: 28 additions & 23 deletions statsmodels/base/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1018,8 +1018,8 @@ def predict(self, exog=None, transform=True, *args, **kwargs):
Returns
-------
prediction : ndarray, pandas.Series or pandas.DataFrame
See self.model.predict
prediction : {ndarray, Series, DataFrame}
See self.model.predict.
Notes
-----
Expand All @@ -1038,7 +1038,6 @@ def predict(self, exog=None, transform=True, *args, **kwargs):
Row indices as in pandas data frames are supported, and added to the
returned prediction.
"""
import pandas as pd

Expand Down Expand Up @@ -1263,21 +1262,19 @@ class LikelihoodModelResults(Results):

# by default we use normal distribution
# can be overwritten by instances or subclasses
use_t = False

def __init__(self, model, params, normalized_cov_params=None, scale=1.,
**kwargs):
super(LikelihoodModelResults, self).__init__(model, params)
self.normalized_cov_params = normalized_cov_params
self.scale = scale

self._use_t = False
# robust covariance
# We put cov_type in kwargs so subclasses can decide in fit whether to
# use this generic implementation
if 'use_t' in kwargs:
use_t = kwargs['use_t']
if use_t is not None:
self.use_t = use_t
self.use_t = use_t if use_t is not None else False
if 'cov_type' in kwargs:
cov_type = kwargs.get('cov_type', 'nonrobust')
cov_kwds = kwargs.get('cov_kwds', {})
Expand Down Expand Up @@ -1318,6 +1315,14 @@ def _get_robustcov_results(self, cov_type='nonrobust', use_self=True,
# TODO: we should not need use_t in get_robustcov_results
get_robustcov_results(self, cov_type=cov_type, use_self=True,
use_t=use_t, **cov_kwds)
@property
def use_t(self):
"""Flag indicating to use the Student's distribution in inference."""
return self._use_t

@use_t.setter
def use_t(self, value):
self._use_t = bool(value)

@cached_value
def llf(self):
Expand Down Expand Up @@ -1488,9 +1493,9 @@ def t_test(self, r_matrix, cov_p=None, scale=None, use_t=None):
See Also
--------
tvalues : individual t statistics
f_test : for F tests
patsy.DesignInfo.linear_constraint
tvalues : Indivudals t statistics for the estimated parameters.
f_test : Perform an F tests on model parameters.
patsy.DesignInfo.linear_constraint : Specify a linear constraint.
Examples
--------
Expand Down Expand Up @@ -1635,10 +1640,10 @@ def f_test(self, r_matrix, cov_p=None, scale=1.0, invcov=None):
See Also
--------
statsmodels.stats.contrast.ContrastResults
wald_test
t_test
patsy.DesignInfo.linear_constraint
t_test : Perform a single hypothesis test.
wald_test : Perform a Wald-test using a quadratic form.
statsmodels.stats.contrast.ContrastResults : Test results.
patsy.DesignInfo.linear_constraint : Specify a linear constraint.
Notes
-----
Expand Down Expand Up @@ -1750,10 +1755,10 @@ def wald_test(self, r_matrix, cov_p=None, scale=1.0, invcov=None,
See Also
--------
statsmodels.stats.contrast.ContrastResults
f_test
t_test
patsy.DesignInfo.linear_constraint
f_test : Perform an F tests on model parameters.
t_test : Perform a single hypothesis test.
statsmodels.stats.contrast.ContrastResults : Test results.
patsy.DesignInfo.linear_constraint : Specify a linear constraint.
Notes
-----
Expand Down Expand Up @@ -1837,7 +1842,7 @@ def wald_test(self, r_matrix, cov_p=None, scale=1.0, invcov=None,
def wald_test_terms(self, skip_single=False, extra_constraints=None,
combine_terms=None):
"""
Compute a sequence of Wald tests for terms over multiple columns
Compute a sequence of Wald tests for terms over multiple columns.
This computes joined Wald tests for the hypothesis that all
coefficients corresponding to a `term` are zero.
Expand Down Expand Up @@ -1887,7 +1892,6 @@ def wald_test_terms(self, skip_single=False, extra_constraints=None,
C(Weight):C(Duration) 0.216694 0.897315972824 2
Duration 11.187849 0.010752286833 3
Weight 30.263368 4.32586407145e-06 4
"""
# lazy import
from collections import defaultdict
Expand Down Expand Up @@ -1973,7 +1977,7 @@ def wald_test_terms(self, skip_single=False, extra_constraints=None,
def t_test_pairwise(self, term_name, method='hs', alpha=0.05,
factor_labels=None):
"""
Perform pairwise t_test with multiple testing corrected p-values
Perform pairwise t_test with multiple testing corrected p-values.
This uses the formula design_info encoding contrast matrix and should
work for all encodings of a main effect.
Expand All @@ -1986,7 +1990,7 @@ def t_test_pairwise(self, term_name, method='hs', alpha=0.05,
correspond to the main part of the exog names.
method : {str, list[str]}
The multiple testing p-value correction to apply. The default is
'hs'. See stats.multipletesting
'hs'. See stats.multipletesting.
alpha : float
The significance level for multiple testing reject decision.
factor_labels : {list[str], None}
Expand Down Expand Up @@ -2142,7 +2146,8 @@ def load(cls, fname):
return load_pickle(fname)

def remove_data(self):
"""remove data arrays, all nobs arrays from result and model
"""
Remove data arrays, all nobs arrays from result and model.
This reduces the size of the instance, so it can be pickled with less
memory. Currently tested for use with predict from an unpickled
Expand Down
15 changes: 14 additions & 1 deletion statsmodels/base/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __setstate__(self, dict_):

def save(self, fname, remove_data=False):
"""
Save a pickle of this instance
Save a pickle of this instance.
Parameters
----------
Expand All @@ -73,6 +73,19 @@ def save(self, fname, remove_data=False):

@classmethod
def load(cls, fname):
"""
Load a pickled results instance.
Parameters
----------
fname : {str, handle}
A string filename or a file handle.
Returns
-------
Results
The unpickled results instance.
"""
from statsmodels.iolib.smpickle import load_pickle
return load_pickle(fname)

Expand Down
5 changes: 4 additions & 1 deletion statsmodels/discrete/conditional_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,13 @@ def fit_regularized(self,
If True, the model is refit using only the variables that
have non-zero coefficients in the regularized fit. The
refitted model is not regularized.
**kwargs
Additional keyword argument that are used when fitting the model.
Returns
-------
An array of parameter estimates.
Results
A results instance.
"""

from statsmodels.base.elastic_net import fit_elasticnet
Expand Down
8 changes: 3 additions & 5 deletions statsmodels/discrete/count_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def __init__(self, endog, exog, exog_infl=None, offset=None,

def loglike(self, params):
"""
Loglikelihood of Generic Zero Inflated model
Loglikelihood of Generic Zero Inflated model.
Parameters
----------
Expand All @@ -118,13 +118,12 @@ def loglike(self, params):
.. math:: \\ln L=\\sum_{y_{i}=0}\\ln(w_{i}+(1-w_{i})*P_{main\\_model})+
\\sum_{y_{i}>0}(\\ln(1-w_{i})+L_{main\\_model})
where P - pdf of main model, L - loglike function of main model.
"""
return np.sum(self.loglikeobs(params))

def loglikeobs(self, params):
"""
Loglikelihood for observations of Generic Zero Inflated model
Loglikelihood for observations of Generic Zero Inflated model.
Parameters
----------
Expand All @@ -135,7 +134,7 @@ def loglikeobs(self, params):
-------
loglike : ndarray
The log likelihood for each observation of the model evaluated
at `params`. See Notes
at `params`. See Notes for definition.
Notes
--------
Expand All @@ -144,7 +143,6 @@ def loglikeobs(self, params):
where P - pdf of main model, L - loglike function of main model.
for observations :math:`i=1,...,n`
"""
params_infl = params[:self.k_inflate]
params_main = params[self.k_inflate:]
Expand Down
53 changes: 31 additions & 22 deletions statsmodels/discrete/discrete_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ def fit_regularized(self, start_params=None, method='l1',
qc_verbose=False, **kwargs):
"""
Fit the model using a regularized maximum likelihood.
The regularization method AND the solver used is determined by the
argument method.
Expand All @@ -245,29 +246,36 @@ def fit_regularized(self, start_params=None, method='l1',
Set to True to print convergence messages.
fargs : tuple
Extra arguments passed to the likelihood function, i.e.,
loglike(x,*args)
loglike(x,*args).
callback : callable callback(xk)
Called after each iteration, as callback(xk), where xk is the
current parameter vector.
retall : bool
Set to True to return list of solutions at each iteration.
Available in Results object's mle_retvals attribute.
alpha : non-negative scalar or numpy array (same size as parameters)
The weight multiplying the l1 penalty term
The weight multiplying the l1 penalty term.
trim_mode : 'auto, 'size', or 'off'
If not 'off', trim (set to zero) parameters that would have been
zero if the solver reached the theoretical minimum.
If 'auto', trim params using the Theory above.
If 'size', trim params if they have very small absolute value
If 'size', trim params if they have very small absolute value.
size_trim_tol : float or 'auto' (default = 'auto')
For use when trim_mode == 'size'
Tolerance used when trim_mode == 'size'.
auto_trim_tol : float
For sue when trim_mode == 'auto'. Use
Tolerance used when trim_mode == 'auto'.
qc_tol : float
Print warning and do not allow auto trim when (ii) (above) is
violated by this much.
qc_verbose : bool
If true, print out a full QC report upon failure
If true, print out a full QC report upon failure.
**kwargs
Additional keyword arguments used when fitting the model.
Returns
-------
Results
A results instance.
Notes
-----
Expand All @@ -290,7 +298,6 @@ def fit_regularized(self, start_params=None, method='l1',
number of iterative refinement steps when solving KKT
equations (default: 1).
Optimization methodology
With :math:`L` the negative log likelihood, we solve the convex but
Expand Down Expand Up @@ -3436,31 +3443,31 @@ def llr_pvalue(self):
"""
return stats.distributions.chi2.sf(self.llr, self.df_model)

def set_null_options(self, llnull=None, attach_results=True, **kwds):
"""set fit options for Null (constant-only) model
def set_null_options(self, llnull=None, attach_results=True, **kwargs):
"""
Set the fit options for the Null (constant-only) model.
This resets the cache for related attributes which is potentially
fragile. This only sets the option, the null model is estimated
when llnull is accessed, if llnull is not yet in cache.
Parameters
----------
llnull : None or float
llnull : {None, float}
If llnull is not None, then the value will be directly assigned to
the cached attribute "llnull".
attach_results : bool
Sets an internal flag whether the results instance of the null
model should be attached. By default without calling this method,
thenull model results are not attached and only the loglikelihood
value llnull is stored.
kwds : keyword arguments
`kwds` are directly used as fit keyword arguments for the null
model, overriding any provided defaults.
Returns
-------
no returns, modifies attributes of this instance
**kwargs
Additional keyword arguments used as fit keyword arguments for the
null model. The override and model default values.
Notes
-----
Modifies attributes of this instance, and so has no return.
"""
# reset cache, note we need to add here anything that depends on
# llnullor the null model. If something is missing, then the attribute
Expand All @@ -3475,7 +3482,7 @@ def set_null_options(self, llnull=None, attach_results=True, **kwds):
if llnull is not None:
self._cache['llnull'] = llnull
self._attach_nullmodel = attach_results
self._optim_kwds_null = kwds
self._optim_kwds_null = kwargs

@cache_readonly
def llnull(self):
Expand Down Expand Up @@ -3629,7 +3636,8 @@ def get_margeff(self, at='overall', method='dydx', atexog=None,

def summary(self, yname=None, xname=None, title=None, alpha=.05,
yname_list=None):
"""Summarize the Regression Results
"""
Summarize the Regression Results.
Parameters
----------
Expand All @@ -3652,7 +3660,7 @@ def summary(self, yname=None, xname=None, title=None, alpha=.05,
See Also
--------
statsmodels.iolib.summary.Summary : class to hold summary results
statsmodels.iolib.summary.Summary : Class that hold summary results.
"""

top_left = [('Dep. Variable:', None),
Expand Down Expand Up @@ -3699,7 +3707,8 @@ def summary(self, yname=None, xname=None, title=None, alpha=.05,

def summary2(self, yname=None, xname=None, title=None, alpha=.05,
float_format="%.4f"):
"""Experimental function to summarize regression results
"""
Experimental function to summarize regression results.
Parameters
----------
Expand All @@ -3724,7 +3733,7 @@ def summary2(self, yname=None, xname=None, title=None, alpha=.05,
See Also
--------
statsmodels.iolib.summary2.Summary : class to hold summary results
statsmodels.iolib.summary2.Summary : Class that holds summary results.
"""
from statsmodels.iolib import summary2
smry = summary2.Summary()
Expand Down
Loading

0 comments on commit 828eb2a

Please sign in to comment.