I have a dataset with 4 columns. This can take 2 values for now.(1 or 0). There are three columns (X1, X2, X3) with missing data.
Row# X1 X2 X3 Y
1 1 0 0 1
2 0 1 1 0
3 NA 0 0 0
4 1 1 1 0
5 1 NA NA 1
6 1 0 0 1
7 NA NA NA 0
8 0 1 0 1
9 NA NA 1 0
10 0 0 1 1
11 NA NA 0 0
12 0 0 0 0
13 0 0 1 1
14 NA 0 NA 0
What i am interested in creating an filled in dataset for possible values of NA. What i mean by this is creating possible rows of data like this below
Row# X1 X2 X3 Y Probability Comments
1 1 0 0 1 1 No missing
2 0 1 1 0 1 No missing
3 1 0 0 0 0.5 X1 Missing
4 0 0 0 0 0.5 X1 Missing
5 1 1 1 0 1 No missing
6 1 1 0 1 0.25 X1, X2 missing
7 1 0 0 1 0.25 X1, X2 missing
8 1 1 1 1 0.25 X1, X2 missing
9 1 0 1 1 0.25 X1, X2 missing
10 1 0 0 1 1 No missing
11 0 0 0 0 0.125 X1, X2, x3 missing
12 1 0 0 0 0.125 X1, X2, x3 missing
13 0 1 0 0 0.125 X1, X2, x3 missing
14 0 0 1 0 0.125 X1, X2, x3 missing
15 1 1 0 0 0.125 X1, X2, x3 missing
16 1 0 1 0 0.125 X1, X2, x3 missing
17 0 1 1 0 0.125 X1, X2, x3 missing
18 1 1 1 0 0.125 X1, X2, x3 missing
19 . . . . . ......
20 . . . . . ......
21 . . . . . ......
22 . . . . . ......
Please note the final dataset will contain 5 columns (X1,X2,X3,Y,Possibility)
The column Probability is calculated based on this logic.
Let us start with Row1&2 in 1st dataset . The first two rows(1,2) dont have any missing data so in the expected output the same two rows are generated and the probability is 1.
Let us look at Row3 in the original dataset. This has missing value in column X1. So two rows 3,4 are generated in the expected output. Hence probability 0.5, 0.5.
1/2=0.5Let us look at the 5th rows in the original dataset. This contains missing data in column X2 and X3. So this will generate 4 rows in Expected data, row# 6,7,8.9. So probability is 0.25, 0.25,0.25, 0.25,
1/4 = 0.25Row7 of the original dataset has missing values for x1,x2,x3. So this scenario will generate 8 rows, row 11- row 18 in the expected output dataset. Hence the probability 0.125 ,
1/8 = 0.125
I could do this using 8 ifelse statements and for loops. But I am wondering if there is any esier and less messy way to achieve this. Thanks.