-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathAnalyse BMI change between fixed stages
234 lines (190 loc) · 11.1 KB
/
Analyse BMI change between fixed stages
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
attach(champ2)
#CHOOSE FIRST WEIGHT CATEGORY RECORDED PER YEAR WHERE THERE ARE MULTIPLE MEASUREMENTS WITHIN A YEAR
d<-duplicated(champ2[,c(1,21)],fromLast=FALSE)
table(d)
#2991 (~3% of 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)#morbid
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)
#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"
##############################################################################
#SELECTING DATA FOR REC-3 AND 3-6
fours<-which(!is.na(alldata$weightcatr))
fourdata<-alldata[fours,]
table(fourdata$AcademicYear)
threes<-which(!is.na(alldata$weightcat3))
thrdata<-alldata[threes,]
table(thrdata$AcademicYear)
sixes<-which(!is.na(alldata$weightcat6))
sixdata<-alldata[sixes,]
table(sixdata$AcademicYear)
recand3<-which(alldata$ChildID %in% fourdata$ChildID & alldata$ChildID %in% thrdata$ChildID)
thrand6<-which(alldata$ChildID %in% thrdata$ChildID & alldata$ChildID %in% sixdata$ChildID)
firstpair<-alldata[recand3,]
firstpair<- firstpair[ c(1, 36, 39) ]
firstpair<-aggregate(firstpair, by=list(Category=firstpair$ChildID), FUN=max,na.rm=TRUE)
secpair<-alldata[thrand6,]
#############################################################################
#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 twice
Recs3<-Recs[Recs$NoRecs==3,]
threevalues<-alldata[alldata$ChildID %in% Recs3$ChildID,] #children measured three times
Recs4<-Recs[Recs$NoRecs==4,]
fourvalues<-alldata[alldata$ChildID %in% Recs4$ChildID,] #children measured four times
Th<-aggregate(threevalues, by=list(Category=threevalues$ChildID), FUN=max)
Fo<-aggregate(fourvalues, by=list(Category=fourvalues$ChildID), FUN=max)
multiple<-with(multiple, multiple[order(ChildID),])
attach(multiple)
as.numeric(c(weightcatr,weightcat1,weightcat2,weightcat3,weightcat4,weightcat5,weightcat6))
multiple$ChildID<-as.factor(multiple$ChildID)
multiple$IsAccountRegistered<-as.numeric(multiple$IsAccountRegistered)-1
multiplebase<-multiple[,c(1,2)]
multiplefirst<-multiple[!is.na(multiple$weightcatr),c(1, 38)]
multiple1<-multiple[!is.na(multiple$weightcat1),c(1, 39)]
multiple2<-multiple[!is.na(multiple$weightcat2),c(1, 40)]
multiple3<-multiple[!is.na(multiple$weightcat3),c(1, 41)]
multiple4<-multiple[!is.na(multiple$weightcat4),c(1, 42)]
multiple5<-multiple[!is.na(multiple$weightcat5),c(1, 43)]
multiple6<-multiple[!is.na(multiple$weightcat6),c(1, 44)]
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,multiplereg,by="ChildID",all.x=TRUE)
multi2<-aggregate(multi,by=list(multi$ChildID),FUN=mean)
multi<-multi2
multi$ChildID<-multi$Group.1
yes<-multi[multi$IsAccountRegistered=="1",]
which(yes$measure1<multi$measure2)#how many registered children had 2 or more measurements
###########################################
#Considering children with single measurements
Recs2<-Recs[Recs$NoRecs>1,]
multiple<-alldata[alldata$ChildID %in% Recs2$ChildID,] #children measured more than once
multiple<-with(multiple, multiple[order(ChildID),])
attach(multiple)
as.numeric(c(weightcatr,weightcat1,weightcat2,weightcat3,weightcat4,weightcat5,weightcat6))
multiple$ChildID<-as.factor(multiple$ChildID)
multiple$IsAccountRegistered<-as.numeric(multiple$IsAccountRegistered)-1
multiplebase<-multiple[,c(1,2)]
multiplefirst<-multiple[!is.na(multiple$weightcatr),c(1, 37)]
multiple1<-multiple[!is.na(multiple$weightcat1),c(1, 38)]
multiple2<-multiple[!is.na(multiple$weightcat2),c(1, 39)]
multiple3<-multiple[!is.na(multiple$weightcat3),c(1, 40)]
multiple4<-multiple[!is.na(multiple$weightcat4),c(1, 41)]
multiple5<-multiple[!is.na(multiple$weightcat5),c(1, 42)]
multiple6<-multiple[!is.na(multiple$weightcat6),c(1, 43)]
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,multiplereg,by="ChildID",all.x=TRUE)
multi2<-aggregate(multi,by=list(multi$ChildID),FUN=mean)
multi<-multi2
multi$ChildID<-multi$Group.1
length(multi$ChildID)#32977
attach(multi)
measure1<-weightcatr
measure1<-as.numeric(measure1)
measure1<-ifelse(is.na(measure1)&weightcat1>=1,paste(weightcat1),measure1)
measure1<-ifelse(is.na(measure1)&weightcat2>=1,paste(weightcat2),measure1)
measure1<-ifelse(is.na(measure1)&weightcat3>=1,paste(weightcat3),measure1)
measure1<-ifelse(is.na(measure1)&weightcat4>=1,paste(weightcat4),measure1)
measure1<-ifelse(is.na(measure1)&weightcat5>=1,paste(weightcat5),measure1)
measure2<-ifelse(!is.na(weightcatr),paste(weightcat1),NA)
measure2<-as.numeric(measure2)
measure2<-ifelse(is.na(measure2)&(!is.na(weightcatr)|!is.na(weightcat1)),paste(weightcat2),measure2)
measure2<-as.numeric(measure2)
measure2<-ifelse(is.na(measure2)&(!is.na(weightcatr)|!is.na(weightcat1)|!is.na(weightcat2)),paste(weightcat3),measure2)
measure2<-as.numeric(measure2)
measure2<-ifelse(is.na(measure2)&(!is.na(weightcatr)|!is.na(weightcat1)|!is.na(weightcat2)|!is.na(weightcat3)),paste(weightcat4),measure2)
measure2<-as.numeric(measure2)
measure2<-ifelse(is.na(measure2)& (!is.na(weightcatr)|!is.na(weightcat1)|!is.na(weightcat2)|!is.na(weightcat3)|!is.na(weightcat4))&weightcat5>=1,paste(weightcat5),measure2)
measure2<-as.numeric(measure2)
measure2<-ifelse(is.na(measure2)& (!is.na(weightcatr)|!is.na(weightcat1)|!is.na(weightcat2)|!is.na(weightcat3)|!is.na(weightcat4)|!is.na(weightcat5))&weightcat6>=1,paste(weightcat6),measure2)
measure2<-as.numeric(measure2)
multi$measure1<-measure1
multi$measure2<-measure2
measure3<-ifelse()
multi$measure3<-measure3
table(multi$IsAccountRegistered)
table(multi$measure1)
table(multi$measure2)
#WHAT IS THE CHANGE AFTER THE SECOND MEASUREMENT?
which((multi$measure1<multi$measure2&multi$IsAccountRegistered=="1"))#which registered children increaed weight category from rec to their next measurement #727
which((multi$measure1<multi$measure2&multi$IsAccountRegistered=="1"))#how many registered children had 2 or more measurements #8521
which((multi$measure1<multi$measure2&multi$IsAccountRegistered=="0"))#which unregistered children increaed weight category from rec to their next measurement #2254
which((multi$IsAccountRegistered=="0"))#how many unregistered children had 2 or more measurements #23118
no<-multi[multi$IsAccountRegistered=="0",]
yes<-multi[multi$IsAccountRegistered=="1",]
which(yes$measure1<multi$measure2)#how many registered children had 2 or more measurements #8521
which((fourten$SDfour)>2)#which children were obese at 4 and also measured at 10
which((multiple$weightcatr>0)&(multiple$weightcat3>0))#which children remained obese from 4 to 10
which((fiveleven$SDfive)>2)#which children were obese at 5 and also measured at eleven
which((fiveeleven$SDeleven)>2&as.numeric(fiveeleven$SDfive)>2)#which children remained obese from 5 to 11
which((fiveeleven$SDeleven)<1.33&as.numeric(fiveeleven$SDfive)>2)#which children obese at 5 are normal weight at 11
which((fourten$SDten)<1.33&as.numeric(fourten$SDfour)>2)#which children obese at 4 are normal weight at 10
#See how champ registered children compare
which (fourten$IsAccountRegistered>0.5)
which (fiveeleven$IsAccountRegistered>0.5)
which((fourten$SDten)-as.numeric(fourten$SDfour)>0&(fourten$IsAccountRegistered>0.5))#which registered children gained SDs from UK90 between 4 and 10
which((fiveeleven$SDeleven)-as.numeric(fiveeleven$SDfive)>0&(fiveeleven$IsAccountRegistered>0.5))#which registered children gained SDs from UK90 between 4 and 10
which((fourten$SDten)-as.numeric(fourten$SDfour)<0&(fourten$IsAccountRegistered>0.5))#which registered children lose SDs from UK90 between 4 and 10
which((fiveeleven$SDeleven)-as.numeric(fiveeleven$SDfive)<0&(fiveeleven$IsAccountRegistered>0.5))#which registered children lose SDs from UK90 between 4 and 10
#Check for unregistered children
which (fourten$IsAccountRegistered<0.5)
which (fiveeleven$IsAccountRegistered<0.5)
which((fourten$SDten)-as.numeric(fourten$SDfour)>0&(fourten$IsAccountRegistered<0.5))#which registered children gained SDs from UK90 between 4 and 10
which((fiveeleven$SDeleven)-as.numeric(fiveeleven$SDfive)>0&(fiveeleven$IsAccountRegistered<0.5))#which registered children gained SDs from UK90 between 4 and 10
which((fourten$SDten)-as.numeric(fourten$SDfour)<0&(fourten$IsAccountRegistered<0.5))#which registered children lose SDs from UK90 between 4 and 10
which((fiveeleven$SDeleven)-as.numeric(fiveeleven$SDfive)<0&(fiveeleven$IsAccountRegistered<0.5))#which registered children lose SDs from UK90 between 4 and 10
#Percentages calculated in excel show little apparent difference at this stage, but there are too few samples to draw conclusions