-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEstatistica, conferencia kcal e macros
More file actions
572 lines (323 loc) · 13.6 KB
/
Copy pathEstatistica, conferencia kcal e macros
File metadata and controls
572 lines (323 loc) · 13.6 KB
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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
###auto Maria Miele
###Conferencia dos dados do banco original
###mesclagem com meu N
library(tidyverse)
library(ggplot2)
library(xlsx)
library(gapminder)
library(tibble)
library(dplyr)
library(magrittr)
#o ggplot tem pacotes de extensão para ele. Uma recomendada é ggtheme
#install.packages("ggthemes") usando a ferrament packages
install.packages("ggthemes")
library(ggthemes)
Macros<-read.xlsx("C:/Users/miele/Dropbox/DOUTORADO/BANCO DE DADOS/Dados/Macros/Macro_total.xlsx", "Tab1")
EER<-read.xlsx("C:/Users/miele/Dropbox/DOUTORADO/BANCO DE DADOS/Dados/EER_kcals/EERkcal_total.xlsx", "Sheet1")
kcal_BD<-read.xlsx("C:/Users/miele/Dropbox/DOUTORADO/BANCO DE DADOS/Dados/EER_kcals/EERkcal_total.xlsx", "Sheet1")
dim(EER)
##retirar colunas indesejadas do EER
EER <- EER [ ,-(10:15)]
##retirar colunas indesejadas do kcal
kcal_BD <- kcal_BD [ ,-3]
kcal_BD <- kcal_BD [ ,-(5:14)]
kcal_BD <- kcal_BD [ ,-(5:6)]
summary(kcal_BD)
##separar por região para avaliar
kcal_BD$centro <- gsub ("UNICAMP", "SE", kcal_BD$centro)
kcal_BD$centro <- gsub ("UNESP", "SE", kcal_BD$centro)
kcal_BD$centro <- gsub ("UFRGS", "SE", kcal_BD$centro)
kcal_BD$centro <- gsub ("MEAC", "NE", kcal_BD$centro)
kcal_BD$centro <- gsub ("UFPE", "NE", kcal_BD$centro)
kcaln <- filter(kcal_BD, centro == "NE")
summary(kcaln)
kcals <- filter(kcal_BD, centro == "SE")
summary(kcals)
#fazer o joind entre macros e EER para unificar o arquivo
Makcal <- left_join(Macros,EER, by = "ID")
dim(Makcal)
###seleciona colunas se macros conforme regiao
Macros <- Macros[ ,-2]
summarise(Macros)
summary(Macros$Calories.kcal.)
#selecionar colunas para calorias
calne <- select(Macros,"Region","Calories.kcal.")
summary(calne$Calories.kcal.)
table(calne$Region)
barplot(table(calne$Region))
#filtrar "Region"
calNE <- filter(calne,Region == "NE") %>% view
calSE <- filter(calne,Region == "SE") %>% view
summary(calNE$Calories.kcal.)
summary(calSE$Calories.kcal.)
sd(calNE$Calories.kcal.)
sd(calSE$Calories.kcal.)
sd(calne$Calories.kcal.)
#selecionar colunas para macros por regiao
Macrosn <- select(Macros,"Region","Carbohydrate...","Protein...","Lipids...")
MacroNE <- filter(Macrosn,Region == "NE") %>% view
MacroSE <- filter(Macrosn,Region == "SE") %>% view
summary(Macrosn$Carbohydrate...)
sd(Macrosn$Carbohydrate...)
#separando os macros
CarboSN <- select(Macrosn,"Carbohydrate...")
ProteSN <- select(Macrosn,"Protein...")
LipSN <- select(Macrosn,"Lipids...")
#Filtra ou seleciona de acordo com alguma condição (maior e igual, menor e ...)
choInsu <- filter(CarboSN, Carbohydrate...<45.0)
count(choInsu)
choAd <- filter(CarboSN, Carbohydrate...>45:65)
count(choInsu)
#definendo uma faixa de valores não entra nenhum valor outlier ou NA
filter(problema, between(c,1,5)) #filtra coluna c nos valores de 1 a 5
filter(problema, between(c,1,5) &between(b,1,6)) # filtrar essas colunas nesses valores
#######
table(calne$Region)
barplot(table(calne$Region))
#filtrar "Region"
calNE <- filter(calne,Region == "NE") %>% view
calSE <- filter(calne,Region == "SE") %>% view
summary(calNE$Calories.kcal.)
summary(calSE$Calories.kcal.)
sd(calNE$Calories.kcal.)
sd(calSE$Calories.kcal.)
sd(calne$Calories.kcal.)
######### medida de posição no R
### minimo, maximo, mdian, mean
##identifica
#quatile identifica qualquer percentual
#summary, ve todoas as posições
min(Adeq1$BMI)
median(Adeq1$BMI)
quantile(MicroBD$B12,c(0.25,0.50,0.75))
summary(MicroBD$B12)
######medidas de dispersão
##amplitude subtrai o maximo do minimo
max(MicroBD$B12)-min(MicroBD$B12)
##desvio padrao dividido pela média traz o coeficiente de variação
sd(MicroBD$B12)/mean(MicroBD$B12)
sd(BBase_final$IdadeMae)/mean(BBase_final$IdadeMae)
##table quantitade de frequencia absoluta de variavel nominal
table(MicroBD$centro)
##conferindo quantidade de brancas e não brancas em contagem e em grafico
table(Macros$centro)
barplot(table(Macros$centro))
##soma da frequencia e o total peso de cada um percentual, frequencia relativas
table(Macros$centro)/1145
dim(Macros)
### Dataframe e colunas
#substituir o nome das especies para NE e SE
MiNS <- MicroBD
MiNS$centro <- gsub ("UNICAMP", "SE", MiNS$centro)
MiNS$centro <- gsub ("UNESP", "SE", MiNS$centro)
MiNS$centro <- gsub ("UFRGS", "SE", MiNS$centro)
MiNS$centro <- gsub ("MEAC", "NE", MiNS$centro)
MiNS$centro <- gsub ("UFPE", "NE", MiNS$centro)
#Filtar cor da pela
Cor_cat2 <- SAMBA_banco_final_26_01_19_testeMAJU %>% select("Etnia_cat2") %>% view
Cor_cat <- SAMBA_banco_final_26_01_19_testeMAJU %>% select("Etnia_cat") %>% view
Cor_etnia <- SAMBA_banco_final_26_01_19_testeMAJU %>% select("Etnia") %>% view
Cor <- SAMBA_banco_final_26_01_19_testeMAJU %>% select("EtniaCordepele") %>% view
#colocar as colanas lado a lado em novo arquivo "cor final"
Cor_final <- cbind(Cor_cat,Cor_cat2,Cor_etnia,Cor)
#exportar para excel
write.xlsx(Cor_final,"C:/Users/miele/Dropbox/DOUTORADO/BANCO DE DADOS/Dados/Cor_final.xlsx")
#tranformar as variaveis em tibble
Cor_cat2 <- as_tibble(Cor_cat2)
Cor<- as_tibble(Cor)
Cor_etnia <- as_tibble(Cor_etnia)
Cor_cat <- as_tibble(Cor_cat)
##fazer intercessao
intersect(Cor_cat,Cor) %>% view
intersect(Cor_cat2,Cor_etnia) %>% view
##selecionar direto as variaveis de interesse
Cor_unica <- SAMBA_banco_final_26_01_19_testeMAJU %>% select("Etnia","Etnia_cat","Etnia_cat2","EtniaCordepele","ID") %>% view
###minerar Cor unica para conferencia dos dados
### 1 enviar esse arquivo com ID para excel
write.xlsx(Cor_unica,"C:/Users/miele/Dropbox/DOUTORADO/BANCO DE DADOS/Dados/Cor_unicaID.xlsx")
####2 criar segundo arquivo cor unica 1 para mineração
Cor_unica1 <- Cor_unica
###mudar os nomes das linhas para fazer intercessão fanzendo todas branca e não branca
Cor_unica1$EtniaCordepele <- gsub ("100-Branca", "1", Cor_unica1$EtniaCordepele)
Cor_unica1$EtniaCordepele <- gsub ("101-Parda", "2", Cor_unica1$EtniaCordepele)
Cor_unica1$EtniaCordepele <- gsub ("102-Preta", "2", Cor_unica1$EtniaCordepele)
Cor_unica1$EtniaCordepele <- gsub ("103-Amarela", "2", Cor_unica1$EtniaCordepele)
Cor_unica1$EtniaCordepele <- gsub ("104-Outra", "2", Cor_unica1$EtniaCordepele)
Cor_unica1$Etnia_cat1 <- gsub ("3", "2", Cor_unica1$Etnia_cat1)
Cor_unica1$Etnia <- gsub ("3", "2", Cor_unica1$Etnia)
### transofrmar em tible
Cor_unica1 <- as_tibble(Cor_unica1)
#buscando informações sobre as variaveis cor
Cor_unica1 %>% count(Cor_unica1$Etnia_cat, Cor_unica1$Etnia_cat2, Cor_unica1$EtniaCordepele, Cor_unica1$Etnia, sort= TRUE) %>% view
Cor_final %>% count(Cor_final$Etnia_cat2,Cor_final$Etnia,Cor_final$EtniaCordepele, Cor_final$Etnia_cat, sort= TRUE) %>% view
###conferencia para DMG
DMG <- SAMBA_banco_final_26_01_19_testeMAJU
DMG %>% count(DMG$Centro, DMG$Caso_DMG, DMG$ID, sort = TRUE)
##selecionar por centro
#selecionando as variaveis de interesse
DMG1 <- DMG %>% select(Centro, Caso_DMG, Caso_diabetes_SAMBA, ID, Centro)
###rever dados DMG com meu N
##fazer o join e recontar
N<-read.xlsx("C:/Users/miele/Dropbox/DOUTORADO/BANCO DE DADOS/Dados/N.xlsx", "Plan1")
DMG1 <- as.data.frame(DMG1)
DMG2 <- N %>% left_join(DMG1, by = "ID")
DMG2 <- DMG2[ ,-3]
###recontagem com meu N
###montar tabela com banco DMG1
###verificar diferenças
DMG2 %>% count(DMG2$Caso_DMG, DMG2$centro, sort = TRUE)
summary(DMG2$Caso_DMG)
table(DMG2$Caso_DMG, DMG2$centro)
barplot(table(DMG2$Caso_DMG))
write.xlsx(DMG2,"C:/Users/miele/Dropbox/DOUTORADO/BANCO DE DADOS/Dados/DMG_final.xlsx")
##############repetir a conferencia para prematuro
###conferencia para PTB
PTB <- SAMBA_banco_final_26_01_19_testeMAJU
PTB %>% count(PTB$Nasc_IGs, PTB$Centro, PTB$ID, sort = TRUE)
##selecionar por centro
#selecionando as variaveis de interesse
PTB1 <- PTB %>% select(Centro, Nasc_IGs, ID, Centro)
###condensando centros
PTB1$Centro <- gsub ("UNICAMP", "SE", PTB1$Centro)
PTB1$Centro <- gsub ("UNESP", "SE", PTB1$Centro)
PTB1$Centro <- gsub ("UFRGS", "SE", PTB1$Centro)
PTB1$Centro <- gsub ("MEAC", "NE", PTB1$Centro)
PTB1$Centro <- gsub ("UFPE", "NE", PTB1$Centro)
###filtrar os nascidos <37 e >==37
PTB38 <- filter(PTB1, Nasc_IGs>=37) %>% view
PTB37 <- filter(PTB1, Nasc_IGs<37) %>% view
summary(PTB37)
summary(PTB38)
table(PTB37$Centro, PTB37$Nasc_IGs)
table(PTB38$Centro, PTB38$Nasc_IGs)
barplot(table(PTB37$Nasc_IGs, PTB37$Centro))
###Unir as duas variaveis prematuro e não prematuro
PTBunion <- union(PTB37,PTB38)
###rever dados DMG com meu N
##fazer o join e recontar
N<-read.xlsx("C:/Users/miele/Dropbox/DOUTORADO/BANCO DE DADOS/Dados/N.xlsx", "Plan1")
PTBunion <- N %>% left_join(PTBunion, by = "ID")
###recontagem com meu N
###montar tabela com banco DMG1
###verificar diferenças
PTBunion %>% filter (Nasc_IGs <37)
PTBunion %>% count (Nasc_IGs <37, by= "Centro")
##separar as colunas de acordo com o nascimento
PTBunion <- as.tibble(PTBunion)
#cria objeto novo "combinando" (Posso fazer Atalah aqui)
combinando<- mutate(PTBunion, Nascimento = if_else(Nasc_IGs<37, "prematuro","termo"))
###formar nova coluna para
summary(PTBunion$Nasc_IGs)
table(PTBunion$Nasc_IGs, PTBunion$Centro)
#Exportar as tabelas
write.xlsx(PTBunion,"C:/Users/miele/Dropbox/DOUTORADO/BANCO DE DADOS/Dados/PTB_final.xlsx")
write.xlsx(combinando,"C:/Users/miele/Dropbox/DOUTORADO/BANCO DE DADOS/Dados/PTBcombinado.xlsx")
##############repetir a conferencia para SGA
SGA <- SAMBA_banco_final_26_01_19_testeMAJU
SGA %>% count(SGA$Caso_RCIU, SGA$ID, SGA$Centro, sort = TRUE)
##selecionar por centro
#selecionando as variaveis de interesse
SGA1 <- SGA %>% select(Centro, Caso_RCIU, ID, Centro)
###condensando centros
SGA1$Centro <- gsub ("UNICAMP", "SE", SGA1$Centro)
SGA1$Centro <- gsub ("UNESP", "SE", SGA1$Centro)
SGA1$Centro <- gsub ("UFRGS", "SE", SGA1$Centro)
SGA1$Centro <- gsub ("MEAC", "NE", SGA1$Centro)
SGA1$Centro <- gsub ("UFPE", "NE", SGA1$Centro)
###conferir
summary(SGA1)
table(SGA1$Centro, SGA1$Caso_RCIU)
barplot(table(SGA1$Caso_RCIU, SGA1$Centro))
###rever dados DMG com meu N
##fazer o join e recontar
N<-read.xlsx("C:/Users/miele/Dropbox/DOUTORADO/BANCO DE DADOS/Dados/N.xlsx", "Plan1")
SGA1 <- N %>% left_join(SGA1, by = "ID")
###recontagem com meu N
SGA1 %>% filter (Caso_RCIU == "Sim")
SGA1 %>% count (Caso_RCIU == "sim", by= "Centro")
table(SGA1$Centro, SGA1$Caso_RCIU)
barplot(table(SGA1$Caso_RCIU, SGA1$Centro))
#Exportar as tabelas
write.xlsx(SGA1,"C:/Users/miele/Dropbox/DOUTORADO/BANCO DE DADOS/Dados/SGA1_final.xlsx")
##############repetir a conferencia para Preemclampsia (PE)
PE <- SAMBA_banco_final_26_01_19_testeMAJU
PE %>% count(PE$Caso_PE, PE$ID, PE$Centro, sort = TRUE)
##selecionar por centro
#selecionando as variaveis de interesse
PE1 <- PE %>% select(Centro, Caso_PE, ID, Centro)
###condensando centros
PE1$Centro <- gsub ("UNICAMP", "SE", PE1$Centro)
PE1$Centro <- gsub ("UNESP", "SE", PE1$Centro)
PE1$Centro <- gsub ("UFRGS", "SE", PE1$Centro)
PE1$Centro <- gsub ("MEAC", "NE", PE1$Centro)
PE1$Centro <- gsub ("UFPE", "NE", PE1$Centro)
#Mesclar com meu N
PE1 <- N %>% left_join(PE1, by = "ID")
###conferir
summary(PE1)
table(PE1$Centro, PE1$Caso_PE)
barplot(table(PE1$Caso_PE, PE1$Centro))
#Graficos rapidos, testar dados
#Histograma uma dimensão
qplot(x=Caso_PE,data=BDfinal)
qplot(x=IdadeMae,data=BDfinal)
qplot(x=Altura_v1,data = BDfinal)
qplot(x=Nasc_peso,data=BDfinal)
#fica sem limite separando as barras
qplot(x=Caso_PE,data=BDfinal,geom="histogram")
###rever dados DMG com meu N
##fazer o join e recontar
N<-read.xlsx("C:/Users/miele/Dropbox/DOUTORADO/BANCO DE DADOS/Dados/N.xlsx", "Plan1")
SGA1 <- N %>% left_join(SGA1, by = "ID")
###recontagem com meu N
SGA1 %>% filter (Caso_RCIU == "Sim")
SGA1 %>% count (Caso_RCIU == "sim", by= "Centro")
table(SGA1$Centro, SGA1$Caso_RCIU)
barplot(table(SGA1$Caso_RCIU, SGA1$Centro))
#Exportar as tabelas
write.xlsx(PE1,"C:/Users/miele/Dropbox/DOUTORADO/BANCO DE DADOS/Dados/Desfecho/PE1_final.xlsx")
##############repetir a conferencia para Peso da Placenta
Placenta <- SAMBA_banco_final_26_01_19_testeMAJU
##selecionar por centro
#selecionando as variaveis de interesse
Placenta <- Placenta %>% select(Centro, Parto_plac, ID, Centro)
###condensando centros
Placenta$Centro <- gsub ("UNICAMP", "SE", Placenta$Centro)
Placenta$Centro <- gsub ("UNESP", "SE", Placenta$Centro)
Placenta$Centro <- gsub ("UFRGS", "SE", Placenta$Centro)
Placenta$Centro <- gsub ("MEAC", "NE", Placenta$Centro)
Placenta$Centro <- gsub ("UFPE", "NE", Placenta$Centro)
#Mesclar com meu N
Placenta <- N %>% left_join(Placenta, by = "ID")
###conferir
summary(Placenta)
table(Placenta$Centro, Placenta$Parto_plac)
barplot(table(Placenta$Parto_plac, Placenta$Centro))
###rever dados DMG com meu N
##fazer o join e recontar
N<-read.xlsx("C:/Users/miele/Dropbox/DOUTORADO/BANCO DE DADOS/Dados/N.xlsx", "Plan1")
Placenta <- N %>% left_join(Placenta, by = "ID")
###recontagem com meu N
summarise(Placenta)
summary(Placenta)
#filtrar "Region"
PlacentaNE <- filter(Placenta,Centro == "NE") %>% view
PlacentaSE <- filter(Placenta,Centro == "SE") %>% view
summary(PlacentaNE$Parto_plac)
summary(PlacentaSE$Parto_plac)
sd(PlacentaNE$Parto_plac)
sd(PlacentaSE$Parto_plac)
#Exportar as tabelas
write.xlsx(Placenta,"C:/Users/miele/Dropbox/DOUTORADO/BANCO DE DADOS/Dados/Desfecho/Placenta_final.xlsx")
###############conferir desfechos
#preparando dados da coluna e desvio padrão
#2 colunas criadas
TabelaRN <- BDfinal %>% group_by(centro) %>% summarise(media = mean(Altura_m), desvio = sd (Altura_m))
##########roda e já forma uma tabela
view(TabelaRN)
#cria um dataframe com essa formula, assim toda a vez a formula está pronta e não precisa repetir
gr <- ggplot(gr)
######medidas de dispersão
##amplitude subtrai o maximo do minimo
max(BDfinal$Caso_PE
)-min(BDfinal$Caso_PE)