[<< wikibooks] Statistics/Distributions/Discrete Uniform
=== Discrete Uniform Distribution ===
The discrete uniform distribution (not to be confused with the continuous uniform distribution) is where the probability of equally spaced possible values is equal. Mathematically this means that the probability density function is identical for a finite set of evenly spaced points. An example of would be rolling a fair 6-sided die. In this case there are six, equally like probabilities.
One common normalization is to restrict the possible values to be integers and the spacing between possibilities to be 1. In this setup, the only two parameters of the function are the minimum value (a), the maximum value (b). (Some even normalize it more, setting a=1.) Let n=b-a+1 be the number of possibilities. The probability density function is then

  
    
      
        f
        :
        {
        a
        ,
        a
        +
        1
        ,
        …
        ,
        b
        −
        1
        ,
        b
        }
        →
        
          R
        
      
    
    {\displaystyle f\colon \{a,a+1,\ldots ,b-1,b\}\to \mathbb {R} }
  

  
    
      
        f
        
          (
          x
          )
        
        =
        
          
            1
            n
          
        
      
    
    {\displaystyle f\left(x\right)={\frac {1}{n}}}
  


==== Mean ====
Let 
  
    
      
        S
        =
        {
        a
        ,
        a
        +
        1
        ,
        …
        ,
        b
        −
        1
        ,
        b
        }
      
    
    {\displaystyle S=\{a,a+1,\ldots ,b-1,b\}}
  . The mean (notated as 
  
    
      
        E
        ⁡
        [
        X
        ]
      
    
    {\displaystyle \operatorname {E} [X]}
  ) can then be derived as follows:

  
    
      
        E
        ⁡
        [
        X
        ]
        =
        
          ∑
          
            x
            ∈
            S
          
        
        x
        f
        (
        x
        )
        =
        
          ∑
          
            i
            =
            0
          
          
            n
            −
            1
          
        
        
          (
          
            
              
                1
                n
              
            
            (
            a
            +
            i
            )
          
          )
        
      
    
    {\displaystyle \operatorname {E} [X]=\sum _{x\in S}xf(x)=\sum _{i=0}^{n-1}\left({\frac {1}{n}}(a+i)\right)}
  

  
    
      
        E
        ⁡
        [
        X
        ]
        =
        
          
            1
            n
          
        
        
          (
          
            
              ∑
              
                i
                =
                0
              
              
                n
                −
                1
              
            
            a
            +
            
              ∑
              
                i
                =
                0
              
              
                n
                −
                1
              
            
            i
          
          )
        
      
    
    {\displaystyle \operatorname {E} [X]={1 \over n}\left(\sum _{i=0}^{n-1}a+\sum _{i=0}^{n-1}i\right)}
  Remember that in 
  
    
      
        
          ∑
          
            i
            =
            0
          
          
            m
          
        
        i
        =
        (
        
          m
          
            2
          
        
        +
        m
        )
        
          /
        
        2
      
    
    {\displaystyle \sum _{i=0}^{m}i=(m^{2}+m)/2}
  

  
    
      
        E
        ⁡
        [
        X
        ]
        =
        
          
            1
            n
          
        
        
          (
          
            n
            a
            +
            
              
                
                  (
                  n
                  −
                  1
                  
                    )
                    
                      2
                    
                  
                  +
                  (
                  n
                  −
                  1
                  )
                
                2
              
            
          
          )
        
      
    
    {\displaystyle \operatorname {E} [X]={1 \over n}\left(na+{(n-1)^{2}+(n-1) \over 2}\right)}
  

  
    
      
        E
        ⁡
        [
        X
        ]
        =
        
          
            
              2
              n
              a
              +
              
                n
                
                  2
                
              
              −
              2
              n
              +
              1
              +
              n
              −
              1
            
            
              2
              n
            
          
        
      
    
    {\displaystyle \operatorname {E} [X]={2na+n^{2}-2n+1+n-1 \over 2n}}
  

  
    
      
        E
        ⁡
        [
        X
        ]
        =
        
          
            
              2
              a
              +
              n
              −
              1
            
            2
          
        
      
    
    {\displaystyle \operatorname {E} [X]={2a+n-1 \over 2}}
  

  
    
      
        E
        ⁡
        [
        X
        ]
        =
        
          
            
              a
              +
              b
            
            2
          
        
      
    
    {\displaystyle \operatorname {E} [X]={a+b \over 2}}
  


==== Variance ====
The variance (
  
    
      
        E
        [
        (
        X
        −
        E
        X
        
          )
          
            2
          
        
        ]
      
    
    {\displaystyle E[(X-EX)^{2}]}
  ) can be derived:

  
    
      
        Var
        ⁡
        (
        X
        )
        =
        E
        ⁡
        [
        (
        X
        −
        E
        ⁡
        [
        X
        ]
        
          )
          
            2
          
        
        ]
        =
        
          ∑
          
            x
            ∈
            S
          
        
        f
        (
        x
        )
        (
        x
        −
        E
        [
        X
        ]
        
          )
          
            2
          
        
        =
        
          ∑
          
            i
            =
            0
          
          
            n
            −
            1
          
        
        
          (
          
            
              
                1
                n
              
            
            
              
                (
                
                  (
                  a
                  +
                  i
                  )
                  −
                  
                    
                      
                        a
                        +
                        b
                      
                      2
                    
                  
                
                )
              
              
                2
              
            
          
          )
        
      
    
    {\displaystyle \operatorname {Var} (X)=\operatorname {E} [(X-\operatorname {E} [X])^{2}]=\sum _{x\in S}f(x)(x-E[X])^{2}=\sum _{i=0}^{n-1}\left({\frac {1}{n}}\left((a+i)-{a+b \over 2}\right)^{2}\right)}
  

  
    
      
        Var
        ⁡
        (
        X
        )
        =
        
          
            1
            n
          
        
        
          ∑
          
            i
            =
            0
          
          
            n
            −
            1
          
        
        
          
            (
            
              
                
                  a
                  +
                  2
                  i
                  −
                  b
                
                2
              
            
            )
          
          
            2
          
        
      
    
    {\displaystyle \operatorname {Var} (X)={1 \over n}\sum _{i=0}^{n-1}\left({a+2i-b \over 2}\right)^{2}}
  

  
    
      
        Var
        ⁡
        (
        X
        )
        =
        
          
            1
            
              4
              n
            
          
        
        
          ∑
          
            i
            =
            0
          
          
            n
            −
            1
          
        
        (
        
          a
          
            2
          
        
        +
        4
        a
        i
        −
        2
        a
        b
        +
        4
        
          i
          
            2
          
        
        −
        4
        i
        b
        +
        
          b
          
            2
          
        
        )
      
    
    {\displaystyle \operatorname {Var} (X)={1 \over 4n}\sum _{i=0}^{n-1}(a^{2}+4ai-2ab+4i^{2}-4ib+b^{2})}
  

  
    
      
        Var
        ⁡
        (
        X
        )
        =
        
          
            1
            
              4
              n
            
          
        
        
          [
          
            
              ∑
              
                i
                =
                0
              
              
                n
                −
                1
              
            
            (
            
              a
              
                2
              
            
            −
            2
            a
            b
            +
            
              b
              
                2
              
            
            )
            +
            
              ∑
              
                i
                =
                0
              
              
                n
                −
                1
              
            
            (
            4
            a
            i
            −
            4
            i
            b
            )
            +
            
              ∑
              
                i
                =
                0
              
              
                n
                −
                1
              
            
            4
            
              i
              
                2
              
            
          
          ]
        
      
    
    {\displaystyle \operatorname {Var} (X)={1 \over 4n}\left[\sum _{i=0}^{n-1}(a^{2}-2ab+b^{2})+\sum _{i=0}^{n-1}(4ai-4ib)+\sum _{i=0}^{n-1}4i^{2}\right]}
  

  
    
      
        Var
        ⁡
        (
        X
        )
        =
        
          
            1
            
              4
              n
            
          
        
        
          [
          
            n
            (
            
              a
              
                2
              
            
            −
            a
            b
            +
            
              b
              
                2
              
            
            )
            +
            4
            (
            a
            −
            b
            )
            
              ∑
              
                i
                =
                0
              
              
                n
                −
                1
              
            
            i
            +
            4
            
              ∑
              
                i
                =
                0
              
              
                n
                −
                1
              
            
            
              i
              
                2
              
            
          
          ]
        
      
    
    {\displaystyle \operatorname {Var} (X)={1 \over 4n}\left[n(a^{2}-ab+b^{2})+4(a-b)\sum _{i=0}^{n-1}i+4\sum _{i=0}^{n-1}i^{2}\right]}
  Remember that in 
  
    
      
        
          ∑
          
            i
            =
            0
          
          
            m
          
        
        
          i
          
            2
          
        
        =
        m
        (
        m
        +
        1
        )
        (
        2
        m
        +
        1
        )
        
          /
        
        6
      
    
    {\displaystyle \sum _{i=0}^{m}i^{2}=m(m+1)(2m+1)/6}
  

  
    
      
        Var
        ⁡
        (
        X
        )
        =
        
          
            1
            
              4
              n
            
          
        
        
          [
          
            n
            (
            b
            −
            a
            
              )
              
                2
              
            
            +
            4
            (
            a
            −
            b
            )
            [
            (
            n
            −
            1
            )
            n
            
              /
            
            2
            ]
            +
            4
            [
            (
            n
            −
            1
            )
            n
            (
            2
            n
            −
            1
            )
            
              /
            
            6
            ]
          
          ]
        
      
    
    {\displaystyle \operatorname {Var} (X)={1 \over 4n}\left[n(b-a)^{2}+4(a-b)[(n-1)n/2]+4[(n-1)n(2n-1)/6]\right]}
  

  
    
      
        Var
        ⁡
        (
        X
        )
        =
        
          
            1
            
              4
              n
            
          
        
        
          [
          
            n
            (
            n
            −
            1
            
              )
              
                2
              
            
            −
            2
            (
            n
            −
            1
            )
            (
            n
            −
            1
            )
            n
            +
            2
            (
            n
            −
            1
            )
            n
            (
            2
            n
            −
            1
            )
            
              /
            
            3
          
          ]
        
      
    
    {\displaystyle \operatorname {Var} (X)={1 \over 4n}\left[n(n-1)^{2}-2(n-1)(n-1)n+2(n-1)n(2n-1)/3\right]}
  

  
    
      
        Var
        ⁡
        (
        X
        )
        =
        
          
            1
            4
          
        
        
          [
          
            −
            (
            n
            −
            1
            
              )
              
                2
              
            
            +
            2
            (
            n
            −
            1
            )
            (
            2
            n
            −
            1
            )
            
              /
            
            3
          
          ]
        
      
    
    {\displaystyle \operatorname {Var} (X)={1 \over 4}\left[-(n-1)^{2}+2(n-1)(2n-1)/3\right]}
  

  
    
      
        Var
        ⁡
        (
        X
        )
        =
        
          
            1
            12
          
        
        
          [
          
            −
            3
            (
            n
            −
            1
            
              )
              
                2
              
            
            +
            2
            (
            n
            −
            1
            )
            (
            2
            n
            −
            1
            )
          
          ]
        
      
    
    {\displaystyle \operatorname {Var} (X)={1 \over 12}\left[-3(n-1)^{2}+2(n-1)(2n-1)\right]}
  

  
    
      
        Var
        ⁡
        (
        X
        )
        =
        
          
            1
            12
          
        
        
          [
          
            −
            3
            (
            
              n
              
                2
              
            
            −
            2
            n
            +
            1
            )
            +
            2
            (
            2
            
              n
              
                2
              
            
            −
            3
            n
            +
            1
            )
          
          ]
        
      
    
    {\displaystyle \operatorname {Var} (X)={1 \over 12}\left[-3(n^{2}-2n+1)+2(2n^{2}-3n+1)\right]}
  

  
    
      
        Var
        ⁡
        (
        X
        )
        =
        
          
            
              
                n
                
                  2
                
              
              −
              1
            
            12
          
        
      
    
    {\displaystyle \operatorname {Var} (X)={n^{2}-1 \over 12}}