Last active
August 28, 2017 15:58
-
-
Save pgilad/071bfb6c8ed35a3d685121512363476f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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