-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.Rhistory
204 lines (204 loc) · 9.64 KB
/
.Rhistory
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
##############################################################################
library(reshape2)
library(data.table)
library(foreach)
setwd( "C:/Users/jmaburto/Documents/GitHub/Lifespan-variation-in-Eastern-Europe")
load("Data/HMD_Data.RData")
source("R/Functions.R")
Eastern_HMDL <- HMDL[HMDL$PopName %in% Country.HMD.vec & HMDL$Year >= 1960,]
Eastern_HMDL$Country <- Country.name.vec[Eastern_HMDL$PopName]
Eastern_HMDL$Sex <- as.factor(Eastern_HMDL$Sex)
levels(Eastern_HMDL$Sex) <- Sexes
Eastern_HMDL <- Eastern_HMDL[with(Eastern_HMDL,order(Country,Sex,Year,Age)),]
gdata::keep(Eastern_HMDL,sure=T)
source("R/Functions.R")
library(data.table)
library(reshape2)
library(latticeExtra)
library(ggplot2)
library(ggthemes)
setwd( "C:/Users/jmaburto/Documents/GitHub/Lifespan-variation-in-Eastern-Europe")
setwd( "C:/Users/jmabu/OneDrive - Nexus365/GitHub/Lifespan-variation-in-Eastern-Europe-2017/")
load("Data/HMD_Data.RData")
source("R/Functions.R")
Eastern_HMDL <- HMDL[HMDL$PopName %in% Country.HMD.vec & HMDL$Year >= 1960,]
Eastern_HMDL$Country <- Country.name.vec[Eastern_HMDL$PopName]
Eastern_HMDL$Sex <- as.factor(Eastern_HMDL$Sex)
levels(Eastern_HMDL$Sex) <- Sexes
ex.m <- ggplot(Eastern_HMDL[Eastern_HMDL$Age == 0 & Eastern_HMDL$Sex=='Male'], aes(Year, ex,colour=Country)) +
ggtitle( expression(paste('Life expectancy (',e[0],')')) , subtitle = 'Males')+
annotate('rect', xmin=1987, xmax=1989, ymin=-Inf, ymax=Inf,
alpha=0.2,fill="red")+
geom_line(aes(group = Country,size= Country),show.legend = F) +
scale_size_manual(values =lwd.fig.F1b,guide = FALSE)+
scale_x_continuous('Year', expand = c(0, 0)) +
scale_y_continuous('Years', limits = c(55,80)) +
theme_fivethirtyeight(base_size = 18)+
geom_vline(aes(xintercept=1991.8),show.legend = F,linetype=2,lwd=1.5, colour="blue")+
scale_colour_manual('Country', values = col.fig.F1b) +
theme(text = element_text(size=18),legend.key.size = unit(.4, "in"),axis.title = element_text(),
rect = element_rect(fill = 'white',
linetype = 0, colour = NA),
legend.position="bottom")
ex.m
ex.f <- ggplot(Eastern_HMDL[Eastern_HMDL$Age == 0 & Eastern_HMDL$Sex=='Female'], aes(Year, ex,colour=Country)) +
ggtitle(expression(paste('Life expectancy (',e[0],')')), subtitle = 'Females')+
annotate('rect', xmin=1987, xmax=1989, ymin=-Inf, ymax=Inf,
alpha=0.2,fill="red")+
geom_line(aes(group = Country,size= Country),show.legend = F) +
scale_size_manual(values =lwd.fig.F1b,guide = FALSE)+
scale_x_continuous('Year', expand = c(0, 0)) +
scale_y_continuous('Years', limits = c(68,85)) +
theme_fivethirtyeight(base_size = 18)+
geom_vline(aes(xintercept=1991.8),show.legend = F,linetype=2,lwd=1.5, colour="blue")+
scale_colour_manual('Country', values = col.fig.F1b) +
theme(text = element_text(size=18),legend.key.size = unit(.4, "in"),axis.title = element_text(),
rect = element_rect(fill = 'white',
linetype = 0, colour = NA),
legend.position="bottom")
ex.f
Eastern_HMDL$dx <-Eastern_HMDL$dx/100000
################ Calculate edagger
edagger <- Eastern_HMDL[,list(ed = e.dagger.LT(fx=dx,ex=ex,ax=ax)), by = list(Year,Sex,PopName,Country)]
ed.m <- ggplot(edagger[edagger$Sex=='Male'], aes(Year, ed,colour=Country)) +
ggtitle(expression(paste('Life disparity (',e^"\u2020",')')), subtitle = 'Males')+
annotate('rect', xmin=1987, xmax=1989, ymin=-Inf, ymax=Inf,
alpha=0.2,fill="red")+
geom_line(aes(group = Country,size= Country),show.legend = F) +
scale_size_manual(values =lwd.fig.F1b,guide = FALSE)+
scale_x_continuous('Year', expand = c(0, 0)) +
scale_y_continuous('Years', limits = c(11,19)) +
theme_fivethirtyeight(base_size = 18)+
geom_vline(aes(xintercept=1991.8),show.legend = F,linetype=2,lwd=1.5, colour="blue")+
scale_colour_manual('Country', values = col.fig.F1b) +
theme(text = element_text(size=18),legend.key.size = unit(.4, "in"),axis.title = element_text(),
rect = element_rect(fill = 'white',
linetype = 0, colour = NA),
legend.position="bottom")
ed.m
source("R/Functions.R")
load("Data/HMD_Data.RData")
source("R/Functions.R")
Eastern_HMDL <- HMDL[HMDL$PopName %in% Country.HMD.vec & HMDL$Year >= 1960,]
Eastern_HMDL$Country <- Country.name.vec[Eastern_HMDL$PopName]
Eastern_HMDL$Sex <- as.factor(Eastern_HMDL$Sex)
levels(Eastern_HMDL$Sex) <- Sexes
Eastern_HMDL$dx <-Eastern_HMDL$dx/100000
################ Calculate edagger
edagger <- Eastern_HMDL[,list(ed = e.dagger.LT(fx=dx,ex=ex,ax=ax)), by = list(Year,Sex,PopName,Country)]
ed.m <- ggplot(edagger[edagger$Sex=='Male'], aes(Year, ed,colour=Country)) +
ggtitle(expression(paste('Life disparity (',e^"\u2020",')')), subtitle = 'Males')+
annotate('rect', xmin=1987, xmax=1989, ymin=-Inf, ymax=Inf,
alpha=0.2,fill="red")+
geom_line(aes(group = Country,size= Country),show.legend = F) +
scale_size_manual(values =lwd.fig.F1b,guide = FALSE)+
scale_x_continuous('Year', expand = c(0, 0)) +
scale_y_continuous('Years', limits = c(11,19)) +
theme_fivethirtyeight(base_size = 18)+
geom_vline(aes(xintercept=1991.8),show.legend = F,linetype=2,lwd=1.5, colour="blue")+
scale_colour_manual('Country', values = col.fig.F1b) +
theme(text = element_text(size=18),legend.key.size = unit(.4, "in"),axis.title = element_text(),
rect = element_rect(fill = 'white',
linetype = 0, colour = NA),
legend.position="bottom")
ed.m
Eastern_HMDL
edagger
library(data.table)
library(reshape2)
library(latticeExtra)
library(ggplot2)
library(ggthemes)
setwd( "C:/Users/jmabu/OneDrive - Nexus365/GitHub/Lifespan-variation-in-Eastern-Europe-2017/")
load("Data/HMD_Data.RData")
source("R/Functions.R")
Eastern_HMDL <- HMDL[HMDL$PopName %in% Country.HMD.vec & HMDL$Year >= 1960,]
Eastern_HMDL$Country <- Country.name.vec[Eastern_HMDL$PopName]
Eastern_HMDL$Sex <- as.factor(Eastern_HMDL$Sex)
levels(Eastern_HMDL$Sex) <- Sexes
Eastern_HMDL$dx <-Eastern_HMDL$dx/100000
################ Calculate edagger
edagger <- Eastern_HMDL[,list(ed = e.dagger.LT(fx=dx,ex=ex,ax=ax)), by = list(Year,Sex,PopName,Country)]
edagger
ed.m <- ggplot(edagger[edagger$Sex=='Male'], aes(Year, ed,colour=Country)) +
ggtitle(expression(paste('Life disparity (',e^"\u2020",')')), subtitle = 'Males')+
annotate('rect', xmin=1987, xmax=1989, ymin=-Inf, ymax=Inf,
alpha=0.2,fill="red")+
geom_line(aes(group = Country,size= Country),show.legend = F) +
scale_size_manual(values =lwd.fig.F1b,guide = FALSE)+
scale_x_continuous('Year', expand = c(0, 0)) +
scale_y_continuous('Years', limits = c(11,19)) +
theme_fivethirtyeight(base_size = 18)+
geom_vline(aes(xintercept=1991.8),show.legend = F,linetype=2,lwd=1.5, colour="blue")+
scale_colour_manual('Country', values = col.fig.F1b) +
theme(text = element_text(size=18),legend.key.size = unit(.4, "in"),axis.title = element_text(),
rect = element_rect(fill = 'white',
linetype = 0, colour = NA),
legend.position="bottom")
ed.m
e.dagger.LT
e.dagger.LT <- function(fx,ex,ax=ax){
l <- length(ex)
v <- (sum(fx[-l]* (ex[-l] + ax[-l]*(ex[-1]-ex[-l]) )) + dx[l]ex[l])
return(v)
}
e.dagger.LT <- function(fx,ex,ax=ax){
l <- length(ex)
v <- (sum(fx[-l]* (ex[-l] + ax[-l]*(ex[-1]-ex[-l]) )) + dx[l]*ex[l])
return(v)
}
################ Calculate edagger
edagger <- Eastern_HMDL[,list(ed = e.dagger.LT(fx=dx,ex=ex,ax=ax)), by = list(Year,Sex,PopName,Country)]
ed.m <- ggplot(edagger[edagger$Sex=='Male'], aes(Year, ed,colour=Country)) +
ggtitle(expression(paste('Life disparity (',e^"\u2020",')')), subtitle = 'Males')+
annotate('rect', xmin=1987, xmax=1989, ymin=-Inf, ymax=Inf,
alpha=0.2,fill="red")+
geom_line(aes(group = Country,size= Country),show.legend = F) +
scale_size_manual(values =lwd.fig.F1b,guide = FALSE)+
scale_x_continuous('Year', expand = c(0, 0)) +
scale_y_continuous('Years', limits = c(11,19)) +
theme_fivethirtyeight(base_size = 18)+
geom_vline(aes(xintercept=1991.8),show.legend = F,linetype=2,lwd=1.5, colour="blue")+
scale_colour_manual('Country', values = col.fig.F1b) +
theme(text = element_text(size=18),legend.key.size = unit(.4, "in"),axis.title = element_text(),
rect = element_rect(fill = 'white',
linetype = 0, colour = NA),
legend.position="bottom")
ed.m
edagger
e.dagger.LT
################ Calculate edagger
edagger <- Eastern_HMDL[,list(ed = e.dagger.LT(fx=dx,ex=ex,ax=ax)), by = list(Year,Sex,PopName,Country)]
################ Calculate edagger
edagger <- Eastern_HMDL[,list(ed = e.dagger.LT(fx=dx,ex=ex,ax=ax)), by = list(Year,Sex,PopName,Country)]
Eastern_HMDL
################ Calculate edagger
edagger <- Eastern_HMDL[,list(ed = e.dagger.LT(fx=dx,ex=ex,ax=ax)), by = list(Year,Sex,PopName,Country)]
v <- (sum(fx[-l]* (ex[-l] + ax[-l]*(ex[-1]-ex[-l]) )) + fx[l]*ex[l])
################ Calculate edagger
edagger <- Eastern_HMDL[,list(ed = e.dagger.LT(fx=dx,ex=ex,ax=ax)), by = list(Year,Sex,PopName,Country)]
e.dagger.LT <- function(fx,ex,ax=ax){
l <- length(ex)
v <- (sum(fx[-l]* (ex[-l] + ax[-l]*(ex[-1]-ex[-l]) )) + fx[l]*ex[l])
return(v)
}
e.dagger.LT
################ Calculate edagger
edagger <- Eastern_HMDL[,list(ed = e.dagger.LT(fx=dx,ex=ex,ax=ax)), by = list(Year,Sex,PopName,Country)]
edagger
ed.m <- ggplot(edagger[edagger$Sex=='Male'], aes(Year, ed,colour=Country)) +
ggtitle(expression(paste('Life disparity (',e^"\u2020",')')), subtitle = 'Males')+
annotate('rect', xmin=1987, xmax=1989, ymin=-Inf, ymax=Inf,
alpha=0.2,fill="red")+
geom_line(aes(group = Country,size= Country),show.legend = F) +
scale_size_manual(values =lwd.fig.F1b,guide = FALSE)+
scale_x_continuous('Year', expand = c(0, 0)) +
scale_y_continuous('Years', limits = c(11,19)) +
theme_fivethirtyeight(base_size = 18)+
geom_vline(aes(xintercept=1991.8),show.legend = F,linetype=2,lwd=1.5, colour="blue")+
scale_colour_manual('Country', values = col.fig.F1b) +
theme(text = element_text(size=18),legend.key.size = unit(.4, "in"),axis.title = element_text(),
rect = element_rect(fill = 'white',
linetype = 0, colour = NA),
legend.position="bottom")
ed.m