mardi 9 mars 2021

weighting after conditional count and proportion on multiple columns in R

I would like to weight diseases prevalences (proportions) using a reference population (metro_prop). I have this dataframe and I don't know and to process with multiple columns (i = 1:4).

Here is an example of the dataframe (not real one).

i = 1:4 persons of the household
columns Ai = age
columns Si = sexe
columns Di = disease (1=yes)

  ID A1 A2 A3 A4 S1 S2 S3 S4 D1 D2 D3 D4
1 ID1 58 75  1 24  F  F  F  M  1  0  1  1
2 ID2 51 12 51  8  M  M  M  M  0  0  0  1
3 ID3  5 44 65 81  F  M  M  F NA  0  1  1
4 ID4 88  2 15 32  M  M  F  M  1  1 NA  0
5 ID5 16 81 88  5  F  F  F  M  0  1  0  0
6 ID6 24  4 12 86  F  F  F  F  0  1  0  0

and I would like to get the following outputs per combinations of age/gender categories (Comb)

D_eff is the effective of disease = 1
D_prop is a proportion of disease = 1
metro_prop is the reference distribution (already have)
D_std is D_prop*metro_pro

                Comb metro_prop D1_eff D1_prop D1_std D2_eff D2_prop D2_std D3_eff D3_prop D3_std D4_eff D5_prop D6_std
1         Men[18,25)       0.08     NA      NA     NA     NA      NA     NA     NA      NA     NA     NA      NA     NA
2         Men[25,35)       0.03     NA      NA     NA     NA      NA     NA     NA      NA     NA     NA      NA     NA
3         Men[35,45)       0.12     NA      NA     NA     NA      NA     NA     NA      NA     NA     NA      NA     NA
4   Men[45 and more)       0.07     NA      NA     NA     NA      NA     NA     NA      NA     NA     NA      NA     NA
5       Women[18,25)       0.06     NA      NA     NA     NA      NA     NA     NA      NA     NA     NA      NA     NA
6       Women[25,35)       0.01     NA      NA     NA     NA      NA     NA     NA      NA     NA     NA      NA     NA
7       Women[35,45)       0.05     NA      NA     NA     NA      NA     NA     NA      NA     NA     NA      NA     NA
8 Women[45 and more)       0.08     NA      NA     NA     NA      NA     NA     NA      NA     NA     NA      NA     NA

Thank you very much for you help

Aucun commentaire:

Enregistrer un commentaire