Skip to content

Instantly share code, notes, and snippets.

@alex23lemm
Last active August 29, 2015 14:26
Show Gist options
  • Save alex23lemm/b8b02fbcd04eb6fdca7d to your computer and use it in GitHub Desktop.
Save alex23lemm/b8b02fbcd04eb6fdca7d to your computer and use it in GitHub Desktop.
Compare LM outputs and visualize startprice variation acrocss biddable/sold-combinations
library(ggplot2)
library(dplyr)
library(readr)
ebay_train <- read.csv("./data/eBayiPadTrain.csv")
# Remove observations which cause trouble for later predictions
ebay_train <- ebay_train %>% filter(carrier != 'Other' | productline != 'iPad 5')
bid_sold_all <- ebay_train %>% select(biddable, startprice, condition, cellular
carrier, color, storage, productline)
# Do not select biddable because it was used for subetting already
b0_s1 <- ebay_train %>% filter(biddable == 0, sold == 1) %>%
select(startprice, condition, cellular, color, carrier
storage, productline)
# Do not select biddable because it was used for subetting already
b0s1_b0s1_b1s0 <- ebay_train %>% filter(biddable != 1, sold != 1) %>%
select(startprice, condition, cellular, color, carrier
storage, productline)
lm_all <- lm(startprice ~ ., data = bid_sold_all)
summary(lm_all)
lm_b0s1 <- lm(startprice ~ ., data = b0_s1)
summary(lm_b0s1)
lm_b0s1_b0s1_b1s0 <- lm(startprice ~ ., data = b0s1_b0s1_b1s0)
summary(lm_b0s1_b0s1_b1s0)
ebay_train$price_diff_all <- ebay_train$startprice - predict(lm_all,
newdata = ebay_train)
ebay_train$price_diff_b0s1 <- ebay_train$startprice - predict(lm_b0s1,
newdata = ebay_train)
ebay_train$price_diff_b0s1_b0s1_b1s0 <- ebay_train$startprice - predict(lm_b0s1_b0s1_b1s0,
newdata = ebay_train)
# Modify entries for plotting later
ebay_train$sold <- ifelse(ebay_train$sold == 0, 'not sold', 'sold')
ebay_train$biddable <- ifelse(ebay_train$biddable == 0, 'non-biddable', 'biddable')
qplot(productline, price_diff_all, data = ebay_train, geom = "boxplot",
facets = biddable ~ sold)
qplot(productline, price_diff_b0s1, data = ebay_train, geom = "boxplot",
facets = biddable ~ sold)
qplot(productline, price_diff_b0s1_b0s1_b1s0, data = ebay_train, geom = "boxplot",
facets = biddable ~ sold)
qplot(storage, price_diff_all, data = ebay_train, geom = "boxplot",
facets = biddable ~ sold)
qplot(storage, price_diff_b0s1, data = ebay_train, geom = "boxplot",
facets = biddable ~ sold)
qplot(storage, price_diff_b0s1_b0s1_b1s0, data = ebay_train, geom = "boxplot",
facets = biddable ~ sold)
qplot(condition, price_diff_all, data = ebay_train, geom = "boxplot",
facets = biddable ~ sold)
qplot(condition, price_diff_b0s1, data = ebay_train, geom = "boxplot",
facets = biddable ~ sold)
qplot(condition, price_diff_b0s1_b0s1_b1s0, data = ebay_train, geom = "boxplot",
facets = biddable ~ sold)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment