Skip to content

Instantly share code, notes, and snippets.

@paulhendricks
Last active November 7, 2016 17:06
Show Gist options
  • Select an option

  • Save paulhendricks/be04b2c9f07591496491cccd733641a3 to your computer and use it in GitHub Desktop.

Select an option

Save paulhendricks/be04b2c9f07591496491cccd733641a3 to your computer and use it in GitHub Desktop.
n <- 10000
alpha <- rnorm(n, 20, 5) # Customers spend on average $20 per transaction
plot(density(alpha))
b <- 10 # Customers who are petite spend on average $10 more per transaction
petite <- rbinom(n, size = 1, prob = 0.25) # Let's say 25% of customers are petite
eps <- rnorm(n, 0, 5) # Add some error
plot(density(eps))
y_true <- alpha + b * petite + eps
plot(density(y_true))
y_true[y_true < 0] <- 0
plot(density(y_true))
summary(glm(y_true ~ petite))
y_true_binary <- 1 * (y_true > 40)
summary(glm(y_true_binary ~ petite, family = binomial))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment