Skip to content

Instantly share code, notes, and snippets.

@pgilad
Last active August 28, 2017 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pgilad/071bfb6c8ed35a3d685121512363476f to your computer and use it in GitHub Desktop.
Save pgilad/071bfb6c8ed35a3d685121512363476f to your computer and use it in GitHub Desktop.
library(ggplot2)
library(MASS)
setwd('~/Downloads/jtls_and_more/')
jtl <- read_csv("~/Downloads/jtls_and_more/sample.jtl.csv")
df <- subset(jtl, jtl$lb == 'HomePage_01')
ggplot(jtl, aes(t)) +
facet_wrap( ~ lb, ncol = 3) +
geom_histogram(bins = 75) +
xlim(0, 1000)
# Fit parameters (to avoid errors, set lower bounds to zero)
fit.params <- fitdistr(jtl$t, "gamma", lower = c(0, 0))
ggplot(data = data, aes(x = x, y = y)) +
geom_point(size = 3) +
geom_line(aes(
x = data$x,
y = dgamma(data$x, fit.params$estimate["shape"], fit.params$estimate["rate"])
), color = "red", size = 1) +
theme_classic()
library(ggplot2)
library(MASS)
# Generate gamma rvs
x <- rgamma(100000, shape = 2, rate = 0.2)
den <- density(x)
data <- data.frame(x = den$x, y = den$y)
# Plot density as points
ggplot(data = data, aes(x = x, y = y)) +
geom_point(size = 3) +
theme_classic()
# Fit parameters (to avoid errors, set lower bounds to zero)
fit.params <- fitdistr(x, "gamma", lower = c(0, 0))
# Plot using density points
ggplot(data = data, aes(x = x, y = y)) +
geom_point(size = 3) +
geom_line(aes(
x = data$x,
y = dgamma(data$x, fit.params$estimate["shape"], fit.params$estimate["rate"])
), color = "red", size = 1) +
theme_classic()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment