# Strategy for a one-sided test of GLM's coefficient(s)

Even though there are some great QAs related to this problem in SE such as this and this, I still have problem finding a good strategy for a one-sided test for a regression's coefficient.

To describe the problem properly, let's go by a simple example, consider the following table:

> table
#       not.B   B
# not.A    82  63
# A       456 456


If we were to perform a goodness of fit test, we would for example do:

chisq.test(table, correct = FALSE)

#   Pearson's Chi-squared test
#
# data:  table
# X-squared = 2.1488, df = 1, p-value = 0.1427

> m <- glm(A ~ B, family = binomial())
> summary(m)

# Call:
# glm(formula = A ~ B, family = binomial())
#
# Deviance Residuals:
#     Min       1Q   Median       3Q      Max
# -1.3035  -1.1575  -0.0506   1.1974   1.1974
#
# Coefficients:
#             Estimate Std. Error z value Pr(>|z|)
# (Intercept) -0.04704    0.06695  -0.703   0.4823
# B            0.33875    0.18071   1.874   0.0609 .
# ---
# Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#
# (Dispersion parameter for binomial family taken to be 1)
#
#     Null deviance: 1439.0  on 1037  degrees of freedom
# Residual deviance: 1435.4  on 1036  degrees of freedom
# AIC: 1439.4
#
# Number of Fisher Scoring iterations: 3
#
> anova(m, test="LRT")
# Analysis of Deviance Table
#
#
# Response: A
#
# Terms added sequentially (first to last)
#
#
#      Df Deviance Resid. Df Resid. Dev Pr(>Chi)
# NULL                  1037     1439.0
# B     1    3.546      1036     1435.4  0.05969 .
# ---
# Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> anova(m, test="Rao")
# Analysis of Deviance Table
#
#
# Response: A
#
# Terms added sequentially (first to last)
#
#
#      Df Deviance Resid. Df Resid. Dev    Rao Pr(>Chi)
# NULL                  1037     1439.0
# B     1    3.546      1036     1435.4 3.5352  0.06008 .
# ---
# Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1


For regression A and B are formed as factors (dummy variables). And as you can see they all agree pretty much and the life goes on.

However, what if the alternative hypothesis is $\beta_B\geq0$? If I perform a one-sided t-test (or z test) here is what I get:

> # one-sided (right tail) z test for B
> pnorm(summary(m)$coefficients[2,3], lower.tail = F) #  0.03043157 > > # or a ttest > pt(summary(m)$coefficients[2,3], df=m$df.residual, lower.tail = F) #  0.03057217  But what does this even mean? and if I calculate the 95% confidence interval for$\beta_B$I would get: # with profiling > confint(m) # Waiting for profiling to be done... # 2.5 % 97.5 % # (Intercept) -0.17836773 0.08415021 # B -0.01378692 0.69583308 # Or using the usual formula > summary(m)$coefficients[2,1] + 1.96*summary(m)$coefficients[2,2] #  0.6929479 > summary(m)$coefficients[2,1] - 1.96*summary(m)$coefficients[2,2] #  -0.01545319  Which shows the CI includes zero. Or perhaps I should have calculated the 90% CI (based on this QA): > confint(m, level = 0.90) # 5 % 95 % # (Intercept) -0.15723305 0.06305549 # B 0.04273375 0.63796301  Question: • What does this one-sided significance mean? • If we just wanted to check the relation between B and A, a goodness of fit test would do it. But, what if we also care about the direction of relationship? • Am I allowed to directly perform a one-sided test (just like the weird example above), or I first need to see if the goodness of fit test is significant and then check for the direction? Or simply check the range of CI and based on the sign of coefficient, make decision about the significance and direction of the coefficient? ## 1 Answer What does this one-sided significance mean? I am not sure which "this" you refer to. This test is a one sided Wald test > # one-sided (right tail) z test for B > pnorm(summary(m)$coefficients[2,3], lower.tail = F)
#  0.03043157


which you can reject at 5% level.

> confint(m, level = 0.90)
#                        5 %       95 %
# (Intercept)    -0.15723305  0.06305549
# B               0.04273375  0.63796301


are confidence intervals using the profile likelihood (see this post). Again, the lower bound is above zero so you can reject at 5% level.

If we just wanted to check the relation between B and A, a goodness of fit test would do it. But, what if we also care about the direction of relationship?

You have a two-by-two contingency table with one response variable and one explanatory and large counts in all cells. Thus, assuming that you you have a random or representative sample, you can make a normal approximation. You can do so with

tab <- matrix(c(82, 63, 456, 456), 2,
dimnames = list(c("Not B", "B"), c("not A", "A")))
prop.test(tab, alternative = "greater")
#R>
#R>     2-sample test for equality of proportions with
#R>     continuity correction
#R>
#R>data:  tab
#R>X-squared = 1.8947, df = 1, p-value = 0.08434
#R>alternative hypothesis: greater
#R>95 percent confidence interval:
#R> -0.005585993  1.000000000
#R>sample estimates:
#R>   prop 1    prop 2
#R>0.1524164 0.1213873


• Great answer. Why the one-sided prop.test results in pvalue of 0.08434 while the regression approach's pvalue is about 0.03? What do you recommend in these scenarios? – NULL Feb 28 '18 at 18:41
• Whatever data you used when you estimated the GLM is not the same. The predicted value for group B is 1/(1 + exp(-(-.047+.339))) which is 0.5724857. I.e., not 0.1213873. – Benjamin Christoffersen Feb 28 '18 at 20:08
• Further, sum(tab) is 1057 while the fit has null deviance with 1037 df. – Benjamin Christoffersen Feb 28 '18 at 20:29