Bernoulli versus binomial distribution

Generalized Linear Models in R

Richard Erickson

Instructor

Foundation of GLM

  • Binomial and Bernoulli foundation of logistic regression
  • Closely related to data input
Generalized Linear Models in R

Bernoulli distribution

  • Binary outcome: e.g., single coin flip
  • Expected probability

    • $k$ outcomes
    • with $p$ probability
    • $f(k,p) = p^k(1-p)^{1-k}$
  • Example of flipping 1 coin

Example of coin flip probability

Generalized Linear Models in R

Binomial distribution

  • Discrete outcome: e.g., flipping multiple coins
  • Expected probability

    • $n$ trials
    • $k$ outcomes
    • with $p$ probability
    • $f(k,n,p) = {n\choose k}p^k(1-p)^{n-k}$
  • Flipping 4 coins at once

Example of coin flip probability

Generalized Linear Models in R

Simulating in R

rbinom(n = , size = , p = )
  • n: Number of random numbers to generate
  • size: Number of trials
  • p: Probability of "success"
  • size = 1: Bernoulli
Generalized Linear Models in R

GLM inputs options

  • Long format (Bernoulli format)

    • y = c(0,1,...)
    • Allows for variables for each observation
  • Wide format (Binomial format)

    • Matrix: cbind(success, failure)
    • Proportion of success: y = c(0.3, 0.1,...) with weights = c(1, 3, 2...)
    • Looks at "groups" rather than individuals
Generalized Linear Models in R

Example

Long data:

  • One entry per row
  • Predictors for each response
response treatment  length
    dead         a 3.471006
    dead         a 3.704329
   alive         a 2.043244
   alive         b 1.667343

Wide data:

  • One group per row
  • Predictors for each group
group dead alive Total groupTemp
    a   12     2    14      high
    b    3    11    14       low
Generalized Linear Models in R

Which input method to use?

  • What is your raw data structure? Long or wide?
  • What variables do I have? Individual or group?
  • Do want to make inferences about groups or individuals?
Generalized Linear Models in R

Let's practice!

Generalized Linear Models in R

Preparing Video For Download...