1 # Tor Censorship Detector
2 # Usage: R --slave < detect-censorship.R
4 # Read CSV file containing daily user number estimates.
5 direct <- read.csv("direct-users.csv")
7 # Start plotting everything to a single PDF (with multiple pages).
8 pdf("detect-censorship.pdf")
10 # Convert the column containing daily Iranian users to a time series
11 # object, starting on the 263th day of 2009 with a frequency of 365 days.
12 # We're probably off by a day or two, but this should be fine for now.
13 all <- ts(direct$ir, start = c(2009, 263), frequency = 365)
15 # Uncomment to print the time series values.
18 # Let's try our approach for the last 365 days to see if we detect any
19 # blocking in that time period. In the final version of this script, we'd
20 # only have a single run with i = 1.
22 idx <- length(direct$date) - i
24 # Convert the daily Iranian users until i days in the past to a time
26 x <- ts(direct$ir[1:idx], start = c(2009, 263), frequency = 365)
28 # Apply an ARIMA(1, 0, 1) model to the time series.
29 x.fit = arima(x, order = c(1, 0, 1))
31 # Predict 10 dates ahead.
32 x.fore=predict(x.fit, n.ahead=10)
34 # Calculate a lower bound. Here we use the predicted value minus three
36 L = x.fore$pred - 3*x.fore$se
38 # If the observed daily user number is lower than our predicted lower
39 # bound, plot the data and lower bound.
40 if (direct$ir[idx + 1] < L[1]) {
42 # Plot the full time series.
45 # Add a line for the ten predicted values.
46 lines(L, col = "red", lwd = 2)
50 # Close the PDF device.