<div class="twitter-share"><a target="_blank" class="twitter-share-button" rel="nofollow" href="https://twitter.com/intent/tweet?url=https%3A%2F%2Ffronkonstin.com%2F2017%2F02%2F21%2Fwho-is-alan-turing%2F&via=aschinchon">Tweet</a></div>
<blockquote><p>This government is committed to introducing posthumous pardons for people with certain historical sexual offence convictions who would be innocent of any crime now (British Government Spokesperson, September 2016)</p>
</blockquote>
<p>Last September, the British government announced its intention to pursue what has become known as the <em>Alan Turing law</em>, offering exoneration to the tens of thousands of gay men convicted of historic charges.  The law was finally unveiled on 20 October 2016.</p>
<p>This plot shows the daily views of the Alan Turing’s wikipedia page during the last 365 days:</p>
<p><br>
<iframe height="500" width="100%" src="https://fronkonstin.com/wp-content/uploads/2017/02/turing1.html"></iframe><br>
<br>
There are three huge peaks in May 27th, July 30th, and October 29th that can be easily detected using <a target="_blank" rel="nofollow" href="https://github.com/twitter/AnomalyDetection">AnomalyDetection package</a>:</p>
<p><img sizes="(max-width: 604px) 100vw, 604px" data-image-description="" data-orig-file="https://i2.wp.com/fronkonstin.com/wp-content/uploads/2017/02/turing2.jpg?fit=1024%2C640&amp;ssl=1" data-orig-size="1024,640" data-image-title="turing2" class="wp-image-3900" data-comments-opened="1" data-recalc-dims="1" data-attachment-id="3900" data-permalink="https://fronkonstin.com/2017/02/21/who-is-alan-turing/turing2/" alt="" data-medium-file="https://i2.wp.com/fronkonstin.com/wp-content/uploads/2017/02/turing2.jpg?fit=300%2C188&amp;ssl=1" data-large-file="https://i2.wp.com/fronkonstin.com/wp-content/uploads/2017/02/turing2.jpg?fit=604%2C378&amp;ssl=1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="https://i2.wp.com/fronkonstin.com/wp-content/uploads/2017/02/turing2.jpg?resize=604%2C378&ssl=1"><br>
After substituting these anomalies by a simple linear imputation, it is clear that the time series has suffered a significant impact since the last days of September:</p>
<p><br>
<iframe height="500" width="100%" src="https://fronkonstin.com/wp-content/uploads/2017/02/turing3.html"></iframe><br>
<br>
To estimate the amount of incremental views since September 28th (this is the date I have chosen as starting point) I use <a target="_blank" rel="nofollow" href="https://google.github.io/CausalImpact/CausalImpact.html">CausalImpact package</a>:</p>
<p><img sizes="(max-width: 604px) 100vw, 604px" data-image-description="" data-orig-file="https://i0.wp.com/fronkonstin.com/wp-content/uploads/2017/02/turing4.jpg?fit=1024%2C640&amp;ssl=1" data-orig-size="1024,640" data-image-title="turing4" data-comments-opened="1" class="wp-image-3901" data-recalc-dims="1" data-attachment-id="3901" data-permalink="https://fronkonstin.com/2017/02/21/who-is-alan-turing/turing4/" alt="" data-medium-file="https://i0.wp.com/fronkonstin.com/wp-content/uploads/2017/02/turing4.jpg?fit=300%2C188&amp;ssl=1" data-large-file="https://i0.wp.com/fronkonstin.com/wp-content/uploads/2017/02/turing4.jpg?fit=604%2C378&amp;ssl=1" data-image-meta="{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}" src="https://i0.wp.com/fronkonstin.com/wp-content/uploads/2017/02/turing4.jpg?resize=604%2C378&ssl=1"><br>
Last plot shows the accumulated effect. After 141 days, there have been around 1 million of incremental views to the Alan Turing’s wikipedia page (more than 7.000 per day) and it does not seem <em>ephemeral</em>.</p>
<p>Alan Turing has won another battle, this time posthumous. And thanks to it, there is a lot of people that have discovered his amazing legacy: long life to Alan Turing.</p>
<p>This is the code I wrote to do the experiment:</p>
<pre>
library(httr)
library(jsonlite)
library(stringr)
library(xts)
library(highcharter)
library(AnomalyDetection)
library(imputeTS)
library(CausalImpact)
library(dplyr)

# Views last 365 days
(Sys.Date()-365) %>% str_replace_all(&quot;[[:punct:]]&quot;, &quot;&quot;) %>% substr(1,8) -> date_ini
Sys.time()       %>% str_replace_all(&quot;[[:punct:]]&quot;, &quot;&quot;) %>% substr(1,8) -> date_fin
url=&quot;https://wikimedia.org/api/rest_v1/metrics/pageviews/per-article/en.wikipedia/all-access/all-agents/Alan%20Turing/daily&quot;
paste(url, date_ini, date_fin, sep=&quot;/&quot;) %>% 
  GET  %>% 
  content(&quot;text&quot;) %>% 
  fromJSON %>% 
  .[[1]] -> wikistats

# To prepare dataset for highcharter
wikistats %>% 
  mutate(day=str_sub(timestamp, start = 1, end = 8)) %>% 
  mutate(day=as.POSIXct(day, format=&quot;%Y%m%d&quot;, tz=&quot;UTC&quot;)) -> wikistats

# Highcharts viz
rownames(wikistats)=wikistats$day
wikistats %>% select(views) %>% as.xts  %>% hchart

# Anomaly detection
wikistats %>% select(day, views) -> tsdf
tsdf %>%  
  AnomalyDetectionTs(max_anoms=0.01, direction='both', plot=TRUE)->res
res$plot

# Imputation of anomalies
tsdf[tsdf$day %in% as.POSIXct(res$anoms$timestamp, format=&quot;%Y-%m-%d&quot;, tz=&quot;UTC&quot;),&quot;views&quot;]&lt;-NA 
ts(tsdf$views, frequency = 365) %>% 
  na.interpolation() %>% 
  xts(order.by=wikistats$day) -> tscleaned
tscleaned %>% hchart

# Causal Impact from September 28th
x=sum(index(tscleaned)&lt;&quot;2016-09-28 UTC&quot;)
impact &lt;- CausalImpact(data = tscleaned %>% as.numeric, 
                       pre.period = c(1,x),
                       post.period = c(x+1,length(tscleaned)), 
                       model.args = list(niter = 5000, nseasons = 7),
                       alpha = 0.05)
plot(impact)
</pre>
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/zR2KFPSzIvs">