@@ -547,9 +547,9 @@ def get_predictor_ws(mdata, num_test_var, effective_sz):
547
547
np .random .shuffle (arr )
548
548
549
549
## 3. effective sample size
550
- indx_W_shuffle = arr [:effective_sz ]
550
+ index_W_shuffle = arr [:effective_sz ]
551
551
552
- W_del_shuffle_eff = Ws_del [indx_W_shuffle , :] # the sample size of W should be equal to effective sample size
552
+ W_del_shuffle_eff = Ws_del [index_W_shuffle , :] # the sample size of W should be equal to effective sample size
553
553
return W_del_shuffle_eff .reshape (- 1 , Ws_ncol )
554
554
555
555
@@ -597,11 +597,11 @@ def contain_common_neighbors_prt_mvar(X, Y, condition_set, skel, prt_m):
597
597
598
598
common_neighbor = (X_child == 1 ) & (Y_child == 1 )
599
599
if sum (common_neighbor ) > 0 : # have at least one common neighbor
600
- indx = np .array ([i for i in range (len (Y_child ))])
601
- common_neighbor_indx = indx [common_neighbor ]
600
+ index = np .array ([i for i in range (len (Y_child ))])
601
+ common_neighbor_index = index [common_neighbor ]
602
602
var = [X ] + [Y ] + list (condition_set )
603
603
prt_ls = get_prt_mvars (var , prt_m )
604
- if len (list (set (common_neighbor_indx ) & set (prt_ls ))):
604
+ if len (list (set (common_neighbor_index ) & set (prt_ls ))):
605
605
# at least one common neighbor is the parent of M
606
606
return True
607
607
else : # the common neighbors are not the parent of M
@@ -615,14 +615,14 @@ def get_prt_mvars(var, prt_m):
615
615
:params:
616
616
- var: a list or a tuple
617
617
:return:
618
- - W_indx_ : a list with unique elements
618
+ - W_index_ : a list with unique elements
619
619
"""
620
- W_indx_ = []
620
+ W_index_ = []
621
621
for vi in var :
622
622
if vi in prt_m ['m' ]: # vi has a missingness indicator requiring correction
623
- W_indx_ += get_prt_of_mi (vi , prt_m )
624
- W_indx_ = list (np .unique (W_indx_ ))
625
- return W_indx_
623
+ W_index_ += get_prt_of_mi (vi , prt_m )
624
+ W_index_ = list (np .unique (W_index_ ))
625
+ return W_index_
626
626
627
627
628
628
def get_prt_of_mi (vi , prt_m ):
@@ -633,30 +633,30 @@ def get_prt_of_mi(vi, prt_m):
633
633
return list (prti )
634
634
635
635
636
- def get_prt_mw (W_indx_ , prt_m ):
636
+ def get_prt_mw (W_index_ , prt_m ):
637
637
"""Iteratively get the parents of missingness indicators of W
638
638
:params:
639
- W_indx_ : a list with unique elements
639
+ W_index_ : a list with unique elements
640
640
:return:
641
- W_indx : a list with unique elements
641
+ W_index : a list with unique elements
642
642
"""
643
- W_indx = W_indx_
644
- prt_W = get_prt_mvars (W_indx , prt_m )
645
- stop_cond = list (set (prt_W ) - set (W_indx ))
646
- while len (stop_cond ) > 0 : # There are parents of W_indx
647
- W_indx += prt_W
648
- W_indx = list (np .unique (W_indx ))
649
- prt_W = get_prt_mvars (W_indx , prt_m )
650
- stop_cond = list (set (prt_W ) - set (W_indx ))
643
+ W_index = W_index_
644
+ prt_W = get_prt_mvars (W_index , prt_m )
645
+ stop_cond = list (set (prt_W ) - set (W_index ))
646
+ while len (stop_cond ) > 0 : # There are parents of W_index
647
+ W_index += prt_W
648
+ W_index = list (np .unique (W_index ))
649
+ prt_W = get_prt_mvars (W_index , prt_m )
650
+ stop_cond = list (set (prt_W ) - set (W_index ))
651
651
652
- # No more parents of W_indx outside of the list W_indx
653
- return list (np .unique (W_indx ))
652
+ # No more parents of W_index outside of the list W_index
653
+ return list (np .unique (W_index ))
654
654
655
655
656
656
def test_wise_deletion (data ):
657
657
"""dataset after test-wise deletion"""
658
- indxCompleteRows = get_indx_complete_rows (data )
659
- return data [indxCompleteRows , :]
658
+ indexCompleteRows = get_index_complete_rows (data )
659
+ return data [indexCompleteRows , :]
660
660
661
661
662
662
def learn_regression_model (tdel_data , num_model ):
@@ -699,13 +699,13 @@ def get_sub_correlation_matrix(mvdata):
699
699
matrix: the correlation matrix of all the variables
700
700
sample_size: the sample size of the dataset after test-wise deletion
701
701
"""
702
- indxRows = get_indx_complete_rows (mvdata )
703
- matrix = np .corrcoef (mvdata [indxRows , :], rowvar = False )
704
- sample_size = len (indxRows )
702
+ indexRows = get_index_complete_rows (mvdata )
703
+ matrix = np .corrcoef (mvdata [indexRows , :], rowvar = False )
704
+ sample_size = len (indexRows )
705
705
return matrix , sample_size
706
706
707
707
708
- def get_indx_complete_rows (mvdata ):
708
+ def get_index_complete_rows (mvdata ):
709
709
"""
710
710
Get the index of the rows with complete records
711
711
-------
@@ -718,9 +718,9 @@ def get_indx_complete_rows(mvdata):
718
718
the index of the rows with complete records
719
719
"""
720
720
nrow , ncol = np .shape (mvdata )
721
- bindxRows = np .ones ((nrow ,), dtype = bool )
722
- indxRows = np .array (list (range (nrow )))
721
+ bindexRows = np .ones ((nrow ,), dtype = bool )
722
+ indexRows = np .array (list (range (nrow )))
723
723
for i in range (ncol ):
724
- bindxRows = np .logical_and (bindxRows , ~ np .isnan (mvdata [:, i ]))
725
- indxRows = indxRows [ bindxRows ]
726
- return indxRows
724
+ bindexRows = np .logical_and (bindexRows , ~ np .isnan (mvdata [:, i ]))
725
+ indexRows = indexRows [ bindexRows ]
726
+ return indexRows
0 commit comments