Chapter 12 Popularity Contest
In the previous chapter we found that arrival times of tweets on a given topic seem to fit a Poisson distribution. Armed with that knowledge we can now develop a test to compare two different Twitter topics to see which one is more popular (or at least which one has a higher posting rate). We will use our knowledge of sampling distributions to understand the logic of the test.
Sources.
Barplots
Poisson Distribution
R Functions Used in this Chapter
-
as.integer() - Coerces another data type to integer if possible
-
barplot2() - Creates a bar graph
-
c() - Concatenates items to make a list
-
diff() - Calculates time difference on neighboring cases
-
EnsurePackage() - Custom function, install() and require() package
-
for() - Creates a loop, repeating execution of code
-
hist() - Creates a frequency histogram
-
mean() - Calculates the arithmetic mean
-
order() - Provides a list of indices reflecting a new sort order
-
plot() - Begins an X-Y plot
-
points() - Adds points to a plot started with plot()
-
poisson.test() - Confidence intervals for poisson events or ratios
-
ppois() - Returns a cumulative probability for particular threshold
-
qpois() - Does the inverse of ppois(): Probability into threshold
-
rpois() - Generates random numbers fitting a Poisson distribution
-
sum() - Adds together a list of numbers
-
TweetFrame() - Custom procedure yielding a dataset of tweets
-
var() - Calculates variance of a list of numbers
R Script - Create Vector of Probabilities From Delay Times
# Like ArrivalProbability, but works with unsorted list
# of delay times
DelayProbability<-function(delays, increment, max)
{
# Initialize an empty vector
plist <- NULL
# Probability is defined over the size of this sample
# of arrival times
delayLen <- length(delays)
# May not be necessary, but checks for input mistake
if (increment>max) {return(NULL)}
for (i in seq(increment, max, by=increment))
{
# logical test <=i provides list of TRUEs and FALSEs
# of length = timeLen, then sum() counts the TRUEs
plist<-c(plist,(sum(delays<=i)/delayLen))
}
return(plist)
}
