1# -*- coding: utf-8 -*-
2"""script to check KernelCensoredReg based on test file
3
4Created on Thu Jan 03 20:20:47 2013
5
6Author: Josef Perktold
7"""
8
9import numpy as np
10import statsmodels.nonparametric.api as nparam
11
12if __name__ == '__main__':
13    #example from test file
14    nobs = 200
15    np.random.seed(1234)
16    C1 = np.random.normal(size=(nobs, ))
17    C2 = np.random.normal(2, 1, size=(nobs, ))
18    noise = 0.1 * np.random.normal(size=(nobs, ))
19    y = 0.3 +1.2 * C1 - 0.9 * C2 + noise
20    y[y>0] = 0  # censor the data
21    model = nparam.KernelCensoredReg(endog=[y], exog=[C1, C2],
22                                     reg_type='ll', var_type='cc',
23                                     bw='cv_ls', censor_val=0)
24    sm_mean, sm_mfx = model.fit()
25
26    import matplotlib.pyplot as plt
27    fig = plt.figure()
28    ax = fig.add_subplot(1,1,1)
29    sortidx = np.argsort(y)
30    ax.plot(y[sortidx], 'o', alpha=0.5)
31    #ax.plot(x, y_cens, 'o', alpha=0.5)
32    #ax.plot(x, y_true, lw=2, label='DGP mean')
33    ax.plot(sm_mean[sortidx], lw=2, label='model 0 mean')
34    #ax.plot(x, mean2, lw=2, label='model 2 mean')
35    ax.legend()
36
37    plt.show()
38