Amherst-Statistics / IS5inR

Companion materials for De Veaux, Velleman, and Bock's "Intro Stats" 5th edition
MIT License
0 stars 3 forks source link

Parallel Slopes Model #21

Closed mchien20 closed 6 years ago

mchien20 commented 6 years ago

In Chapter 9, page 294, there's a visualization with parallel slopes and one that isn't. gf_lm() automatically adds the interaction into the model. I looked at Bonnie's code for parallel slopes, but since there are 8 levels, I am looking for a simpler way to do it. Here's the model: library(readr) library(mosaic) library(janitor) Diamonds <- read_csv("http://nhorton.people.amherst.edu/is5/data/Diamonds.csv") %>% clean_names() diamondlm <- lm(sqrt(price) ~ carat_size + color, data = Diamonds) msummary(diamondlm)

mchien20 commented 6 years ago

I used broom in this commit: https://github.com/Amherst-Statistics/IS5inR/commit/de258ed94866de545c0d297e2d839a2936de21e6 However, I can't seem to get the parallel slopes to work.

nicholasjhorton commented 6 years ago

@shukryzablah can you please check in on this front?

shukryzablah commented 6 years ago

Is this what we want?:

library(readr)
library(mosaic)
library(janitor)
library(broom)
Diamonds <- read_csv(
  "http://nhorton.people.amherst.edu/is5/data/Diamonds.csv"
  ) %>%
  clean_names()
diamondlm <- lm(sqrt(price) ~ carat_size + color, data = Diamonds)

augmentedMod <- augment(diamondlm)

gf_point(sqrt.price. ~ carat_size, data = augmentedMod, color = ~ color) %>%
  gf_line(.fitted ~ carat_size)

Created on 2018-07-06 by the reprex package (v0.2.0).

mchien20 commented 6 years ago

https://github.com/Amherst-Statistics/IS5inR/commit/7f804358e45856e9367c6302d91fa8f2bdb0cd14