Forked from t-redactyl/comparing_small_and_larger_samples.R
Created
September 27, 2017 05:32
-
-
Save chaityacshah/34f2b57e508c6ead1a41ccbf399c6a76 to your computer and use it in GitHub Desktop.
Code associated with blog post: http://t-redactyl.github.io/blog/2015/09/representative-sampling.html
This file contains 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
set.seed(567) | |
# Sample of 30 (29 from the Poisson distribution and an outlier of 260) | |
sample1 <- c(rpois(29, lambda = 220), 260) | |
# Sample of 10 (9 from the Poisson distribution and an outlier of 260) | |
sample2 <- c(rpois(9, lambda = 220), 260) |
This file contains 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
# Simulate some data for 2014, with mean page views of 220 per day. | |
days <- seq(as.Date("2014/1/1"), as.Date("2014/12/31"), "days") | |
page.views <- rpois(365, lambda = 220) | |
views <- data.frame(days, page.views) | |
# Generate post Christmas sale peak period (January 1-10) with mean page views of 400 per day. | |
views$page.views[views$days >= "2014/01/01" & views$days <= "2014/01/10"] <- rpois(10, lambda = 400) | |
# Generate Easter peak period (April 1-21) with mean page views of 350 per day. | |
views$page.views[views$days >= "2014/04/01" & views$days <= "2014/04/21"] <- rpois(21, lambda = 350) | |
# Generate Black Friday and Christmas peak periods (November 28-December 31) mean page views of 500 per day. | |
views$page.views[views$days >= "2014/11/28" & views$days <= "2014/12/31"] <- rpois(34, lambda = 500) |
This file contains 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
require(ggplot2); require(knitr); require(magrittr) | |
opts_chunk$set(fig.path='/figure/',echo=FALSE, warning=FALSE, message=FALSE) | |
qplot(days, page.views, data = views, geom = "line") %>% | |
add(geom_line(colour = "#4271AE")) %>% | |
add(ggtitle('Website Page Views in 2014')) %>% | |
add(xlab('')) %>% | |
add(ylab('Daily page views')) %>% | |
add(geom_hline(yintercept=220, linetype="dashed")) %>% | |
add(theme_bw()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment