Solved – within-subject regression analysis

multiple regressionpythonrrepeated measuresstatsmodels

I have three levels (suppose A,B, and C) in my experiment and wish to do within-subject regression analysis. All the 3 levels are manipulated within-subject.

Also A is outcome category, B is outcome probability and C is outcome delay in milliseconds

I have data in long format with columns for: subject, A,B,C and measure.

I used statsmodels in python with following command:

lm = smf.ols(formula='measure ~ A + B + C + A*B + B*C + C*A + A*B*C', data=data).fit()

But the above formula does not adjust for within-subject condition.

It would very helpful if somebody tell how to solve the problem either in R or python(statsmodels).

Best Answer

Have you considered Mixed effects models? Basically, fitting a random intercept for each person (treating your intercept as itself a random variable), can help to remove the within subjects correlations. In R, lme4 or nlme can do this procedure.

Alternatively, generalized estimating equations will attempt to fit a specified within subjects correlation matrix to your data, and then fit the model.

They're both pretty good.