Test Coefficient for positivity in linear model

61 views
Skip to first unread message

Leander Kurscheidt

unread,
Sep 29, 2021, 1:11:19 PM9/29/21
to pystatsmodels
Hello,

I have a linear model of the shape Response ~ factor1 + C(factor2) + factor3. Factor2 is a Boolean (True, False).

I want to test whether C(factor2)[T.True] is greater than zero, so I perform:

model = smf.ols(formula='Response ~ factor1 + C(factor2) + factor3', data=df)
res = model.fit()

my statistics knowledge is a bit rusty, but I am pretty sure a one-tailed t-test is the correct thing to do. So I try:

res.t_test("C(factor2)[T.True] > 0")

but I get:

PatsyError: unrecognized token in constraint C(factor2)[T.True] > 0

What am I doing wrong?

Thanks,
Leander

josef...@gmail.com

unread,
Sep 29, 2021, 1:35:56 PM9/29/21
to pystatsmodels
Nothing wrong. One sided alternatives are unfortunately still not supported in the models.

However a hypothesis like  "C(factor2)[T.True] > 0"   wouldn't be clear

The null hypothesis needs to include the boundary point. That's where it will be evaluated.
What we want to show should be the alternative.

for example
H0: b <= 0
H1: b > 0

which is in this case equivalent to 

H0: b = 0
H1: b > 0

Or flip inequality signs to show the opposite, i.e. reject if b < 0.

What you can do if your parameter estimate is on the appropriate side (*), is to double the two-sided pvalue.
(*) I don't remember right now whether the appropriate side is positive or negative

or you double alpha, and check whether the confidence interval does not include zero and is on the side that you want, i.e. positive.

Josef
 

Thanks,
Leander

--
You received this message because you are subscribed to the Google Groups "pystatsmodels" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pystatsmodel...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pystatsmodels/97db9677-1fa6-422c-868a-9a046ca3b54dn%40googlegroups.com.

Leander Kurscheidt

unread,
Sep 30, 2021, 12:42:30 PM9/30/21
to pystatsmodels
Thats unfortunate but thank you. Checking the "greater or equal" hypothesis would also be fine...

I think I get what you mean with the two-sided pvalue, but I am unsure how to do that in statsmodels

Reply all
Reply to author
Forward
0 new messages