6
$\begingroup$

I am doing the logistic regression with logit link in MATLAB

[b, ~, stats] = glmfit(X, [Y N], 'binomial', 'link', 'logit');

I can find the $p$-values for each coefficient in stats, but this tests if a coefficient is equal to 0.

How do I test, say, if the first coefficient is statistically different from the second?

Note that I am asking this from a stats perspective, so the answers are not necessarily MATLAB-specific.

| cite | improve this question | | | | |
$\endgroup$
  • 1
    $\begingroup$ You might do some reading about "linear contrasts", ie, hypotheses of the form $\mathbf C \hat{ \beta} = 0$ for fixed matrix $\mathbf C$. (Your $\mathbf C$ might just be the $1 \times 2$ matrix $\left[-1 \,\, 1 \right]$.) $\endgroup$ – Andrew M May 11 '15 at 6:53
  • $\begingroup$ @AndrewM I do have some experience with contrasts, but I am not sure what distribution would $\beta_1-\beta_2$ follow? $\endgroup$ – Sibbs Gambling May 11 '15 at 7:42
11
$\begingroup$

There's a couple of these questions floating around that essentially have the same answer. There are essentially two approaches to testing what are model constraints.

Given a regression $Y = \beta_0 + \beta_1X_1 + \beta_2X_2 $, you can

1. Modify ("constrain") the regression structure and perform some kind of test

Write out what you want to test and substitute into the regression formula , e.g.
$\beta_1 = \beta_2$
which substitutes in as
$Y = \beta_0 + \beta_1 X_3 $ where $X_3 = X_1 + X_2$

You now have two models, the original and restricted, and you perform a likelihood ratio test between the two. This is the method discussed by @Sid and @Analyst using lratiotest

Alternatively in the same spirit:
$\beta_1 = \beta_2$ equivalent to
$\beta_1 - \beta_2 = 0$ which can be rewritten as
$\beta_1 - \beta_2 = \alpha$
Substitute this back into the original regression formulation
$ Y = \beta_0 + (\alpha + \beta_2) X_1 + \beta_2X_2 $
$ Y = \beta_0 + \alpha X_1 + \beta_2 X_3 $ after rearranging

Here, a test of $\alpha$ is a test of $\beta_1 = \beta_2$ in the original regression. This is the method shown by @Glen_b here.

This method is usable with other hypothesis as well, like $\beta_1 = 0.5$ or $\beta_1 = 3\beta_2$; just substitute as appropriate.

2. Perform what are known as "general linear hypothesis" or "regression Wald tests" after estimation. They have more names, another common one is "linear contrasts", and I've seen others as well.

Once you have your vector of regression coefficients
$\mathbf{B} = [\text{b x 1}] = [\beta_0, \beta_1, \beta_2]'$
and their var-covariance matrix
$\mathbf{V} = [\text{b x b}] = [\text{stuff}]$

You construct a vector defining your hypothesis. So in this case, where we want to test $\beta_1 - \beta_2 = 0$, we have
$H = [\text{1 x b}] = [0,1,-1]$
resulting in a hypothesis of
$HB = [0,1,-1] \times [\beta_0, \beta_1, \beta_2]'$
If you wanted to test against something other than 0, then you would subtract the constant as such $HB - c$

Then you calculate the test statistic
$S = (HB - c)'(HVH')^{-1}(HB -c)$
This is distributed $~\chi^2_1$ for logistic regression (in linear regression, it is an F-statistic).

In MATLAB, it looks like linhyptest is what you want for this.

As with #1, this is usable with any other hypothesis that involve linear combinations of the coefficients. $\beta_1 = 0.5$ or $\beta_1 = 3\beta_2$ fit easily into this framework; construct $H$ and $c$ as appropriate.


I have a preference for the second method. It has the advantage of not requiring refitting a second model, reducing the work in sorting out how the second model should be formulated, especially if you have multiple hypothesis. In addition, multiple hypothesis can be tested jointly as well by "stacking" the $H$ and $c$ vectors, turning $H$ into a $\text{q x b}$ and $c$ into a $\text{q x 1}$, with the resulting test statistic having $q$ degrees of freedom instead of 1.

| cite | improve this answer | | | | |
$\endgroup$
  • 1
    $\begingroup$ (+1) But the Wald statistic is asymptotically distributed as $\chi^2$. Same for the likelihood-ratio test statistic, but the approximation's closer in small samples: speed is the only reason to choose Wald's method (as you say, it involves fitting only one model). $\endgroup$ – Scortchi - Reinstate Monica May 12 '15 at 9:07
  • $\begingroup$ Thanks, Affine! You've answered more than I asked! Is there an authoritative reference (like a book) that mentions "This is distributed χ21 for logistic regression (in linear regression, it is an F-statistic)."? Because I need to reference a source in the paper. :-) $\endgroup$ – Sibbs Gambling Jun 14 '15 at 15:03
  • $\begingroup$ @Scortchi Thanks a lot for the comment! So you mean, if speed is not a concern at all, I better, regardless of linear or logistic regression, adopt the likelihood-ratio test? But computing the likelihood for the linear regression is kinda tricky (not as straightforward as the logistic regression, i.e., binomial, case)... $\endgroup$ – Sibbs Gambling Jun 14 '15 at 15:10
4
$\begingroup$

You can specify two models: 1) Model with parameter restrictions 2) Model without these.

Next you can test via likelihood ratio test if your restricted model should be abandoned in favor of unrestricted one. So null hypothesis is restricted model, which is not accepted but can only be rejected.

Here is link to implementation in MATLAB:

http://se.mathworks.com/help/econ/lratiotest.html

Unfortunately I cannot help you further since I do not have MATLAB software myself.

| cite | improve this answer | | | | |
$\endgroup$
  • $\begingroup$ In this case, the DoF (number of restrictions) should be one, right? In the restricted model, I only impose one restriction. $\endgroup$ – Sibbs Gambling May 11 '15 at 8:26
  • $\begingroup$ At least one solution would be to have an zero element for difference vector of two variables in coefficient vector where you have parameter estimates. This means postulating that both parameter values are same. $\endgroup$ – Analyst May 11 '15 at 10:32
  • $\begingroup$ Sorry, I don't get your sentence, is there a typo somewhere? Thanks $\endgroup$ – Sibbs Gambling May 11 '15 at 10:33
1
$\begingroup$

Questions of this form in hypothesis testing are generally answered by testing the hypothesis that the difference of two parameters is greater than zero. I am not aware of a direct approach, but this is one possibility. Suppose you want to test if $a$ is statistically different from $b$ in

$logit (z) = aX + bY$ ..(1)

fit

$logit(z) = aX + aY$ ..(2)

and compare the fits in (1) and (2) using methods described by @Analyst. If the fits are drastically different, I would conclude the parameters are statistically different

| cite | improve this answer | | | | |
$\endgroup$
0
$\begingroup$

LR test may be similar to F-test in linear regression. If individual coefficients are to be compared, something like t-test may be more relevant.

GLM, if estimated by maximum likelihood estimation, coefficient estimators follow the normal distribution asymtotically and this is why Z-test is normally performed rather than t-test for individual coefficients. Then it'd be quite similar to testing of mean difference.

| cite | improve this answer | | | | |
$\endgroup$
  • $\begingroup$ Can you please elaborate? Thanks! $\endgroup$ – Sibbs Gambling May 11 '15 at 7:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.