Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if permute:
perm_dat = dat.copy()
dv_var = self.formula.split("~")[0].strip()
grp_vars = list(self.grps.keys())
perms = []
for i in range(permute):
perm_dat[dv_var] = perm_dat.groupby(grp_vars)[dv_var].transform(
lambda x: x.sample(frac=1)
)
if self.family == "gaussian":
perm_obj = lmer.lmer(self.formula, data=perm_dat, REML=REML)
else:
perm_obj = lmer.glmer(
self.formula, data=perm_dat, family=_fam, REML=REML
)
perms.append(_return_t(perm_obj))
perms = np.array(perms)
pvals = []
for c in range(df.shape[0]):
if self.family in ["gaussian", "gamma", "inverse_gaussian"]:
pvals.append(_perm_find(perms[:, c], df["T-stat"][c]))
else:
pvals.append(_perm_find(perms[:, c], df["Z-stat"][c]))
df["P-val"] = pvals
if "DF" in df.columns:
df["DF"] = [permute] * df.shape[0]
df = df.rename(columns={"DF": "Num_perm", "P-val": "Perm-P-val"})
else:
df["Num_perm"] = [permute] * df.shape[0]
df = df.rename(columns={"P-val": "Perm-P-val"})
if "P-val" in df.columns: