-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAdding variables from other sources
46 lines (35 loc) · 1.64 KB
/
Adding variables from other sources
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
load("age_mig.rdata") #For info on fields see in the Dropbox #LA level
nonUK<-read.csv("nonUKborn.csv") #For info on fields see in the Dropbox #LA level
pop<-read.csv("PopDensity2016.csv") #LSOA level
#Use table provided on challenge website as a key
key<-read.csv("LSOA_LA_key.csv")
#AGGREGATE LSOA level data to LA level
pop<-merge(pop,key,by.x="LSOA",by.y="LSOA11CD")
p_aggregate <- aggregate(pop[,3:5],list(pop$LAD16CD), mean,na.action=na.pass)
largefile<-read.csv("lsoa-atlas-data-clean-interesting-columns.csv") #LSOA level
largefile<-merge(largefile,key,by.x="LSOA",by.y="LSOA11CD")
l_aggregate <- aggregate(largefile[,c(5:15)],list(largefile$LAD16CD), mean,na.action=na.pass)
#MERGE FILES BY LA
names(p_aggregate)[1]<-"LAD16CD"
names(l_aggregate)[1]<-"LAD16CD"
all<-merge(age_mig,p_aggregate,all=TRUE)
all<-merge(all,l_aggregate,all.x=TRUE)
summary(all
all<-all[,c(1:12)]
save(all,file="Covariates.rda")
five<-read.csv("draft_ethnicity_brexit_05.csv")
aggfive <-aggregate(five, by=list(five$LAD16CD),
FUN=mean, na.rm=TRUE)
head(aggfive)
aggfive<-aggfive[,c(1,4:17,19:20,26:34)]
head(aggfive)
names(aggfive)[1]<-"LAD16CD"
#Assessing correlation between surname estimated immigration and ONS estimated immigration
write.csv(aggfive,file="Brexit_combined_05.csv")
load("Brexit_combined_05.rda")
non<-read.csv("nonUKborn.csv")
names(aggfive)[1]<-"AreaCode"
aggfive<-merge(aggfive,non,all.x=TRUE)
aggfive$actual_imm<-aggfive$nonUK2005/aggfive$resPop2005
cor.test(aggfive$actual_imm, aggfive$nonUK2005, alternative = c("two.sided", "less", "greater"), method = c("pearson", "kendall", "spearman"),
exact = NULL, conf.level = 0.95, continuity = FALSE, ...)