<commit_before># emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
"""
This module implements some standard regression models: OLS and WLS
models, as well as an AR(p) regression model.

Models are specified with a design matrix and are fit using their
'fit' method.

Subclasses that have more complicated covariance matrices
should write over the 'whiten' method as the fit method
prewhitens the response by calling 'whiten'.

General reference for regression models:

'Introduction to Linear Regression Analysis', <NAME>,
    <NAME>, <NAME>, 2006.

"""

__docformat__ = 'restructuredtext en'

import warnings

import numpy as np


from scipy import stats
import scipy.linalg as spl

from nipy.algorithms.utils.matrices import matrix_rank, pos_recipr

from .model import LikelihoodModel, LikelihoodModelResults

from .descriptors import setattr_on_read

def categorical(data):
    '''
    Returns an array changing categorical variables to dummy variables.

    Take a structured or record array and returns an array with categorical variables.

    Notes
    -----
    This returns a dummy variable for EVERY distinct string.  If noconsant
    then this is okay.  Otherwise, a "intercept" needs to be designated in regression.

    Returns the same array as it's given right now, consider returning a structured 
    and plain ndarray (with names stripped, etc.)
    '''
    if not data.dtype.names and not data.mask.any():
        print data.dtype
        print "There is not a categorical variable?"
        return data
    #if data.mask.any():
    #    print "Masked arrays are not handled yet."
    #    return data

    elif data.dtype.names:  # this will catch both structured and record
                            # arrays, no other array could have string data!
                            # not sure about masked arrays yet
        for i in range(len(data.dtype)):
            if data.dtype[i].type is np.string_:
                tmp_arr = np.unique(data.field(i))
                tmp_dummy = (tmp_arr[:,np.newaxis]==data.field(i)).astype(float)
# .field only works for record arrays
# tmp_dummy is a number of dummies x number of observations array
                data=nprf.drop_fields(data,data.dtype.names[i],usemask=False, 
                                asrecarray=True)
                data=nprf.append_fields(data,tmp_arr.strip("\""), data=tmp_dummy,
                                    usemask=False, asrecarray=True)
        return data


#How to document a class?
#Docs are a little vague and there are no good examples
#Some of these attributes are most likely intended to be private I imagine
class OLSModel(LikelihoodModel):
    """ A simple ordinary least squares model.

    Parameters
    ----------
    design : array-like
        This is your design matrix.  Data are assumed to be column ordered with
        observations in rows.

    Methods
    -------
    model.__init___(design)
    model.logL(b=self.beta, Y)

    Attributes
    ----------
    design : ndarray<commit_msg>RF - deleted unused and untested function<commit_after># emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
"""
This module implements some standard regression models: OLS and WLS
models, as well as an AR(p) regression model.

Models are specified with a design matrix and are fit using their
'fit' method.

Subclasses that have more complicated covariance matrices
should write over the 'whiten' method as the fit method
prewhitens the response by calling 'whiten'.

General reference for regression models:

'Introduction to Linear Regression Analysis', <NAME>,
    <NAME>, <NAME>. Wiley, 2006.

"""

__docformat__ = 'restructuredtext en'

import warnings

import numpy as np


from scipy import stats
import scipy.linalg as spl

from nipy.algorithms.utils.matrices import matrix_rank, pos_recipr

from .model import LikelihoodModel, LikelihoodModelResults

from .descriptors import setattr_on_read

#How to document a class?
#Docs are a little vague and there are no good examples
#Some of these attributes are most likely intended to be private I imagine
class OLSModel(LikelihoodModel):
    """ A simple ordinary least squares model.

    Parameters
    ----------
    design : array-like
        This is your design matrix.  Data are assumed to be column ordered with
        observations in rows.

    Methods
    -------
    model.__init___(design)
    model.logL(b=self.beta, Y)

    Attributes
    ----------
    design : ndarray
{'fraction_non_alphanumeric': 0.08202099737532809, 'fraction_numerical': 0.003499562554680665, 'mean_word_length': 2.878710771840543, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5385162', 'n_tokens_mistral': 1290, 'n_tokens_neox': 1236, 'n_words': 518}