-
Notifications
You must be signed in to change notification settings - Fork 0
/
explo.R
38 lines (30 loc) · 1.21 KB
/
explo.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
setwd("~/uni/statml/project/")
source("setup.R")
db=db %>% select(c(iyear,success,longitude,latitude, suicide, nperps, claimed, nkill, nwound))
timedy=data.frame() # db %>% filter(F)
for (y in c(1970:1992,1994:2017)) {
sel= db %>% filter(iyear==y)
#sel=sel%>% mutate_each(funs(function(x) x/nrow(sel)), c("success","suicide", "claimed"))
#sel[,c("success","suicide", "claimed")]=sel[,c("success","suicide", "claimed")]/length(sel)
rmsloc=rms(sample(na.omit(sel$longitude), 400)-sample(na.omit(sel$longitude), 400))+rms(sample(na.omit(sel$latitude), 400)-sample(na.omit(sel$latitude), 400))
sel=sel %>% select(-c(longitude,latitude))
v=as.data.frame(t( apply(sel, 2, function(x) sum(x, na.rm = T))))
v[,c("success","suicide", "claimed")]=v[,c("success","suicide", "claimed")]/nrow(sel)
v=cbind(v,rmsloc)
v$iyear=y
if (nrow(timedy)==0) {
timedy<<-v
}
else {
timedy<<-rbind(timedy, v )
}
}
### stolen
normalit<-function(m){
(m - min(m))/(max(m)-min(m))
}
timedy=timedy %>% mutate_each(funs(normalit), nkill, nwound, nperps, rmsloc)
pdf("doc/plots/time.pdf", width = 6, height = 3)
ggplot(melt(timedy%>% select(-nperps,-nwound) ,id="iyear") , aes(x=iyear, y=value, colour=variable))+
geom_line()
dev.off()