{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Estimate moments"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this basic example we are going to estimate statistical moments from a sample."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from __future__ import print_function\n",
    "import openturns as ot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Create data\n",
    "size = 100\n",
    "mu = [-4.0, 5.0]\n",
    "sigma = [2.0, 3.0]\n",
    "R = ot.CorrelationMatrix(2)\n",
    "normal = ot.Normal(mu, sigma, R)\n",
    "sample = normal.getSample(size)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<p>[-3.99594,4.75612]<br>\n",
       "</p>"
      ],
      "text/plain": [
       "class=Point name=Unnamed dimension=2 values=[-3.99594,4.75612]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Estimate mean\n",
    "sample.computeMean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<p>[[ 1.89414   0         ]<br>\n",
       " [ 0.0759477 3.13125   ]]<br>\n",
       "</p>"
      ],
      "text/plain": [
       "class=TriangularMatrix dimension=2 implementation=class=MatrixImplementation name=Unnamed rows=2 columns=2 values=[1.89414,0.0759477,0,3.13125]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Estimate standard deviation\n",
    "sample.computeStandardDeviation()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<p>[3.58776,9.81049]<br>\n",
       "</p>"
      ],
      "text/plain": [
       "class=Point name=Unnamed dimension=2 values=[3.58776,9.81049]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Estimate variance\n",
    "sample.computeVariance()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<p>[-0.169881,0.108393]<br>\n",
       "</p>"
      ],
      "text/plain": [
       "class=Point name=Unnamed dimension=2 values=[-0.169881,0.108393]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Estimate skewness\n",
    "sample.computeSkewness()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<p>[3.45227,3.07151]<br>\n",
       "</p>"
      ],
      "text/plain": [
       "class=Point name=Unnamed dimension=2 values=[3.45227,3.07151]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Estimate kurtosis\n",
    "sample.computeKurtosis()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
