statsmodels.tools.tools.add_constant

statsmodels.tools.tools.add_constant(data, prepend=True, has_constant='skip')[source]

This appends a column of ones to an array if prepend==False.

Parameters:

data : array-like

data is the column-ordered design matrix

prepend : bool

True and the constant is prepended rather than appended.

has_constant : str {‘raise’, ‘add’, ‘skip’}

Behavior if ``data’’ already has a constant. The default will return data without adding another constant. If ‘raise’, will raise an error if a constant is present. Using ‘add’ will duplicate the constant, if one is present. Has no effect for structured or recarrays. There is no checking for a constant in this case.

Returns:

data : array

The original array with a constant (column of ones) as the first or last column.