Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding planned contrasts #219

Open
rnesti opened this issue Dec 13, 2021 · 2 comments
Open

Adding planned contrasts #219

rnesti opened this issue Dec 13, 2021 · 2 comments
Labels
feature request 🚧 New feature or request

Comments

@rnesti
Copy link

rnesti commented Dec 13, 2021

Hi @raphaelvallat,

Could you please add a possibility to test (planned) contrasts ?

Referring to Andy Field's Goggles.sav example from previously:

What I could imagine would be a function planned_contrasts() used like:

pg.planned_contrasts(data = data, dv = "Attractiveness", between = ['Alcohol'], contrasts = [-2,1,1] )

which would compare Placebo vs. Low dose & High dose.

Changing contrasts to [0,-1,1] would copare Low dosis vs. High dosis

Other contrasts would also be cool :)

Thank you very much!

Best regards!

@raphaelvallat
Copy link
Owner

Hi @rnesti,

Thanks for this suggestion. I agree that this would be a useful addition. However, it will take a significant amount of time to implement and test, and it is therefore unlikely to be implemented in Pingouin in the near future. I know that there is a Contrast module in statsmodels, have you looked into it?

Thanks,
Raphael

@rnesti
Copy link
Author

rnesti commented Dec 14, 2021

Hi @raphaelvallat,

You're welcome!

Yes, I know the Contrast site of statsmodels. Sadly, It is also not possible to use the proper contrasts for planned contrasts. To get silimar results to JAMOVI you have to use the Sum contrast in the formula-based statsmodels:

import statsmodels.formula.api as smf

linear_model = smf.ols(" Y ~ C(X1, Sum) * C(X2, Sum)" , data = data) 

However, the problem is that you can't use additional contrasts, so the categoricals are "blocked" with the Sum contrast. A workaround would be to use the models t_test() function and pass it the contrasts like:

linear_model.t_test([2,-1,-1,0,0]) 

But this isn't working, because you are not able to access the reference levels. You could then use -1 to remove the Intercept but then the Intercept will be replaced with the mean of the first factor.

Best regards!

@raphaelvallat raphaelvallat added the feature request 🚧 New feature or request label Feb 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request 🚧 New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants