class: inverse background-image: url(https://images.unsplash.com/photo-1572291720677-d8d28ac52a5b?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1556&q=80) background-size: cover

{ggxmean}





















Photo credit: Hans Veth

# This is the recommended set up for flipbooks
# you might think about setting cache to TRUE as you gain practice --- building flipbooks from scratch can be time consuming
knitr::opts_chunk$set(fig.width = 8, message = FALSE, warning = FALSE, comment = "", cache = F)
library(flipbookr)
library(tidyverse)

class: inverse, center, middle

viz the mean and conditional means


r chunk_reveal("vizthemean1d", break_type = "user")

library(tidyverse)
library(ggxmean)
palmerpenguins::penguins %>% 
  drop_na() %>% 
  ggplot() +
  aes(x = bill_length_mm) +
  geom_rug(alpha = .3) +
  geom_histogram(alpha = .4) + #BREAK
  geom_x_mean() + #BREAK
  aes(color = species) + #BREAK
  aes(fill = species) + #BREAK
  facet_grid(rows = vars(species)) + #BREAK
  facet_grid(rows = vars(species, sex)) + #BREAK
  geom_rug(alpha = .6) + #BREAK
  geom_x_quantile(quantile = .5,
                  linetype = "dashed") + #BREAK
  geom_x_percentile(percentile = 75,
                    color = "goldenrod") + #BREAK
  geom_x_median(color = "black") + #BREAK
  geom_x_quantile(quantile = .25, linetype = "dashed") + #BREAK
  geom_boxplot(y = 0,
               width = 3,
               fill = "white",
               color = "black") #BREAK

class: inverse, center, middle

and the mean of y


r chunk_reveal("vizthemean2d", break_type = "user")

library(ggxmean)
palmerpenguins::penguins %>% 
  drop_na() %>% 
  ggplot() +
  aes(x = bill_length_mm) +
  aes(y = flipper_length_mm) +
  geom_point() + #BREAK
  geom_x_mean() + #BREAK
  geom_y_mean() + #BREAK
  aes(color = species) + #BREAK
  facet_wrap(facets = vars(species)) + #BREAK
  facet_grid(cols = vars(species),
             rows = vars(sex)) #BREAK

r chunk_reveal("ttest")

set.seed(1456)
ggplot(starwars %>% sample_n(30)) +
  aes(x = height) +
  geom_rug() +
  geom_dotplot() +
  geom_x_mean(linetype = "dashed") +
  ggxmean:::geom_tdist(
    height = 50, 
    alpha = .5
    ) + 
  ggxmean:::geom_ttestconf(
    size = 2, 
    conf.level = .9,
    y = -.05
    ) 

r chunk_reveal("multittest", break_type = 20)

ggplot(tibble(height = runif(20))) +
  aes(x = height) +
  geom_rug() +
  geom_x_mean(
    linetype = "dashed",
    color = "mediumvioletred",
    size = 1.5
    ) +
  ggxmean:::geom_tdist(
    height = 1, 
    alpha = .5, 
    fill = "mediumvioletred"
    ) +
    ggxmean:::geom_ttestconf(
    size = 2, 
    color = "mediumvioletred", 
    alpha = .75, 
    y = -.01, 
    conf.level = .90) +
  scale_x_continuous(limits = c(0, 1)) +
  scale_y_continuous(limits = c(0, 1.7))

class: inverse, center, middle

OLS


r chunk_reveal("ols", break_type = "user", widths = c(1,1))

palmerpenguins::penguins %>% 
  filter(species == "Chinstrap" & sex == "male") %>% 
  ggplot() +
  aes(x = flipper_length_mm) +
  aes(y = body_mass_g) +
  geom_point() + #BREAK
  geom_lm() + #BREAK
  geom_rug(aes(y = NULL)) + #BREAK
  geom_x_line(alpha = .2,  
              linetype = "dotted") + #BREAK
  geom_lm_fitted(color = "blue", size = 2.5) + #BREAK
  geom_lm_residuals(color = "tomato3") + #BREAK
  geom_y_mean() + #BREAK
  geom_x_mean() + #BREAK
  geom_xy_means(size = 3, color = "lightpink4") + #BREAK
  geom_lm_formula() + #BREAK
  # plug and chug to calculate an 
  # expected value of y for a given x 
  annotate(geom = "point",  
           x = 208,  
           y = 40.3 * 208 - 4110,  
           size = 5, 
           shape = "diamond") + #BREAK
  ggxmean:::geom_lm_run(color = "violetred4") + #BREAK
  ggxmean:::geom_lm_rise(color = "violetred4") + #BREAK
  ggxmean:::geom_lm_run10(color = "chartreuse3") + #BREAK
  ggxmean:::geom_lm_rise10(color = "chartreuse3") + #BREAK
  ggxmean:::geom_lm_predictx(alpha = .2) + #BREAK
  ggxmean:::geom_lm_predicty(alpha = .2) + #BREAK
  ggxmean:::geom_lm_intercept() + #BREAK
  ggxmean:::geom_lm_interceptcoords(hjust = 0) #BREAK

class: inverse

Correlation

--

Don't worry about the overall importance of the problem;

-- work on it if it looks interesting.
-- I think there's a sufficient correlation between interest and importance.
-- - David Blackwell


r chunk_reveal("vizthecorrelation", break_type = "user")

library(ggxmean)
palmerpenguins::penguins %>% 
  mutate(id = row_number()) %>% 
  ggplot() + 
  aes(x = bill_length_mm) +
  aes(y = flipper_length_mm) + 
  geom_point() + 
  geom_x_mean() + #BREAK
  geom_y_mean() + #BREAK
  geom_y_line(alpha = .02) + #BREAK
  geom_x_line(alpha = .02) + #BREAK
  ggxmean:::geom_xdiff() + #BREAK
  ggxmean:::geom_ydiff() + #BREAK
  ggxmean:::geom_diffsmultiplied() + #BREAK
  ggxmean:::geom_x1sd() + #BREAK
  ggxmean:::geom_y1sd() + #BREAK
  ggxmean:::geom_rsq1(fill = "blue") + #BREAK
  ggxmean:::geom_xy1sd(fill = "green") + #BREAK
  ggxmean:::geom_xydiffsmean(alpha = 1,
                   fill = "plum3") + 
  ggxmean:::geom_corrlabel() + #BREAK
  geom_lm() + #BREAK
  facet_wrap(facet = vars(species)) #BREAK

r chunk_reveal("suprising")

cars %>% 
  ggplot() +
  aes(x = speed) +
  geom_rug() +
  geom_x_mean() + 
  geom_x_mean_label() +
  aes(y = dist) +
  geom_y_mean() + 
  geom_y_mean_label() +
  geom_point() 

```{css, eval = TRUE, echo = FALSE} .remark-code{line-height: 1.5; font-size: 80%}

@media print { .has-continuation { display: block; } }

code.r.hljs.remark-code{ position: relative; overflow-x: hidden; }

code.r.hljs.remark-code:hover{ overflow-x:visible; width: 500px; border-style: solid; } ```



EvaMaeRey/ggxmean documentation built on April 10, 2024, 6:32 p.m.