0

Trying to use statsmodels in Python for a 2 way ANOVA and getting a PatsyError (Tried using pingouin as well, also posted about that issue in another post). Here is my code where param is a variable I define earlier and data_rostral is my data frame:

for param in params:
print(param)

model = ols('param ~ C(ShamBlast) + C(RostralCaudal)+C(ShamBlast):C(RostralCaudal)', data=data_rostral).fit()
anova_table = sm.stats.anova_lm(model, typ=2)
anova_table

Here is the error I am getting:

PatsyError: Number of rows mismatch between data argument and param (23 versus 1)
    param ~ C(ShamBlast) + C(RostralCaudal)+C(ShamBlast):C(RostralCaudal)

Tried being less fancy and using totalcells instead of param, which is one of the dependent variables defined by param, thinking I would calculate each ANOVA separately, but then got a ValueError.

    60             raise ValueError("wrong shape for coefs")
     61         if self.coefs.shape[0] == 0:
---> 62             raise ValueError("must have at least one row in constraint matrix")
     63         if self.coefs.shape[0] != self.constants.shape[0]:
     64             raise ValueError("shape mismatch between coefs and constants")

ValueError: must have at least one row in constraint matrix

TIA, I know there are other posts similar to this, but I couldn't figure out how those suggestions applied to my code.

Subbu VidyaSekar
  • 2,503
  • 3
  • 21
  • 39
Kat
  • 1

0 Answers0