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
# Defining lambda and n | |
lambda <- 220 | |
n <- 30 | |
# Calculating SEM | |
sem <- sqrt(lambda / n) |
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(gridExtra) | |
# Set the colours for the graphs | |
barfill <- "#4271AE" | |
barlines <- "#1F3552" | |
line1 <- "black" | |
line2 <- "#FF3721" | |
# Plotting histogram of sample of daily page views | |
g1 <- ggplot(data=as.data.frame(sample), aes(sample)) + |
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
# Generate the 95% confidence interval. | |
lci <- -1 * qt(c(.975), 78) | |
uci <- qt(c(.975), 78) |
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
use http://www.ats.ucla.edu/stat/stata/library/depress, clear | |
reshape long dep, i(subj) | |
rename _j time | |
drop pre |
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
# Load required packages | |
require(ggplot2); require(gridExtra) | |
# Set the colours for the graphs | |
barfill <- "#4271AE" | |
barlines <- "#1F3552" | |
line1 <- "black" | |
line2 <- "#FF3721" | |
# Plotting histogram of sample 1 |
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
av_peds_2 <- ddply(p.subset, c("date", "collapsed_sensors_2"), summarise, | |
n_peds = sum(Hourly_Counts)) | |
# Extract weekday versus weekend | |
av_peds_2$day <- weekdays(av_peds_2$date, abbreviate = FALSE) | |
av_peds_2$weekend <- ifelse((av_peds_2$day == "Saturday" | av_peds_2$day == "Sunday"), | |
"Weekend", "Weekday") | |
av_peds_2$weekend <- as.factor(av_peds_2$weekend) | |
# Extract time of day |
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
library(ggplot2); library(gridExtra) | |
g1 <- ggplot(data=mtcars, aes(x=wt, y=mpg)) + | |
geom_point(alpha = 0.7, colour = "#0971B2") + | |
ylab("Miles per gallon") + | |
ylim(10, 35) + | |
xlab("Weight (`000 lbs)") + | |
ggtitle("Untransformed Weight") + | |
geom_vline(xintercept = 0) + | |
theme_bw() |
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
mtcars$am.f <- as.factor(mtcars$am); levels(mtcars$am.f) <- c("Automatic", "Manual") | |
mtcars$cyl.f <- as.factor(mtcars$cyl); levels(mtcars$cyl.f) <- c("4 cyl", "6 cyl", "8 cyl") | |
mtcars$vs.f <- as.factor(mtcars$vs); levels(mtcars$vs.f) <- c("V engine", "Straight engine") | |
mtcars$gear.f <- as.factor(mtcars$gear); levels(mtcars$gear.f) <- c("3 gears", "4 gears", "5 gears") | |
mtcars$carb.f <- as.factor(mtcars$carb) |
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
def name_print(cat): | |
'''Print the name of the cat.''' | |
print "The cat is called %s." % cat.name | |
name_print(felix) |
OlderNewer