2024-06-08

Population Mean

\[\mu = \frac{\sum X_N}{N}\]

  • \(\mu\), or “mu,” represents the population mean or average
  • \(\sum X_N\) represents the sum of the entire population.
  • \(N\) represents size of the population.

Sample Mean

\[\bar{x}= \frac{\sum x_n}{n}\]

  • \(\bar{x}\), or “x bar,” represents the sample mean or average.
  • \(\sum x_n\) represents the sum of \(n\) observations.
  • \(n\) represents the size of the sample.

Top 25 Counties by Black Population

Warning in geom_hline(yintercept = oh_mean$popblack, width = 2, color =
"blue"): Ignoring unknown parameters: `width`

Top 25 Counties by Total Population vs White Population

All Populations

Plotly Code

fig <- plot_ly(
  data = oh_demo
  ,x = ~poptotal
  ,y = ~county
  ,type = 'bar'
  ,name = 'Total Population'
  ,orientation = 'h'
) %>% 
  add_trace(
    x = ~popwhite
    ,name = 'White Population'
  ) %>% 
  add_trace(
    x = ~popblack
    ,name = "Black Population"
  ) %>% 
  add_trace(
    x = ~popallother
    ,name = 'Other Populations'
  ) %>% 
  layout(
    title = 'Population by County with Mean Lines'
    ,xaxis = list(title = 'Count')
    ,yaxis = list(
      title = 'County'
      ,categoryorder = 'total ascending'
                 )
    ,barmode = 'group'
    ,shapes = list(
      list( # Total Population Line
        type = 'line'
        ,y0 = 0
        ,y1 = 1
        ,yref = 'paper'
        ,x0 = oh_mean$poptotal
        ,x1 = oh_mean$poptotal
        ,line = list(
          color = 'blue'
        )
      )
      ,list( # Total Population Line
        type = 'line'
        ,y0 = 0
        ,y1 = 1
        ,yref = 'paper'
        ,x0 = oh_mean$popwhite
        ,x1 = oh_mean$popwhite
        ,line = list(
          color = 'orange'
        )
      )
      ,list( # Total Population Line
        type = 'line'
        ,y0 = 0
        ,y1 = 1
        ,yref = 'paper'
        ,x0 = oh_mean$popblack
        ,x1 = oh_mean$popblack
        ,line = list(
          color = 'green'
        )
      )
      ,list( # Total Population Line
        type = 'line'
        ,y0 = 0
        ,y1 = 1
        ,yref = 'paper'
        ,x0 = oh_mean$popallother
        ,x1 = oh_mean$popallother
        ,line = list(
          color = 'red'
        )
      )
    )
  )

Mean vs Median

  • Median is the value at the 50% mark.
  • Mean is sensitive to outliers.
  • Median is not sensitive to outliers.