-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmatched cases BMI centile transitions
421 lines (354 loc) · 20.1 KB
/
matched cases BMI centile transitions
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
thisyear<-alldata
thisyear$birthmonth<-month(as.POSIXlt(thisyear$DateOfBirth, format="%Y-%m-%d"))
thisyear$assmonth<-month(as.POSIXlt(thisyear$AssessmentDate, format="%Y-%m"))
thisyear$class<-0
thisyear$class<-ifelse(thisyear$ageattestyr==4,0,NA) #4 year olds are in Reception
thisyear$class<-ifelse(thisyear$birthmonth>=9 & thisyear$ageattestyr==4 &thisyear$assmonth>8,-1,thisyear$class) #4 year olds that have a birthday from September onwards that are measured in the autumn term are not yet in Reception
thisyear$class<-ifelse(thisyear$birthmonth>=9 & thisyear$ageattestyr==4 &thisyear$assmonth>8 & thisyear$birthmonth<thisyear$assmonth,0,thisyear$class)
thisyear$class<-ifelse(thisyear$birthmonth<=thisyear$assmonth & thisyear$ageattestyr==4 &thisyear$assmonth<=8,-1,thisyear$class) #4 year olds with a birthday before September that are measured in the spring term are not yet in Reception
thisyear$class<-ifelse(thisyear$ageattestyr==5,1,thisyear$class) #most 5 year olds are in year one
thisyear$class<-ifelse(thisyear$birthmonth>=9 & thisyear$ageattestyr==5 &thisyear$assmonth>8,0,thisyear$class) #5 year olds that have a birthday from September onwards that are measured in the autumn term are in Reception
thisyear$class<-ifelse(thisyear$birthmonth>=9 & thisyear$ageattestyr==5 &thisyear$assmonth>8 & thisyear$birthmonth<thisyear$assmonth,1,thisyear$class) #5 year olds that have a birthday from September onwards that are measured in the autumn term are in Reception
thisyear$class<-ifelse(thisyear$birthmonth<=thisyear$assmonth & thisyear$ageattestyr==5 &thisyear$assmonth<=8,0,thisyear$class) #5 year olds with a birthday before September that are measured in the spring term are in Reception
thisyear$class<-ifelse(thisyear$ageattestyr==6,2,thisyear$class) # most 6 year olds are in year 2
thisyear$class<-ifelse(thisyear$birthmonth>=9 & thisyear$ageattestyr==6&thisyear$assmonth>8,1,thisyear$class) #6 year olds that have a birthday from September onwards that are measured in the autumn term are in yr1
thisyear$class<-ifelse(thisyear$birthmonth>=9 & thisyear$ageattestyr==6 &thisyear$assmonth>8 & thisyear$birthmonth<thisyear$assmonth,2,thisyear$class) #5 year olds that have a birthday from September onwards that are measured in the autumn term are in Reception
thisyear$class<-ifelse(thisyear$birthmonth<=thisyear$assmonth & thisyear$ageattestyr==6 &thisyear$assmonth<=8,1,thisyear$class) #6 year olds with a birthday before September that are measured in the spring term are in Reception
thisyear$class<-ifelse(thisyear$ageattestyr==7,3,thisyear$class) # most 7 year olds are in year 3
thisyear$class<-ifelse(thisyear$birthmonth>=9 & thisyear$ageattestyr==7 &thisyear$assmonth>8,2,thisyear$class) #7 year olds that have a birthday from September onwards that are measured in the autumn term are in yr2
thisyear$class<-ifelse(thisyear$birthmonth>=9 & thisyear$ageattestyr==7 &thisyear$assmonth>8 & thisyear$birthmonth<thisyear$assmonth,3,thisyear$class) #5 year olds that have a birthday from September onwards that are measured in the autumn term are in Reception
thisyear$class<-ifelse(thisyear$birthmonth<=thisyear$assmonth & thisyear$ageattestyr==7 &thisyear$assmonth<=8,2,thisyear$class) #7 year olds with a birthday before September that are measured in the spring term are in yr1
thisyear$class<-ifelse(thisyear$ageattestyr==8,4,thisyear$class) # most 8 year olds are in year 4
thisyear$class<-ifelse(thisyear$birthmonth>=9 & thisyear$ageattestyr==8 &thisyear$assmonth>8,3,thisyear$class) #8 year olds that have a birthday from September onwards that are measured in the autumn term are in yr3
thisyear$class<-ifelse(thisyear$birthmonth>=9 & thisyear$ageattestyr==8 &thisyear$assmonth>8 & thisyear$birthmonth<thisyear$assmonth,4,thisyear$class) #5 year olds that have a birthday from September onwards that are measured in the autumn term are in Reception
thisyear$class<-ifelse(thisyear$birthmonth<=thisyear$assmonth & thisyear$ageattestyr==8 &thisyear$assmonth<=8,3,thisyear$class) #8 year olds with a birthday before September that are measured in the spring term are in yr3
thisyear$class<-ifelse(thisyear$ageattestyr==9,5,thisyear$class) # most 9 year olds are in year 5
thisyear$class<-ifelse(thisyear$birthmonth>=9 & thisyear$ageattestyr==9 &thisyear$assmonth>8,4,thisyear$class) #9 year olds that have a birthday from September onwards that are measured in the autumn term are in yr4
thisyear$class<-ifelse(thisyear$birthmonth>=9 & thisyear$ageattestyr==9 &thisyear$assmonth>8 & thisyear$birthmonth<thisyear$assmonth,5,thisyear$class) #5 year olds that have a birthday from September onwards that are measured in the autumn term are in Reception
thisyear$class<-ifelse(thisyear$birthmonth<=thisyear$assmonth & thisyear$ageattestyr==9 &thisyear$assmonth<=8,4,thisyear$class) #9 year olds with a birthday before September that are measured in the spring term are in yr4
thisyear$class<-ifelse(thisyear$ageattestyr==10,6,thisyear$class) # most 10 year olds are in year 6
thisyear$class<-ifelse(thisyear$birthmonth>=9 & thisyear$ageattestyr==10 &thisyear$assmonth>8,5,thisyear$class) #10 year olds that have a birthday from September onwards that are measured in the autumn term are in yr5
thisyear$class<-ifelse(thisyear$birthmonth>=9 & thisyear$ageattestyr==10 &thisyear$assmonth>8 & thisyear$birthmonth<thisyear$assmonth,6,thisyear$class) #5 year olds that have a birthday from September onwards that are measured in the autumn term are in Reception
thisyear$class<-ifelse(thisyear$birthmonth<=thisyear$assmonth & thisyear$ageattestyr==10 &thisyear$assmonth<=8,5,thisyear$class) #10 year olds with a birthday before September that are measured in the spring term are in yr5
thisyear$class<-ifelse(thisyear$ageattestyr==11,6,thisyear$class)
champ2<-thisyear
attach(champ2)
champ2$class<-as.numeric(champ2$class)
#CHOOSE FIRST WEIGHT CATEGORY RECORDED PER YEAR WHERE THERE ARE MULTIPLE MEASUREMENTS WITHIN A YEAR
d<-duplicated(champ2[,c(1,3)],fromLast=FALSE)
table(d)
#40 children have multiple measurements within a year
head(champ2[d,],n=10)
champ2<-champ2[!d,]
#DRAW IN BMI THRESHOLD TO WORK OUT CENTILES FOR OVERWEIGHT, OBESE, SEVERELY OBESE
champ2$weightcat<-1#normal
champ2$weightcat<-ifelse(champ2$Centile_BMI>=90.879,2,champ2$weightcat)#overweight
champ2$weightcat<-ifelse(champ2$Centile_BMI>=97.725,3,champ2$weightcat)#obese
champ2$weightcat<-ifelse(champ2$Centile_BMI<2.275,4,champ2$weightcat)#underweight
champ2$weightcat<-ifelse(champ2$Centile_BMI>=99.617,5,champ2$weightcat)#severe
champ2$weightcat<-ifelse(champ2$Centile_BMI<0.383,6,champ2$weightcat)#very underweight
table(champ2$weightcat)
champ2$NoRecords<-1
alldata<-champ2
attach(alldata)
#Assign class at test vector
alldata$Recordr<-as.numeric(ifelse(class==0,1,0))
alldata$Record1<-as.numeric(ifelse(class==1,1,0))
alldata$Record2<-as.numeric(ifelse(class==2,1,0))
alldata$Record3<-as.numeric(ifelse(class==3,1,0))
alldata$Record4<-as.numeric(ifelse(class==4,1,0))
alldata$Record5<-as.numeric(ifelse(class==5,1,0))
alldata$Record6<-as.numeric(ifelse(class==6,1,0))
#Print BMI at each test
alldata$BMIr<-as.numeric(ifelse(class==0,BMI,NA))
alldata$BMI1<-as.numeric(ifelse(class==1,BMI,NA))
alldata$BMI2<-as.numeric(ifelse(class==2,BMI,NA))
alldata$BMI3<-as.numeric(ifelse(class==3,BMI,NA))
alldata$BMI4<-as.numeric(ifelse(class==4,BMI,NA))
alldata$BMI5<-as.numeric(ifelse(class==5,BMI,NA))
alldata$BMI6<-as.numeric(ifelse(class==6,BMI,NA))
#Print weightcat at each age
alldata$weightcatr<-as.numeric(ifelse(class==0,weightcat,NA))
alldata$weightcat1<-as.numeric(ifelse(class==1,weightcat,NA))
alldata$weightcat2<-as.numeric(ifelse(class==2,weightcat,NA))
alldata$weightcat3<-as.numeric(ifelse(class==3,weightcat,NA))
alldata$weightcat4<-as.numeric(ifelse(class==4,weightcat,NA))
alldata$weightcat5<-as.numeric(ifelse(class==5,weightcat,NA))
alldata$weightcat6<-as.numeric(ifelse(class==6,weightcat,NA))
attach(alldata)
#Print centile at each age
alldata$centr<-as.numeric(ifelse(class==0,Centile_BMI,NA))
alldata$cent1<-as.numeric(ifelse(class==1,Centile_BMI,NA))
alldata$cent2<-as.numeric(ifelse(class==2,Centile_BMI,NA))
alldata$cent3<-as.numeric(ifelse(class==3,Centile_BMI,NA))
alldata$cent4<-as.numeric(ifelse(class==4,Centile_BMI,NA))
alldata$cent5<-as.numeric(ifelse(class==5,Centile_BMI,NA))
alldata$cent6<-as.numeric(ifelse(class==6,Centile_BMI,NA))
attach(alldata)
#Print date at each age
alldata$dr<-as.numeric(ifelse(class==0,AssessmentDate,NA))
alldata$d1<-as.numeric(ifelse(class==1,AssessmentDate,NA))
alldata$d2<-as.numeric(ifelse(class==2,AssessmentDate,NA))
alldata$d3<-as.numeric(ifelse(class==3,AssessmentDate,NA))
alldata$d4<-as.numeric(ifelse(class==4,AssessmentDate,NA))
alldata$d5<-as.numeric(ifelse(class==5,AssessmentDate,NA))
alldata$d6<-as.numeric(ifelse(class==6,AssessmentDate,NA))
attach(alldata)
#Determine how many measurements taken per child
alldata$NoRecords<-(Recordr+Record1+Record2+Record3+Record4+Record5+Record6)
Recs<-aggregate(alldata$NoRecords, by=list(Category=ChildID), FUN=sum)
names(Recs)[names(Recs)=="x"] <- "NoRecs"
names(Recs)[names(Recs)=="Category"] <- "ChildID"
##############################################################################
#Merge to have BMI at different ages on the same line
Recs2<-Recs[Recs$NoRecs==2,]
multiple<-alldata[alldata$ChildID %in% Recs2$ChildID,] #children measured more than once
multiple<-with(multiple, multiple[order(ChildID),])
attach(multiple)
as.numeric(c(centr,cent1,cent2,cent3,cent4,cent5,cent6))
multiple$ChildID<-as.factor(multiple$ChildID)
multiple$IsAccountRegistered<-as.numeric(multiple$IsAccountRegistered)-1
multiplebase<-multiple[,c(1,12)]
multiplefirst<-multiple[!is.na(multiple$centr),c(1, 45)]
multiple1<-multiple[!is.na(multiple$cent1),c(1, 46)]
multiple2<-multiple[!is.na(multiple$cent2),c(1, 47)]
multiple3<-multiple[!is.na(multiple$cent3),c(1, 48)]
multiple4<-multiple[!is.na(multiple$cent4),c(1, 49)]
multiple5<-multiple[!is.na(multiple$cent5),c(1, 50)]
multiple6<-multiple[!is.na(multiple$cent6),c(1, 51)]
multiple$ageattestyr<-as.numeric(multiple$ageattestyr)
multiple7<-aggregate(multiple$ageattestyr,by=list(multiple$ChildID),FUN=min)
colnames(multiple7)<- c("ChildID","AgeF")
multiple8<-aggregate(as.numeric(multiple$Gender),by=list(ChildID),FUN=min)
colnames(multiple8)<- c("ChildID","Gender")
Ethnicity2<-multiple$Ethnicity
levels(Ethnicity2)[1:3]<-"White"
levels(Ethnicity2)[11:12]<-"Black African and other"
levels(Ethnicity2)[2:3]<-"Mixed black and white"
levels(Ethnicity2)[9:10]<-"Black"
levels(Ethnicity2)[5:6]<-"Indian/Pakistani"
levels(Ethnicity2)[3]<-"Asian"
levels(Ethnicity2)[5:7]<-"Asian"
levels(Ethnicity2)[4]<-"other"
levels(Ethnicity2)[7]<-"other"
levels(Ethnicity2)[6]<-"Asian"
levels(Ethnicity2)[7]<-"NA"
levels(Ethnicity2)[4]<-"NA"
levels(Ethnicity2)[6]<-"NA"
levels(Ethnicity2)[4]<-"other"
levels(Ethnicity2)[2]<-"other"
multiple$Ethnicity2<-Ethnicity2
attach(multiple)
multiple9<-aggregate(as.numeric(multiple$Ethnicity2),by=list(multiple$ChildID),FUN=min)
colnames(multiple9)<- c("ChildID","Eth2")
multiplereg<-multiple[c(1, 10)]
library(plyr)
multi<-merge(multiplebase,multiplefirst,by="ChildID",all.x=TRUE)
multi<-merge(multi,multiple1,by="ChildID",all.x=TRUE)
multi<-merge(multi,multiple2,by="ChildID",all.x=TRUE)
multi<-merge(multi,multiple3,by="ChildID",all.x=TRUE)
multi<-merge(multi,multiple4,by="ChildID",all.x=TRUE)
multi<-merge(multi,multiple5,by="ChildID",all.x=TRUE)
multi<-merge(multi,multiple6,by="ChildID",all.x=TRUE)
multi<-merge(multi,multiple7,by="ChildID",all.x=TRUE)
multi<-merge(multi,multiple8,by="ChildID",all.x=TRUE)
multi<-merge(multi,multiple9,by="ChildID",all.x=TRUE)
multiple10<-multiple[!is.na(multiple$dr),c(1, 52)]
multiple11<-multiple[!is.na(multiple$d1),c(1, 53)]
multiple12<-multiple[!is.na(multiple$d2),c(1, 54)]
multiple13<-multiple[!is.na(multiple$d3),c(1, 55)]
multiple14<-multiple[!is.na(multiple$d4),c(1, 56)]
multiple15<-multiple[!is.na(multiple$d5),c(1, 57)]
multiple16<-multiple[!is.na(multiple$d6),c(1, 58)]
multi<-merge(multiplebase,multiplefirst,by="ChildID",all.x=TRUE)
multi<-merge(multi,multiple1,by="ChildID",all.x=TRUE)
multi<-merge(multi,multiple2,by="ChildID",all.x=TRUE)
multi<-merge(multi,multiple3,by="ChildID",all.x=TRUE)
multi<-merge(multi,multiple4,by="ChildID",all.x=TRUE)
multi<-merge(multi,multiple5,by="ChildID",all.x=TRUE)
multi<-merge(multi,multiple6,by="ChildID",all.x=TRUE)
multi<-merge(multi,multiple7,by="ChildID",all.x=TRUE)
multi<-merge(multi,multiple8,by="ChildID",all.x=TRUE)
multi<-merge(multi,multiple9,by="ChildID",all.x=TRUE)
multi<-merge(multi,multiple10,by="ChildID",all.x=TRUE)
multi<-merge(multi,multiple11,by="ChildID",all.x=TRUE)
multi<-merge(multi,multiple12,by="ChildID",all.x=TRUE)
multi<-merge(multi,multiple13,by="ChildID",all.x=TRUE)
multi<-merge(multi,multiple14,by="ChildID",all.x=TRUE)
multi<-merge(multi,multiple15,by="ChildID",all.x=TRUE)
multi<-merge(multi,multiple16,by="ChildID",all.x=TRUE)
multi<-merge(multi,multiplereg,by="ChildID",all.x=TRUE)
attach(multi)
multi2<-aggregate(multi,by=list(multi$ChildID),FUN=mean)
multi2$ChildID<-multi2$Group.1
multi<-multi2
###############################################
#CALCULATE DIFF BETWEEN MEASUREMENTS
length(multi$ChildID)#25024
attach(multi)
measure1<-as.numeric(centr)
measure1<-ifelse(is.na(measure1)&!is.na(cent1),paste(cent1),measure1)
measure1<-as.numeric(measure1)
measure1<-ifelse(is.na(measure1)&!is.na(cent2),paste(cent2),measure1)
measure1<-as.numeric(measure1)
measure1<-ifelse(is.na(measure1)&!is.na(cent3),paste(cent3),measure1)
measure1<-as.numeric(measure1)
measure1<-ifelse(is.na(measure1)&!is.na(cent4),paste(cent4),measure1)
measure1<-as.numeric(measure1)
measure1<-ifelse(is.na(measure1)&!is.na(cent5),paste(cent5),measure1)
measure1<-as.numeric(measure1)
measure1<-ifelse(is.na(measure1)&!is.na(cent6),paste(cent6),measure1)
measure2<-as.numeric(cent6)
measure2<-ifelse(is.na(measure2)&(!is.na(cent5)),paste(cent5),measure2)
measure2<-as.numeric(measure2)
measure2<-ifelse(is.na(measure2)&(!is.na(cent4)),paste(cent4),measure2)
measure2<-as.numeric(measure2)
measure2<-ifelse(is.na(measure2)&(!is.na(cent3)),paste(cent3),measure2)
measure2<-as.numeric(measure2)
measure2<-ifelse(is.na(measure2)& (!is.na(cent2)),paste(cent2),measure2)
measure2<-as.numeric(measure2)
measure2<-ifelse(is.na(measure2)& (!is.na(cent1)),paste(cent1),measure2)
measure2<-ifelse(is.na(measure2)& (!is.na(centr)),paste(centr),measure2)
multi$measure1<-as.numeric(measure1)
multi$measure2<-as.numeric(measure2)
multi$cendiff<-multi$measure2-multi$measure1
multi$diffnorm<-(abs(50-measure1)-abs(50-measure2)) #if positive, marks a move towards the normal
attach(multi)
multi$dir<-ifelse(multi$cendiff>0,1,0)
table(multi$IsAccountRegistered)
table(multi$measure1)
table(multi$measure2)
attach(multi)
#MARK THE DATES OF 1ST AND SECOND MEASUREMENTS
d<-dr
d<-as.numeric(d)
d<-ifelse(is.na(d),paste(d1),d)
d<-as.numeric(d)
d<-ifelse(is.na(d),paste(d2),d)
d<-as.numeric(d)
d<-ifelse(is.na(d),paste(d3),d)
d<-as.numeric(d)
d<-ifelse(is.na(d),paste(d4),d)
d<-as.numeric(d)
d<-ifelse(is.na(d),paste(d5),d)
d<-as.numeric(d)
d<-ifelse(is.na(d),paste(d6),d)
multi$d<-as.numeric(d)
db<-d6
db<-as.numeric(db)
db<-ifelse(is.na(db),paste(d5),db)
db<-as.numeric(db)
db<-ifelse(is.na(db),paste(d4),db)
db<-as.numeric(db)
db<-ifelse(is.na(db),paste(d3),db)
db<-as.numeric(db)
db<-ifelse(is.na(db),paste(d2),db)
db<-as.numeric(db)
db<-ifelse(is.na(db),paste(d1),db)
multi$db<-as.numeric(db)
multi<-multi[!is.na(multi$db)&!is.na(multi$Eth2)&!is.na(multi$PostcodeDecile),]
multi<-multi[!multi$db==multi$d,]
save(multi, file ="multi.Rda")
###############################################
#BREAKPOINT
################################################
load(multi, file ="multi.Rda")
#Find difference over couse of 1 year
multi$days<-as.numeric(multi$db)-as.numeric(multi$d)
multi$cendiffs<-multi$cendiff/multi$days*365.25
multi$diffnorms<-abs(as.numeric(multi$measure1)-50)-abs(as.numeric(multi$measure2)-50) #if positive, marks a move towards the normal
multi<-multi[multi$measure1>=2.275,]
multi$bmidecile<-findInterval(multi$measure1,c(10,20,30,40,50,60,70,80,90))
multi$cat1<-findInterval(multi$measure1,c(10,20,30,40,50,60,70,80,90))
multi$cat2<-findInterval(multi$measure1,c(10,20,30,40,50,60,70,80,90))
multi$imdquintile<-findInterval(multi$PostcodeDecile,c(0,2,4,6,8,10))
attach(multi)
save(multi, file ="multi.Rda")
#CREATE SUBSETS BY BMI CATEGORY USING CLINICAL THRESHOLDS
multi<-multi[,c(2:34)]
multi$IsAccountRegistered<-as.factor((as.numeric(multi$IsAccountRegistered)))
multi<-multi[!is.na(multi$Eth2)&!is.na(multi$AgeF)&!is.na(multi$imdquintile)&!is.na(multi$diffnorms)&!is.na(multi$cendiffs)&!is.na(multi$bmidecile)&!is.na(multi$IsAccountRegistered)&!is.na(multi$bmidecile)&!is.na(multi$Gender),]
attach(multi)
over<-multi[multi$measure1>=90.879&multi$measure1<97.725,]
normal<-multi[multi$measure1>=2.275&multi$measure1<90.879,]
obese<-multi[multi$measure1>=97.725,]
#MATCH CASES AND CONTROLS
##############################################
library(MatchIt)#missing data cause failure even if they are in fields not included in the matching terms
set.seed(1234)
match.ov<- matchit(IsAccountRegistered~AgeF+Gender+Eth2+imdquintile,data=over[,c(1,10:12,20,28:29,30,33)], method="exact", ratio=2)
match.ob<- matchit(IsAccountRegistered~AgeF+Gender+Eth2+imdquintile,data=obese[,c(1,10:12,20,28:29,30,33)], method="exact", ratio=2)
match.no<- matchit(IsAccountRegistered~AgeF+Gender+Eth2+bmidecile+imdquintile,data=normal[,c(1,10:12,20,28:29,30,33)], method="exact", ratio=2)
matchd.no<- match.data(match.no,group="all", distance="distance",weights="weights", subclass="subclass")
matchd.ob<- match.data(match.ob,group="all", distance="distance",weights="weights", subclass="subclass")
matchd.ov<- match.data(match.ov,group="all", distance="distance",weights="weights", subclass="subclass")
matchd.ov$mov<-ifelse(matchd.ov$diffnorms<0,1,NA)
matchd.ov$mov<-ifelse(matchd.ov$diffnorms==0,2,matchd.ov$mov)
matchd.ov$mov<-ifelse(matchd.ov$diffnorms>0,3,matchd.ov$mov)
ta<-table(matchd.ov$IsAccountRegistered,matchd.ov$mov)
chisq.test(ta)
matchd.ob$mov<-ifelse(matchd.ob$diffnorms<0,1,NA)
matchd.ob$mov<-ifelse(matchd.ob$diffnorms==0,2,matchd.ov$mov)
matchd.ob$mov<-ifelse(matchd.ob$diffnorms>0,3,matchd.ov$mov)
tb<-table(matchd.ob$IsAccountRegistered,matchd.ob$mov)
chisq.test(tb)
matchd.no$mov<-ifelse(matchd.no$diffnorms<0,1,NA)
matchd.no$mov<-ifelse(matchd.no$diffnorms==0,2,matchd.no$mov)
matchd.no$mov<-ifelse(matchd.no$diffnorms>0,3,matchd.no$mov)
tc<-table(matchd.no$IsAccountRegistered,matchd.no$mov)
chisq.test(tc)
matchd.no$stay<-ifelse(matchd.no$measure1==matchd.no$measure2,1,2)
tc<-table(matchd.no$IsAccountRegistered,matchd.no$stay)
chisq.test(tc)
t.test(matchd.ov$cendiffs~matchd.ov$IsAccountRegistered)
t.test(matchd.nov$cendiffs~matchd.no$IsAccountRegistered)
t.test(matchd.ob$cendiffs~matchd.ob$IsAccountRegistered)
normno<-matchd.no[matchd.no$IsAccountRegistered==0,]
normyes<-matchd.no[matchd.no$IsAccountRegistered==1,]
obyes<-matchd.ob[matchd.ob$IsAccountRegistered==1,]
obno<-matchd.ob[matchd.ob$IsAccountRegistered==0,]
ovyes<-matchd.ov[matchd.ov$IsAccountRegistered==1,]
ovno<-matchd.ov[matchd.ov$IsAccountRegistered==0,]
#CALCULATE CENTILE CHANGE IN MATCHED CHILDREN
mean(ovyes$cendiffs)
mean(ovno$cendiffs)
mean(obno$cendiffs)
mean(obyes$cendiffs)
mean(normyes$cendiffs)
mean(normno$cendiffs)
length(obno$ChildID[obno$diffnorms>0])
length(obno$ChildID[obno$diffnorms==0])
length(obno$ChildID[obno$diffnorms<0])
length(ovno$ChildID[ovno$diffnorms>0])
length(ovno$ChildID[ovno$diffnorms==0])
length(ovno$ChildID[ovno$diffnorms<0])
length(normno$ChildID[normno$diffnorms>0])
length(normno$ChildID[normno$diffnorms==0])
length(normno$ChildID[normno$diffnorms<0])
length(obyes$ChildID[obyes$diffnorms>0])
length(obyes$ChildID[obyes$diffnorms==0])
length(obyes$ChildID[obyes$diffnorms<0])
length(ovno$ChildID[ovyes$diffnorms>0])
length(ovyes$ChildID[ovyes$diffnorms==0])
length(ovyes$ChildID[ovyes$diffnorms<0])
length(normyes$ChildID[normyes$diffnorms>0])
length(normyes$ChildID[normyes$diffnorms==0])
length(normyes$ChildID[normyes$diffnorms<0])
median(ovyes$cendiffs)
median(ovno$cendiffs)
median(obno$cendiffs)
median(obyes$cendiffs)
median(normyes$cendiffs)
median(normno$cendiffs)
mean(ovyes$diffnorms)
mean(ovno$diffnorms)
mean(obno$diffnorms)
mean(obyes$diffnorms)
mean(normyes$diffnorms)
mean(normno$diffnorms)
median(ovyes$diffnorms)
median(ovno$diffnorms)
median(obno$diffnorms)
median(obyes$diffnorms)
median(normyes$diffnorms)
median(normno$diffnorms)