Skip to content

Commit

Permalink
pca: fix impute_method logic so None means all 0s
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacovercast committed Sep 23, 2024
1 parent eb76f41 commit 65b5b09
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions ipyrad/analysis/pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def __init__(
index=self.names, columns=["missing"])

# impute missing data
if (self.impute_method is not None) and self._mvals:
if self._mvals:
self._impute_data()


Expand Down Expand Up @@ -229,11 +229,16 @@ def _impute_data(self):
self.snps = self._impute_kmeans(
self.topcov, self.niters, self.quiet)

else:
#self.snps[self.snps == 9] = 0
elif self.impute_method == "random":
missing = self.snps == 9
self.snps[self.snps == 9] = 0
self.snps[missing] += np.random.choice([0,1,2], self.snps.shape)[missing].astype(np.uint64)
self._print(
"Imputation (Random; sets to ~U[0,1,2]): {:.1f}%, {:.1f}%, {:.1f}%"
.format(33.3, 33.3, 33.3)
)

else:
self.snps[self.snps == 9] = 0
self._print(
"Imputation (null; sets to 0): {:.1f}%, {:.1f}%, {:.1f}%"
.format(100, 0, 0)
Expand Down

0 comments on commit 65b5b09

Please sign in to comment.