Linear model analysis

In [1]:
# import relevant module
import openturns as ot
import otpod
# enable display figure in notebook
    %matplotlib inline

Generate data

In [2]:
N = 100
defectDist = ot.Uniform(0.1, 0.6)
# normal epsilon distribution
epsilon = ot.Normal(0, 1.9)
defects = defectDist.getSample(N)
signalsInvBoxCox = defects * 43. + epsilon.getSample(N) + 2.5
# Inverse Box Cox transformation
invBoxCox = ot.InverseBoxCoxTransform(0.3)
signals = invBoxCox(signalsInvBoxCox)

Run analysis without Box Cox

In [3]:
analysis = otpod.UnivariateLinearModelAnalysis(defects, signals)

Get some particular results

In [4]:
[Intercept for uncensored case : -604.758]
[R2 for uncensored case : 0.780469]
[Kolmogorov p-value for uncensored case : 0.803087]

Show graphs

The linear model is not correct

In [6]:
fig, ax = analysis.drawLinearModel()
/home/dumas/anaconda2/lib/python2.7/site-packages/matplotlib/ UserWarning: matplotlib is currently using a non-GUI backend, so cannot show the figure
  "matplotlib is currently using a non-GUI backend, "

The residuals are not homoskedastic

In [7]:
fig, ax = analysis.drawResiduals()

Run analysis with Box Cox

In [8]:
analysis = otpod.UnivariateLinearModelAnalysis(defects, signals, boxCox=True)

Save all results in a csv file

In [10]:

Show graphs

The linear regression model with data

In [11]:
fig, ax = analysis.drawLinearModel(name='figure/linearModel.png')
# The figure is saved as png file

The residuals with respect to the defects

In [12]:
fig, ax = analysis.drawResiduals(name='figure/residuals.eps')
# The figure is saved as eps file

The fitted residuals distribution with the histogram

In [13]:
fig, ax = analysis.drawResidualsDistribution()
# The figure is saved after the changes
fig.savefig('figure/residualsDistribution.png', bbox_inches='tight')

The residuals QQ plot

In [14]:
fig, ax = analysis.drawResidualsQQplot()

The Box Cox likelihood with respect to the defect

In [15]:
fig, ax = analysis.drawBoxCoxLikelihood(name='figure/BoxCoxlikelihood.png')