\documentclass{article}
\usepackage{graphicx}\usepackage{beamerarticle}\usepackage[margin=9mm]{geometry}
\usetheme{Madrid}
\usepackage[spanish]{babel}
\usepackage{dsfont}
\usepackage{ifthen}
\usepackage{mleftright}\mleftright
\def\qedsymbol{} % quita el símbolo final de las demos
\addtobeamertemplate{theorem begin}{\normalfont}{} % que no esté en cursiva
\newtheorem*{lema}{Lema}
\newtheorem*{teorema}{Teorema}
\newtheorem*{notacion}{Notación}
\newcommand{\Dn}{\ensuremath{\Delta_n}} % estadígrafo de KyS
\newcommand{\dkn}{\ensuremath{\delta_n^k}}
\renewcommand{\P}[1]{\Pr\left[#1\right]} % probabilidad
\newcommand{\casiseguro}%
{\ensuremath{\xrightarrow[n\rightarrow\infty]{\text{c.s.}}}}
\newcommand{\enley}%
{\ensuremath{\xrightarrow[n\rightarrow\infty]{\mathcal L}}}
\newcommand{\abs}[1]{\left|#1\right|} % valor absoluto
\newcommand{\funcion}[2]{\ifthenelse{\equal{#2}{}}{#1}{#1\left(#2\right)}}
\newcommand{\F}[1]{\funcion{F}{#1}} % función de distribución
\newcommand{\Fn}[1]{\funcion{F_n}{#1}} % función de distribución empírica
\newcommand{\N}{\mathbb{N}} % naturales
\newcommand{\R}{\mathbb{R}} % recta real
\newcommand{\uno}[2]{\mathds{1}_{#1}\left(#2\right)}
\newcommand{\sigue}{\mathbin{\sim}}
\newcommand{\binomial}[2]{\mathcal B \left(#1,#2\right)}
\newcommand{\gausiana}[2]{\mathcal N \left(#1,#2\right)}
\newcommand{\iz}[1]{#1^{-}}
\newcommand{\x}[2]{x_{#1,#2}}
\newcommand{\xiz}[2]{\iz{x}_{#1,#2}}
\newcommand{\conjuntotalque}[2]{\left\{#1\;\middle|\;#2\right\}}
\begin{document}
\title{Función de distribución empírica}
\subtitle{Teorema fundamental de la estadística (Glivenco y Canteli)}
\author{Inferencia Estadística}
\maketitle

\begin{frame}
  \begin{notacion}
    \rule{0pt}{.7ex}
    \begin{description}
    \item[$X$] población; variable aleatoria $X:\Omega\longrightarrow\R$.
    \item[$X_1,...,X_n,...$] sucesión de variables aleatorias independientes
      e idénticamente distribuidas como $X$
    \item[$\F{\cdot}$] función de distribución de $X$
    \item[$\Fn{\cdot}$] función de distribución empírica de $X_1,...,X_n$
      \[ \Fn{x} = \frac1n\sum_{i=1}^n \uno{(-\infty,x]}{X_i} \]
    \end{description}
    \rule{0pt}{.7ex}
  \end{notacion}
\end{frame}


\begin{frame}
  \begin{notacion}
    \begin{description}
    \item[\casiseguro] convergencia casi seguro cuando $n$ tiende a infinito:
    \end{description}
  \end{notacion}
  \begin{block}{}
    \[\begin{array}{rccc}
        A_1,...,A_n,...\colon&\Omega&\longrightarrow&\R^{\infty}\\
        &\omega & \longmapsto & (a_1,...,a_n,...)
      \end{array}\]
    \begin{eqnarray*}
      A_n\casiseguro a &\iff& \P{\lim_n A_n=a}=1\\
      &\iff& \P{\left\{\omega\;\middle|\;\lim_n a_n=a\right\}}=1\\
    \end{eqnarray*}
  \end{block}
\end{frame}


\begin{frame}
  \begin{block}{Función de distribución empírica}
      \[ \Fn{x} = \frac1n\sum_{i=1}^n \uno{(-\infty,x]}{X_i} \]    
    \end{block}
    \begin{block}{}
      \[ n\cdot\Fn{x} \sigue \binomial{n}{\P{X\leq x}} =
        \binomial{n}{\F{x}} \]
    \end{block}
    \begin{block}{}
      \[ \text{Ley fuerte de los grandes números:}\quad
        \forall\, x\in\R, \;\Fn{x} \casiseguro \F{x} \]
    \end{block}
    \begin{block}{}
      \[ \text{T.C.L.:}\quad \forall\, x\in\R, \quad
        \frac{\Fn{x}-\F{x}}{\sqrt{\frac{\F{x}[1-\F{x}]}{n}}}
        \enley \gausiana{0}{1} \]
    \end{block}
    \begin{block}{}
      Lo mismo ocurre con $\displaystyle\Fn{\iz{x}}=\lim_{t\to \iz{x}}\Fn{t}$
      y $\F{\iz{x}}=\P{X<x}$.
    \end{block}
\end{frame}
\begin{frame}
  \begin{notacion}
    \begin{description}
    \item[\Dn] distancia máxima en vertical entre dos funciones:
      \[ \Dn = D_{\infty}(F_n,F)=\sup_{x\in\R} \abs{\Fn{x}-\F{x}} \]
    \end{description}
  \end{notacion}
  \begin{block}{}
    \begin{center}
      \includegraphics[width=150pt]{bildoj/deltan.png}
    \end{center}
  \end{block}
\end{frame}

\begin{frame}[fragile]
  \begin{block}{Funciones de distribución}
    \begin{verbatim}
      D <- "unif"                     # norm exp ...
      X <- get (paste0 ("r", D)) (10) # 100 1000 ...
      F <- get (paste0 ("p", D))      # teórica
      Fn <- ecdf (X)                  # empírica
      plot (Fn)                        
      plot (F, min(X), max(X), col=2, add=TRUE)
\end{verbatim}
  \end{block}
  \begin{block}{Distancia máxima}
\begin{verbatim}
      X   <- sort (X) ; n <- length (X)
      Dn1 <- abs (F(X) - Fn(X))
      Dn2 <- abs (F(X) - c(0,Fn(X[-n])))
      i1  <- which.max (Dn1) ; i2 <- which.max (Dn2)
      I   <- if (Dn1[i1] > Dn2[i2]) 1 else 2
      i   <- c(i1,i2)[I] ; Xi <- X[i]
      Yi  <- c (Fn(Xi), c(0,Fn(X))[i]) [I]
      arrows (Xi, F(Xi), Xi, Yi, code=3, col=3)
\end{verbatim}
  \end{block}
\end{frame}

\begin{frame}
  \begin{teorema}[fundamental de la estadística o de Glivenco y Canteli]
    \[ \Dn \casiseguro 0 \]
  \end{teorema}
\end{frame}

\begin{frame}
  \begin{lema}{}
    Sean \(A_1,A_2,\dots\) sucesos con \(\P{A_i}=1\,\forall i\)

    Entonces \(\P{\bigcap_i A_i}=1\).
  \end{lema}
  \begin{proof}
    \[\P{\bigcap_i A_i}=1-\P{\bigcup_i A_i^c} \ge 1-\sum_i\P{A_i^c}
      =1-\sum_i 0=1\]
  \end{proof}
\end{frame}

\begin{frame}
  \begin{teorema}[fundamental de la estadística o de Glivenco y Canteli]
    \[ \Dn \casiseguro 0 \]
  \end{teorema}
  \begin{proof}
    Veremos dos situaciones:
    \begin{enumerate}
    \item variable discreta con número finito de valores
    \item caso general
    \end{enumerate}
    En cada situación se consideran
    \begin{itemize}
    \item sucesión de variables \((X_1,\dots,X_n,\dots)\)
    \item sucesión particular \(\omega=(x_1,\dots,x_n,\dots)\)
    \end{itemize}
  \end{proof}
\end{frame}

 \begin{frame}
   \begin{block}{Caso discreto finito}
     $X$ toma valores $x_j$, $j\in\{1,\dots,k\}$, con $x_j<x_{j+1}$.
     %y $p_j=\P{X=x_j}$.
     \[ \text{$\F{}$ y $\Fn{}$ escalonadas}\implies
       \Dn(\omega) = \max_j\,\abs{\Fn{x_j,\omega}-\F{x_j}} \]
     $\forall\,j$, sea
     $A_j=\conjuntotalque{\omega}{\lim\Fn{x_j,\omega}=\F{x_j}}$. Sea
     $\displaystyle A=\bigcap_{j=1}^k A_j$.

     \[\Fn{x_j}\casiseguro\F{x_j}\implies\P{A_j}=1
       \implies \P{A}=1\]
     \[\omega\in A\implies\omega\in A_j\implies\forall\,\epsilon\,
       \exists\,n_{j,\epsilon}\,\forall\,n>n_{j,\epsilon},
       \abs{\Fn{x_j,\omega}-\F{x_j}}<\epsilon\]
     \[\omega\in A\implies\forall\,\epsilon\,
       \exists\,n_{\epsilon}=\max_{j=1}^nn_{j,\epsilon}\,\forall\,n>n_{\epsilon},
       \Dn(\omega)<\epsilon\]
     \[\implies\P{\lim\Dn=0}=1\implies\Dn\casiseguro0\]
     
   \end{block}
 \end{frame}

\begin{frame}
  \begin{block}{Caso general}
    Sea $k\in\N$ y considérense los cuantiles
    \[ \x{k}{j} = \inf\conjuntotalque{x}{\F{x}\geq\frac j k}
      \qquad j=1,...,k\]

    % \bigskip
    
    % Más adelante se usará que
    % \[ \F{\xiz k {j+1}} \le \F{\x k j} + \frac1k \]
    % Se verá ahora la interpretación gráfica de esa fórmula
    % para ilustrar los $\x k j$.
  \end{block}
\end{frame}

% \begin{frame}
%   \begin{proof}[Caso continuo]
%     \begin{center}
%     \setlength{\unitlength}{1cm}
%     \begin{picture}(9,6)
%       \put(-0.5,0){\vector(1,0){10}}
%       \put(0,-0.5){\vector(0,1){6}}
%       \put(-0.25,-0.35){0}
%       %% \put(2,-0.35){$\x k 1$}
%       \put(2.9,-0.35){$\cdots$}
%       \put(4,-0.35){$\x k j$}
%       \put(6,-0.35){$\x k{j+1}$}
%       \put(7.5,-0.35){$\cdots$}
%       \put(-.25,4.9){1}
%       \multiput(0,5)(0.2,0){40}{\line(1,0){0.1}}
%       %% \multiput(2.1,0)(0,0.2){4}{\line(0,1){0.1}}
%       %% \multiput(0,.72)(0.2,0){10}{\line(1,0){0.1}}
%       %% \put(-.3,.62){$\frac1k$}
%       \multiput(4.1,0)(0,0.2){8}{\line(0,1){0.1}}
%       \multiput(0,1.6)(0.2,0){21}{\line(1,0){0.1}}
%       \put(-.3,1.5){$\frac j k$}
%       \multiput(6.1,0)(0,0.2){14}{\line(0,1){0.1}}
%       \multiput(0,2.7)(0.2,0){31}{\line(1,0){0.1}}
%       \put(-.6,2.61){$\frac{j+1}k$}
%       \thicklines
%       \qbezier(0,0)(3,1)(5,2)
%       \qbezier(5,2)(7,3)(8,5)
%       \qbezier(8,5)(8.5,5)(9,5) \put(8.5,4){$\F{x}$}
%       %\only<2>{\put(.5,2){\( \F{\iz{\x k {j+1}}} \le \F{\x k j} + \frac1k \)}}
%       \only<2>{\put(6.5,2.6){\( \F{\iz{\x k {j+1}}} = \F{\x k {j+1}} \)}}
%       \only<3>{\put(6.5,2.6){\( \F{\iz{\x k {j+1}}} = \frac{j+1}k \)}}
%       \only<4>{\put(6.5,2.6){\( \F{\iz{\x k {j+1}}} = \frac jk+\frac{1}k \)}}
%       \only<5>{\put(6.5,2.6){\( \F{\iz{\x k {j+1}}} = {} \)}}
%       \only<6>{\put(6.5,2.6){\( \F{\iz{\x k {j+1}}} \le {} \)}}
%       \only<5>{\put(7,1.8){\( {} = \F{\x k j} + \frac1k \)}}
%       \only<6>{\put(7,1.8){\( {} \le \F{\x k j} + \frac1k \)}}
%     \end{picture}      
%     \end{center}
%   \end{proof}
% \end{frame}

% \begin{frame}
%   \begin{proof}[Caso discreto (sin coincidencia)]
%     \begin{center}
%     \setlength{\unitlength}{1cm}
%     \begin{picture}(9,6)
%       \put(-0.5,0){\vector(1,0){10}}
%       \put(0,-0.5){\vector(0,1){6}}
%       \put(-0.25,-0.35){0}
%       \put(2,-0.35){$\x k j$}
%       \put(1,-0.35){$\cdots$}
%       \only<3->{\put(7.5,-0.35){$\cdots$}
%       \put(5.9,-0.35){$\x k{j+1}$}}
%       \put(-.25,4.9){1}
%       \multiput(0,5)(0.2,0){40}{\line(1,0){0.1}}
%       \multiput(0,.72)(0.2,0){10}{\line(1,0){0.1}} \put(-1.3,.69){$\F{\x k j}$}
%       \only<4->{
%       \multiput(0,1.6)(0.2,0){21}{\line(1,0){0.1}}
%       \put(-1.6,1.56){$F\bigl(\x k{j+1}^{-}\bigr)$}}
%       \only<2->{\multiput(0,2.7)(0.2,0){31}{\line(1,0){0.1}}
%       \put(-1.6,2.66){$F(\!\x k j\!)\!+\!\frac1k$}
%       \multiput(6.1,1.6)(0,0.2){11}{\line(0,1){0.1}}}
%       \only<3->{\multiput(0,3.7)(0.2,0){31}{\line(1,0){0.1}}
%       \put(-1.6,3.6){$\F{\x k {j+1}}$}}
%       \thicklines
%       \put(8,5){\line(1,0){1}}
%       \put(8,5){\circle*{0.2}}
%       \put(2.1,.72){\circle*{0.2}}
%       \put(2.1,.72){\line(1,0){2}}
%       \put(4.1,1.6){\circle*{0.2}}
%       \put(4.1,1.6){\line(1,0){2}}
%       \put(6.1,3.7){\circle*{0.2}}
%       \put(6.1,3.7){\line(1,0){1}}
%       \put(7.2,4.2){$\cdots$}
%       \only<5>{\put(5.5,.7){\( \F{\iz{\x k {j+1}}} \le \F{\x k j} + \frac1k \)}}
%     \end{picture}      
%     \end{center}
%   \end{proof}
% \end{frame}

% \begin{frame}
%   \begin{proof}[Caso discreto (con coincidencia)]
%     \begin{center}
%     \setlength{\unitlength}{1cm}
%     \begin{picture}(9,6)
%       \put(-0.5,0){\vector(1,0){10}}
%       \put(0,-0.5){\vector(0,1){6}}
%       \put(-0.25,-0.35){0}
%       \put(2,-0.35){$\x k j$}
%       \put(1,-0.35){$\cdots$}
%       \only<2->{\put(6,-0.35){$\x k{j+1}$}\put(7.5,-0.35){$\cdots$}}
%       \put(-.25,4.9){1}
%       \multiput(0,5)(0.2,0){40}{\line(1,0){0.1}}
%       \multiput(0,.72)(0.2,0){10}{\line(1,0){0.1}} \put(-1.3,.69){$\F{\x k j}$}
%       \only<4->{
%       \multiput(0,1.6)(0.2,0){21}{\line(1,0){0.1}}
%       \put(-1.6,1.56){$F\bigl(\xiz k{j+1}\bigr)$}}
%     \only<2>{%\multiput(0,2.7)(0.2,0){31}{\line(1,0){0.1}}
%       \multiput(0,3.7)(0.2,0){31}{\line(1,0){0.1}}
%       \put(-1.6,3.6){$F(\!\x k j\!)\!+\!\frac1k$}
%       % \multiput(6.1,1.6)(0,0.2){11}{\line(0,1){0.1}}
%     }
%       \only<3->{\multiput(0,3.7)(0.2,0){31}{\line(1,0){0.1}}
%       \put(-1.6,3.6){$\F{\x k{j+1}}$}}
%       \thicklines
%       \put(8,5){\line(1,0){1}}
%       \put(8,5){\circle*{0.2}}
%       \put(2.1,.72){\circle*{0.2}}
%       \put(2.1,.72){\line(1,0){2}}
%       \put(4.1,1.6){\circle*{0.2}}
%       \put(4.1,1.6){\line(1,0){2}}
%       \put(6.1,3.7){\circle*{0.2}}
%       \put(6.1,3.7){\line(1,0){1}}
%       \put(7.2,4.2){$\cdots$}
%       \only<5>{\put(1.5,2.5){\( \F{\iz{\x k {j+1}}} \le \F{\x k j} + \frac1k \)}}
%     \end{picture}      
%     \end{center}
%   \end{proof}
% \end{frame}


\begin{frame}
  \begin{block}{}
  Sabemos que $\forall \, k\in\N\quad\forall\,1\leq j\le k$
  \[
    \Fn{\x k j} \casiseguro \F{\x k j}\qquad\text{y}\qquad
    \Fn{\iz{\x k j}} \casiseguro \F{\iz{\x k j}}
  \]
\end{block}
\begin{block}{}
  Sean
  \[A_{k,j}=\conjuntotalque{\omega}{\lim\Fn{\x k j,\omega}=\F{\x k j}}\]
  \[B_{k,j}=\conjuntotalque{\omega}{\lim\Fn{\xiz k j,\omega}=\F{\xiz k j}}\]
  \[C_{k}=\bigcap_{j=1}^k A_{k,j}\cap B_{k,j}\qquad C=\bigcap_{k\in\N}C_k \]
\end{block}
\begin{block}{}
  Entonces
  \[\forall\,k\,\forall\,j,\,\P{A_{k,j}}=\P{B_{k,j}}=\P{C_k}=\P{C}=1\]
\end{block}
\end{frame}

 \begin{frame}
   \begin{block}{}
     Para cada $\omega=(x_n)_{n\in\N}\in\Omega$ sea $\Fn{}$ la función de
     distribución empírica asociada a $(x_1,\dots,x_n)$ y sea
     \[\dkn =
       \max_{j}\left\{\abs{\Fn{\x kj}-\F{\x kj}},
         \abs{\Fn{\xiz kj}-\F{\xiz kj}}\right\}\]
     luego
          \[ \forall\,\,\omega\in C, \lim_{n\to\infty}\dkn=0 \]
   \end{block}
   \begin{block}{}
     Si $x\in[\x kj,\x k{j+1})$ entonces
     \begin{eqnarray*}
       \Fn{\x k j}&\le\Fn{x}\le&\Fn{\xiz k {j+1}} \\
       \frac j k \le \F{\x k j}&\le\F{x}\le&\F{\xiz k {j+1}}\le\frac{j+1}k 
     \end{eqnarray*}
     luego
     \[\Fn{\x kj}-\F{\xiz k{j+1}}
     \le \Fn{x}-\F{x} \le \Fn{\xiz k{j+1}}-\F{\x k{j}}\]
   \end{block}
 \end{frame}

 \begin{frame}
     \begin{block}{}
     \[\Fn{\x kj}-\F{\xiz k{j+1}}
     \le \Fn{x}-\F{x} \le \Fn{\xiz k{j+1}}-\F{\x k{j}}\]
     \end{block}
   \begin{block}{}
     \[   \frac j k \le \F{\x k j}\le\F{\xiz k {j+1}}\le\frac{j+1}k
       \implies \F{\xiz k {j+1}} \le \F{\x k j} + \frac1k \]
     entonces
     \[ \Fn{\xiz k {j+1}} -  \F{\x k j} \le
       \Fn{\xiz k {j+1}} + \frac1k - \F{\xiz k {j+1}}
       \le \dkn+\frac1k\]
     \[  \Fn{\x k j} - \F{\xiz k {j+1}}   \ge
         \Fn{\x k j} - \F{\x kj} -\frac1k \ge -\dkn-\frac1k\]
     \end{block}
     \begin{block}{}
       \[-\dkn-\frac1k\le\Fn{x}-\F{x}\le\dkn+\frac1k\]
     \end{block}
 \end{frame}
 \begin{frame}
   \begin{block}{}
     Por tanto, $\forall\,k\in\N\;\forall\,j\in\{1,\dots,k-1\}\;
     \forall\,x\in[\x kj,\x k{j+1})$
     \[\abs{\Fn{x}-\F{x}}\le\dkn+\frac1k\]
   \end{block}
   \begin{block}{}
     Queda ver qué ocurre en los extremos,
     \begin{itemize}
     \item $x<\x k1$
     \item $x\ge\x kk$
     \end{itemize}
   \end{block}
 \end{frame}
 \begin{frame}
 \begin{block}{}
     Si $x<\x k1$ entonces $\F{\xiz k1}\le\frac1k$ y
     \[
       \left.
       \begin{array}{ccc}
         0\le&\Fn{x}&\le\Fn{\xiz k1}\\
         0\le&\F{x}&\le\F{\xiz k1}
       \end{array}
       \right\}\implies-\F{\xiz k1}\le\Fn{x}-\F{x}\le\Fn{\xiz k1}
     \]

     Por definición de $\dkn$,
     \[
       \Fn{\xiz k1}\le\F{\xiz k1}+\dkn \le\frac1k+\dkn
     \]
     \[
       -\F{\xiz k1}\ge-\frac1k\ge-\frac1k-\dkn
     \]
     \[\implies \abs{\Fn{x}-\F{x}}\le\frac1k+\dkn\]
   \end{block}
 \end{frame}
 \begin{frame}
   \begin{block}{}
     Si $x\ge\x kk$ entonces $\F{\x kk}=1$ y $\Fn{\x kk}=1$,

     luego $\abs{\Fn{x}-\F{x}}=\abs{1-1}=0$.
   \end{block}
   \begin{block}{}
     Por tanto, $\forall\,x\in\R$
     \[ \abs{\Fn{x}-\F{x}}\le\frac1k+\dkn \]
     luego $\forall\,\omega\in C$
     \[ \Dn(\omega)=\sup_{x\in\R}\abs{\Fn{x,\omega}-\F{x}}\le\frac1k+\dkn \]
     y
     \[ \lim_{n\to\infty}\dkn=0 \]
   \end{block}
 \end{frame}

 \begin{frame}
   \begin{block}{}
     Para todo \(\omega\in C\)
     \[0\leq\lim_{n\to\infty}\Dn(\omega)
       \leq \lim_n\frac1k+\dkn=\frac1k+\lim_n\dkn=\frac1k\]
     Como eso se verifica $\forall\,k\in\N$,
     \[\lim_{n\to\infty}\Dn(\omega)=0\quad\forall\,\omega\in C\]
     y como $\P{C}=1$ entonces
     \[\Dn\casiseguro 0\]
   \end{block}
   \begin{block}{Interpretación}
     \begin{itemize}
     \item 
     $\F{x}$ está dentro de la banda
     $\Fn{x}\pm\epsilon$ con probabilidad $1$.
   \item Se puede estimar $\F{}$ con precisión arbitraria siempre que
     se disponga de suficiente tamaño muestral.
     \end{itemize}
   \end{block}
 \end{frame}
% \begin{frame}
%   \begin{proof}[Caso continuo]
%     \[ t_{j+1} = \inf\{x\mid\F{x}\geq\F{t_j}+\epsilon\} \]
%     En este caso,
%     \begin{eqnarray*}
%       \F{t_{j+1}} &=& \F{t_j}+\epsilon = j\cdot\epsilon
%                       \text{ para $j=0,...,k-1$} \\
%       \F{t_k} &=& 1
%     \end{eqnarray*}
%     luego
%     \[
%       \F{t_{j+1}^-} - \F{t_j} = \F{t_{j+1}} - \F{t_j} = \epsilon \leq \epsilon
%     \]
%   \end{proof}
% \end{frame}

% \begin{frame}
%   \begin{proof}[Caso discreto]
%     \[ t_{j+1} = \inf\{x\mid\F{x}\geq\F{t_j}+\epsilon\} \]
%     En ambos casos,
%     \[
%       \F{t_{j+1}^-} - \F{t_j} \leq \epsilon
%     \]
%     \qed
%   \end{proof}
% \end{frame}

\end{document}
