Regression Analysis 5 of 6
On this page

Regression Analysis

4.4 Simple Logistic Regression

Chapter 4 of 5 51 min read

4.4.1.1 Statistical Model

A simple logistic regression model is used for the case of regression with one explanatory variable.

Assume a sample of $n$ independent observations of the terna $(x_i,m_i,y_i),$ $i=1,2,\ldots,n$, where:

  • $x_i$ is the value of the explanatory variable;

  • $m_i$ is the number of items checked in the sample (number of tests);

  • $y_i$ number of occurrence of an event (example: quantity of non-conforming parts) in $m_i$ rehearsals; and

  • $n$ is the sample size.

Therefore, we assume that the response variable has a binomial probability distribution $( Y_i \sim B(m_i,\pi_i))$, such that

$$P[Y_i=y_i]=\binom{m_i}{y_i}\pi_i^{y_i}(1-\pi_i)^{m_i-y_i}.$$

To fit the average response to the linear model, we use the link function

$$\pi(x_i)=\frac{e^{\beta_0+\beta_1x_i}}{1+e^{\beta_0+\beta_1x_i}}, i=1, \ldots, n,$$

which can be written as

$$\ln\left(\frac {\pi_i} {1 - \pi_i}\right)= \beta_0+\beta_1x_i.$$

The following figures illustrate the shape of the logistical model for $\beta_1$ positive and negative.

$$\pi(x_i)=\frac{e^{10-0.1x_i}}{1+e^{10-0.1x_i}}$$

Figura4.4.1

Figure 4.4.1: Logistics model with $\beta_1$ positive.

Figura4.4.2.svg

Figure 4.4.2: Logistics model with $\beta_1$ negative.

In this case, we use the maximum likelihood method to estimate the parameters $(\beta_0 ,\beta_1)$. Generally speaking, the maximum likelihood method provides us with values ​​for the unknown parameters that maximize the probability of obtaining a given set of data.

Assuming that $(x_0, m_0 , y_0), \ldots, (x_n, m_n, y_n)$ are independent, the likelihood function is as follows

$$P [Y=y_1,\ldots,y_n|\beta_0,\beta_1]~=~\prod_{i=1}^n \binom{m_i} {y_i} \pi_i^{y_i}(1-\pi_i)^{m_i-y_i}$$

$$=\prod_{i=1}^n \binom{m_i} {y_i} \pi_i^{y_i}(1-\pi_i)^{m_i}(1-\pi_i)^{-y_i}$$

$$=\prod_{i=1}^n \binom{m_i} {y_i} \frac{\pi_i^{y_i}(1-\pi_i)^{m_i}}{(1-\pi_i)^{y_i}}$$

$$=\prod_{i=1}^n \binom{m_i} {y_i} \left(\frac{\pi_i}{1-\pi_i}\right)^{y_i}{(1-\pi_i)^{m_i}}$$

Ignoring the constant term $\displaystyle\binom{m_i} {y_i},$ which does not depend on $x_i,$ and taking the logarithm $(\ln)$ on both sides of the previous expression, we have

$$L~(\beta_0,\beta_1|(x_i;m_i;y_i))~=~\ln \left(\frac{\pi_i}{1-\pi_i}\right)^{y_i}+\ln {(1-\pi_i)^{m_i}}$$

$$L~(\beta_0,\beta_1|(x_i;m_i;y_i))~=~{y_i} \ln \left(\frac{\pi_i}{1-\pi_i}\right)+ {m_i} \ln(1-\pi_i) \tag{4.1.1.1}$$

Detailing $\ln \left(\displaystyle\frac{\pi_i}{1-\pi_i}\right),$ and considering that,

$$\pi_i~=~\frac{e^{\beta_0+\beta_1 x_i}}{1+e^{\beta_0+\beta_1 x_i}}, \hbox{temos}$$

$$\ln \left(\displaystyle\frac{\pi_i}{1-\pi_i}\right)~=~\ln \left(\displaystyle\frac{\displaystyle\frac{e^{\beta_0+\beta_1x_i}}{1+e^{\beta_0+\beta_1x_i}}}{1-\displaystyle\frac{e^{\beta_0+\beta_1 x_i}}{1+e^{\beta_0+\beta_1 x_i}}}\right)$$

$$=\ln \left(\frac{\displaystyle\frac{e^{\beta_0+\beta_1 x_i}}{1+e^{\beta_0+\beta_1 x_i}}}{\displaystyle\frac{1}{1+e^{\beta_0+\beta_1 x_i}}}\right)$$

Thus, the expression (4.1.1.1) can be rewritten as:

$$L~(\beta_0,\beta_1|(x_i;m_i;y_i))~=~\sum^n_{i=1}\left[ y_i ~\ln \left(\frac{\pi_i}{1-\pi_i} \right)+m_i \ln (1-\pi_i)\right]$$

$$=\sum^n_{i=1}\left[ y_i ~\left(\beta_0 + \beta_1 x_i \right)+ m_i \ln \left(1 - \frac{e^{\beta_0+\beta_1 x_i}}{1+e^{\beta_0+\beta_1x_i}}\right)\right]$$

$$=\sum^n_{i=1}\left[y_i~(\beta_0+\beta_1 x_i)+m_i \ln \left(\frac{1}{1+e^{\beta_0+\beta_1x_i}}\right)\right]$$

$$=\sum^n_{i=1}\left[y_i~(\beta_0+\beta_1 x_i) + m_i (\ln 1 - \ln (1+e^{\beta_0+\beta_1 x_i}))\right]$$

$$=\sum^n_{i=1}y_i~(\beta_0+\beta_1 x_i) - \sum^n_{i=1} m_i \ln (1+e^{\beta_0+\beta_1 x_i})$$

Therefore,

$$L~(\beta_0,\beta_1|(x_i;m_i;y_i))=\sum^n_{i=1}y_i~(\beta_0+\beta_1x_i) - \sum^n_{i=1}m_i \ln (1+e^{\beta_0+\beta_1 x_i}) \tag{4.1.1.2}$$

To simplify the notation we will do $L~(\beta_0,\beta_1|(x_i;m_i;y_i))= L~(\beta_0,\beta_1).$

4.4.1.2 Estimation of model parameters

To fit a regression model we must estimate the parameters $\beta_0$ and $\beta_1$ of the model.

The maximum likelihood estimators for the parameters $\beta_0$ and $\beta_1$ are the values of $\widehat{\beta_0}$ and $\widehat{\beta_1}$ which maximize the logarithm of the likelihood function. The likelihood function has a maximum, since $0 < P[Y_i = y_i \mid x_i] < 1,$ because the logarithm function is strictly increasing.

To maximize the likelihood function, we simply derive it in relation to the model parameters, as follows

$$\frac{\partial}{\partial\beta_0} L(\beta_0,\beta_1)~=~\sum^n_{i=1}y_i-\sum^n_{i=1}{m_i} \frac{e^{\beta_0+\beta_1x_i}}{1+e^{\beta_0+\beta_1x_i}}$$

$$\frac{\partial}{\partial\beta_1} L(\beta_0,\beta_1)~=~\sum^n_{i=1}y_i~x_i-\sum^n_{i=1}{m_i x_i} \frac{e^{\beta_0+\beta_1x_i}}{1 +e^{\beta_0+\beta_1x_i}}$$

Equating these derivatives to zero and substituting the parameters ($\beta_0,\beta_1$) by the estimators $(\widehat{\beta_0},\widehat{\beta_1}),$

$$\sum^n_{i=1}y_i-\sum^n_{i=1}{m_i}\dfrac{e^{\widehat{\beta_0}+\widehat{\beta_1}x_i}}{1+e^{\widehat{\beta_0}+\widehat{\beta_1}x_i}}=0$$

$$\sum^n_{i=1}y_i~x_i-\sum^n_{i=1}{m_i x_i}\dfrac{e^{\widehat{\beta_0}+\widehat{\beta_1}x_i}}{1 +e^{\widehat{\beta_0}+\widehat{\beta_1}x_i}} = 0$$

However, these equations are non-linear in parameters and to solve them it is necessary to resort to interactive numerical methods, such as Newton-Raphson (Gourieroux and Monfort, 1995). This method is defined by expanding the function U($\pmb{\beta}$) around the starting point $\pmb{\beta}^{(0)}$, such that

$$U(\pmb{\beta})\approx U(\pmb{\beta}^{(0)})+U^\prime (\pmb{\beta}^{(0)})(\pmb{\beta}-\pmb{\beta}^{(0)}), \tag{4.1.2.1}$$

where U($\pmb{\beta}$) are the first order derivatives of the logarithm of the likelihood function in relation to the model parameters and $U^\prime (\pmb{\beta}) $ are the order 2 derivatives of the logarithm of the likelihood function.

If we repeat the process (4.1.2.1) we will reach the iterative process

$$\pmb{\beta}^{(m+1)}=\pmb{\beta}^{(m)}+[-U^\prime (\pmb{\beta}^{(m)})]^{-1}U^\prime (\pmb{\beta}^{(m)}),$$

being that $m=0,1,\ldots$

How does the matrix $-U^\prime (\pmb{\beta})$ may not be positive definite, and therefore not invertible, it is replaced by the Fisher information matrix. So

$$\pmb{\beta}^{(m+1)}=\pmb{\beta}^{(m)}+[{-I}(\pmb{\beta}^{(m)})^{-1}]U^\prime (\pmb{\beta}^{(m)}), \quad m=0,1,\ldots \tag{4.1.2.2}$$

The Fisher information matrix, for the logistic model with one variable, has the following form:

$$ I(\widehat{\beta})=- \begin{bmatrix} \dfrac{\partial^2}{\partial\beta_0^2} \ln L(\beta_0,\beta_1) \quad \dfrac{\partial^2}{\partial\beta_0 \beta_1} \ln L(\beta_0,\beta_1) \cr \cr \dfrac{\partial^2}{\partial\beta_0\beta_1} \ln L(\beta_0,\beta_1) \quad \dfrac{\partial^2}{\partial \beta_1^2} \ln L(\beta_0,\beta_1) \end{bmatrix} $$

$$=\begin{bmatrix}\sum\limits_{i=1}^n m_i\dfrac{e^{\beta_0+\beta_1x_i}}{(1+e^{\beta_0+\beta_1x_i})^2}~~\sum\limits_{i=1}^n m_i x_i\dfrac{e^{\beta_0+\beta_1x_i}}{(1+e^{\beta_0+\beta_1x_i})^2} \cr \cr \sum\limits_{i=1}^n m_i x_i \dfrac{e^{\beta_0+\beta_1x_i}}{(1+e^{\beta_0+\beta_1x_i})^2} ~~\sum\limits_{i=1}^n m_i x_i^2\dfrac{e^{\beta_0+\beta_1x_i}}{(1+e^{\beta_0+\beta_1x_i})^2} \end{bmatrix} \tag{4.1.2.3}$$

After obtaining estimates of the model parameters, it is possible to calculate the estimated probabilities

$$\widehat{\pi}_i=\dfrac{e^{\widehat{\beta_0}+\widehat{\beta_1}x_i}}{1+e^{\widehat{\beta_0}+\widehat{\beta_1}x_i}} \tag{4.1.2.4}$$

Example 4.1.2.1

Training was carried out with 30 employees from a specific sector of a company. The objective of the training was to determine the smallest number of hours of training necessary for the smallest number of assembly errors to occur. Table 4.4.1 shows the data collected during training.

Training Hours (X) Assembly Errors (Y) Analyzed Parts (M) Training Hours (X) Assembly Errors (Y) Analyzed Parts (M)
30 2 200 17 9 200
30 2 200 17 10 200
30 2 200 16 10 200
29 2 200 15 11 200
28 3 200 13 11 200
27 4 200 12 12 200
26 5 200 11 12 200
26 5 200 11 12 200
25 6 200 11 13 200
24 6 200 10 13 200
23 8 200 10 13 200
20 8 200 9 13 200
20 8 200 8 13 200
20 8 200 8 14 200
17 9 200 5 14 200

Table 4.4.1: Training Data.

In this example, the explanatory variable is called ($X$), the response variable ($Y$) and ($M$) is the number of trials (repetitions). As these data have a binomial distribution, it is possible to adjust a logistic model.

To estimate the parameters of this model, we used the Newton-Raphson iterative method. As a starting point we consider $ \beta = (\beta_0, \beta_1) = (0,0) $ and using the expression 4.1.2.2, there are the following steps in the iterative process:

[1st] Iteration:

$$\widehat{\beta}= \begin{bmatrix}0 \cr 0 \cr \end{bmatrix}+ \begin{bmatrix}1500 \quad 27400 \cr 27400 \quad 589700 \cr \end{bmatrix}^{-1}\times\begin{bmatrix}-2742 \cr -50994 \cr \end{bmatrix}=\begin{bmatrix}-1,64228866 \cr -0,01016668 \cr \end{bmatrix}$$

[2nd] Iteration:

$$\widehat{\beta}=\begin{bmatrix}-1,64228866 \cr -0,01016668 \cr \end{bmatrix}+\begin{bmatrix}716,4305 \quad 12774,56 \cr 12774,5605 \quad 270061,59 \cr \end{bmatrix}^{-1}\times\begin{bmatrix}-574,4487 \cr -10968,1864 \cr \end{bmatrix}=\begin{bmatrix} -2,13823758 \cr -0,02732075 \cr \end{bmatrix}$$

[3rd] Iteration:

$$\widehat{\beta}=\begin{bmatrix}-2,13823758 \cr -0,02732075 \cr \end{bmatrix}+\begin{bmatrix}379,0670 \quad 6399,839 \cr 6399,8389 \quad 129715,680 \cr \end{bmatrix}^{-1} \times\begin{bmatrix}-149,8268 \cr -3036,3513 \cr \end{bmatrix}=\begin{bmatrix}-2,13856968 \cr -0,05071211 \cr \end{bmatrix}$$

[4th] Iteration:

$$\widehat{\beta}=\begin{bmatrix}-2,13856968 \cr -0,05071211 \cr \end{bmatrix}+\begin{bmatrix}269,9642 \quad 4225,006 \cr 4225,0061 \quad 80422,963 \cr \end{bmatrix}^{-1}\times\begin{bmatrix}-27,2826 \cr -622,3350 \cr \end{bmatrix}=\begin{bmatrix}-2,02583693 \cr -0,06437278 \cr \end{bmatrix}$$

[5th] Iteration:

$$\widehat{\beta}=\begin{bmatrix}-2,02583693 \cr -0,06437278 \cr \end{bmatrix}+\begin{bmatrix}246,7687 \quad 3697,78 \cr 3697,7797 \quad 67728,94 \cr \end{bmatrix}^{-1}\times\begin{bmatrix}-2,370660 \cr -59,028702 \cr \end{bmatrix}=\begin{bmatrix}-2,00685123 \cr -0,06628088 \cr \end{bmatrix}$$

[6th] Iteration:

$$\widehat{\beta}=\begin{bmatrix}-2,00685123 \cr -0,06628088 \cr \end{bmatrix}+\begin{bmatrix}244,5458 \quad 3642,619 \cr 3642,6187 \quad 66355,737 \cr \end{bmatrix}^{-1}\times\begin{bmatrix} -0,03166171 \cr -0,79013813 \cr \end{bmatrix}=\begin{bmatrix}-2,00658851 \cr -0,06630721 \cr \end{bmatrix}$$

The process was interrupted in the 6th iteration, as, from then on, the result stabilized. Thus, for the data in Table 4.4.1, the parameter estimators $\beta=(\beta_0,\beta_1),$ are respectively:

$$\widehat{\beta_0} = -2,0066$$

$$\widehat{\beta_1} = -0,0663$$

The estimator $\widehat{\beta_0}$ is the intercept of the model and $\widehat{\beta_1}$ is the coefficient of the explanatory variable (Training Hours).

The estimated probability of Assembly Errors occurring in relation to Training Hours was obtained from expression 4.1.2.4. These estimates are presented in Table 4.4.2. We can see from Figure 4.4.3 that the greater the number of Training Hours, the lower the probability of error.

Training Hours Error Probability Training Hours Error Probability
30 0,01806045 17 0,04173392
30 0,01806045 17 0,04173392
30 0,01806045 16 0,04446776
29 0,01927472 15 0,04737184
28 0,02056892 13 0,05372869
27 0,02194807 12 0,05720136
26 0,02341749 11 0,06088404
26 0,02341749 11 0,06088404
25 0,02498277 11 0,06088404
24 0,02664982 10 0,06478753
23 0,02842486 10 0,06478753
20 0,03446517 9 0,06892291
20 0,03446517 8 0,07330157
20 0,03446517 8 0,07330157
17 0,04173392 5 0,08801434

Table 4.4.2: Probability of error occurring.

Figura 4.4.3

Figure 4.4.3: Adjusted probability graph.

4.4.1.2.1 Interpretation of model parameters

The interpretation of the parameters of a logistic regression model is obtained by comparing the probability of success with the probability of failure, using the odds ratio - OR function. This function is obtained from the odds function.

$$g(x)=\displaystyle\frac{\pi(x)}{[1-\pi(x)]}=\displaystyle\frac{\displaystyle\frac{e^{\beta_0+\beta_1x_i}}{1+e^{\beta_0+\beta_1x_i}}}{1-\displaystyle\frac{e^{\beta_0+\beta_1x_i}}{1+e^{\beta_0+\beta_1x_i}}}= \displaystyle\frac{\displaystyle\frac{e^{\beta_0+\beta_1x_i}}{1+e^{\beta_0+\beta_1x_i}}}{\displaystyle\frac{1}{1+e^{\beta_0+\beta_1x_i}}}= e^{\beta_0+\beta_1x_i}.$$

Thus, when we take two different values of the explanatory variable, $x_j$ and $x_{j+1}$, we get

$$OR=\frac{g(x_{j+1})}{g(x_{j})}=\frac{e^{\beta_0+\beta_1~x_{j+1}}}{e^{\beta_0+\beta_1~x_{j}}}. \tag{4.1.2.1.1}$$

We also have to:

$$\ln(OR)=\ln\left[\frac{g(x_{j+1})}{g(x_{j+1})} \right]=\ln\left[g(x_{j+1}) \right]-\ln\left[g(x_{j}) \right]$$

$$=\beta_0 + \beta_1 x_{j+1} -\beta_0 -\beta_1 x_{j} = \beta_1(x_{j+1}-x_j).$$

Doing $x_{j+1}-x_j=1$ unit, then $$\ln(OR) = \ln(e^{{\beta_1}})={\beta_1}. $$

Thus, we have how likely the result will occur among individuals $x_{j+1}$ in relation to individuals $x_j$, therefore carrying out some analyses:

$$\beta_1> 0~~\Rightarrow~~ OR> 1 \Rightarrow ~~ \pi(x_{j+1})~~>~~\pi(x_{j})$$

$$\beta_1< 0~~\Rightarrow~~ OR< 1 \Rightarrow ~~ \pi(x_{j+1})~~ <~~\pi(x_{j})$$

See “categorical independent variables” when the explanatory variable is categorical.

Example 4.1.2.1.1

Considering the data and the estimate of $\beta_1$ from Example 4.2.1.1, we will calculate the Odds Ratio. Thus, we have:

$$\text{OR}~(\hat{\beta_1}) = e^{-0,0663} = 0,936.$$

As the Odds Ratio is less than 1, the probability of making Assembly Errors tends to decrease when Training Hours increase.

4.4.1.2.2 Estimation of standard deviations

In the logistic regression model, the standard deviation of the estimators is obtained from the Fisher information matrix. We can also obtain the Fisher information matrix $I(\widehat{\beta})$ for the logistic model from the data, as follows, $I(\widehat{\beta}) = X^{^\prime } V X,$ being that

$$X=\begin{bmatrix}1~~x_{1} \cr 1~~x_{2} \cr \vdots \quad \vdots \cr 1~~x_{n} \cr \end{bmatrix}, {V} = \text{diag}~[m_1 \hat{\pi}_1 (1 - \hat{\pi}_1),\ldots, m_n\hat{\pi}_n (1 - \hat{\pi}_n)],$$

$m_i$ is the number of repetitions for each sample element, $i=1,\ldots,n.$

The variances and covariances of the estimators $\widehat{\beta}=(\widehat{\beta_0}, \widehat{\beta_1})$ are obtained by inverting the Fisher information matrix, that is, calculating $\widehat{\Sigma} = I^{-1}(\widehat{\beta}).$

O $j$-th element of the main diagonal of the matrix $\widehat{\Sigma}$ is the variance of the estimator $\widehat{\beta}_j,$ called $\widehat{\sigma}^2(\widehat{\beta}_j).$ The other elements of the matrix $\widehat{\Sigma}$ are the covariances between $(\widehat{\beta}_j;\widehat{\beta}_u),$ $j\neq u.$

In this way, the standard deviation is defined as: $$\widehat{DP}(\widehat{\beta}_j)= \sqrt{\widehat{\sigma}^2(\widehat{\beta}_j)}.$$

Example 4.1.2.2.1

Let’s consider the data and estimates from Example 4.2.1.1.

To calculate standard deviations, you first need to obtain the matrix $\widehat{\Sigma}=I(\widehat{\beta})^{-1}=(X^\prime V X)^{-1}$

$$X^{^\prime } = \begin{bmatrix}1 \quad 1 \quad 1 \quad 1 \quad 1 \ldots 1 \cr 30 \quad 30 \quad 30 \quad 30 \quad 29\ldots 5 \cr \end{bmatrix}_{(2 \times 30)} \quad \text{e}$$

$${V} = \hbox{diag}~ [200 * 0,01806045 * 0,9819395 ; \ldots ; 200 * 0,08801434 * 0,9119857]$$

$$=\begin{bmatrix}3,546855 \quad 0 \quad \ldots \quad 0 \cr 0 \quad 3,546855 \quad \ldots \quad 0 \cr \vdots \qquad \vdots \qquad \ddots \quad \qquad \vdots \cr 0 \quad 0 \quad \ldots \quad 16,053563 \cr \end{bmatrix}_{(30 \times 30)}$$

therefore the Fisher information matrix will be:

$$I(\widehat{\beta})=\begin{bmatrix}244,5157 \quad 3641,87 \cr 3641,8697 \quad 66337,09 \cr \end{bmatrix}$$

and the matrix of variances and covariances:

$$\Sigma=\begin{bmatrix}0,022432 \quad -0,001232 \cr -0,001232 \quad 0,000083 \cr \end{bmatrix}$$

From the matrix $\Sigma$ we conclude that the estimates of the standard deviations of the estimators $\widehat{\beta}=(\widehat{\beta_0},\widehat{\beta_1}),$ are:

$$\widehat{{DP}}(\widehat{\beta_0}) = \sqrt{\widehat{\sigma}^2(\widehat{\beta_0})}= \sqrt{0,022432}=0,1498$$

$$\widehat{{DP}}(\widehat{\beta_1})=\sqrt{\widehat{\sigma}^2(\widehat{\beta_1})} = \sqrt{0,000083} =0,0091.$$

4.4.1.3 Inference in a simple logistic model

After estimating the coefficients, we are interested in ensuring the significance of the variables in the model. This generally involves formulating and testing a statistical hypothesis to determine whether the independent variable in the model is significantly related to the response variable. For this, we have hypothesis tests. The most commonly used hypothesis tests are the Likelihood Ratio, Wald and Score tests. Below, we have an approach to each of them.

4.4.1.3.1 Wald test

The Wald test is obtained by comparing the maximum likelihood estimate of the parameter ($\widehat{\beta_1}$) and the estimate of its standard error. The resulting ratio, under the hypothesis $\text{H}_0:~\beta_1=0,$ has a standard normal distribution.

The Wald test statistic for logistic regression is $W_j=\displaystyle\frac{\widehat{\beta_1}}{\widehat{DP}(\widehat{\beta_1})}.$

The p-value is defined as

$$\text{p-valor}=\mathbb{P}[|Z|>|W_j||H_0]=2\mathbb{P}[Z>|W_j||H_0],$$

where Z denotes the random variable of the standard normal distribution.

Hauck and Donner (1977) examined performance on the Wald test and found that it behaves strangely in certain situations; often not rejecting the null hypothesis when the coefficient is significant. They recommend using the likelihood ratio test to test whether the coefficient is actually not significant when the Wald test does not reject the null hypothesis.

Example 4.1.3.1.1

Let’s now test whether the parameters in Example 4.2.1.1 are significant for the model. To do this, we need the standard deviation values ​​calculated in Example 4.1.2.2.1.

The values of the Wald test statistic for the hypotheses ${H}_0:\beta_j=0$ and ${H}_1:\beta_j \neq 0,$ $j=0,1,$ are:

$$W_0=\frac{\widehat{\beta_0}}{\widehat{DP}(\widehat{\beta_0})}=\frac{-2,0065}{0,149772}= -13,397$$

$$W_1=\frac{\widehat{\beta_1}}{\widehat{DP}(\widehat{\beta_1})}=\frac{-0,0663}{0,009092}= -7,291$$

For these hypotheses, the p values are:

For $\widehat{\beta_0} = P(|Z|> 13,396) = 0,000.$

For $\widehat{\beta_1} = P(|Z|> 7,29) = 0,000.$

As the p-value is less than the significance level $\alpha = 0,05$ in both cases, we conclude that the parameters $\beta_0$ and $\beta_1$ are significant in the model.

4.4.1.3.2 Likelihood Ratio Test

In linear regression, the interest is in the value of the SQR. A high value of the SQR suggests that the independent variable is important, otherwise the independent variable is not useful in predicting the response variable.

In logistic regression the idea is the same: compare the observed values ​​of the response variable with the predicted values ​​obtained from models with and without the variable in question. The comparison of observed with predicted values ​​is based on the log likelihood. To better understand this comparison, it is useful to think of an observed value of the response variable as also being a predicted value resulting from a saturated model. A saturated model is one that contains as many parameters as observations.

The comparison of the observed with the predicted values using the likelihood function is based on the following expression:

$$D=-2ln\frac{\hbox{(verossimilhança do modelo ajustado)}}{\hbox{(verossimilhança do modelo saturado)}}.$$

For the purpose of ensuring the significance of an independent variable, we compare the value of D with and without the variable in the equation. The change in D due to the inclusion of the variable in the model is obtained as follows: $$G=D \hbox{(modelo~sem~a~variável)} - D \hbox{(modelo~com~a~variável)}.$$

We can then write the G statistic as:

$$G=-2ln\frac{\hbox{(verossimilhança sem a variável)}}{\hbox{(verossimilhança com a variável)}}.$$

or even: $$G=-2ln(L_s)+2ln(L_c),$$

in which $L_s$ is the likelihood of the model without the covariate and $L_c$ is the likelihood of the model with the covariate.

We want to test:

$$\begin{cases} H_{0}:\beta_1=0 \cr H_1:\beta_1\neq 0 \end{cases}$$

Under the null hypothesis, the statistic $G$ It has a chi-square distribution with 1 degree of freedom.

Example 4.1.3.2.1

Let’s consider Example 4.1.2.1 to check whether the variable “training hours” is significant in explaining the assembly error, through the likelihood ratio test (TRV).

The log-likelihood value of the model with just the intercept ($L_s$) is -1064.183 and the model with the variable ($L_c$) is -1035.089.

Thus, the value of the test statistic is:

$$G=-2(-1064,183)-(-2(-1035,089))= 58,188.$$

The p-value $P(\chi^{2}_{1}>\ G=58,188)< 0,0001$.

We reject the null hypothesis. Thus, using the TRV, we have that the training hours variable is significant for the model

4.4.1.3.3 Test Score

The test statistic for the Test Score is:

$$ST=\frac{\displaystyle\sum_{i=1}^{n}x_i(y_i-\bar{y})}{(\overline{y}(1-\overline{y})\displaystyle\sum_{i=1}^{n}(x_i-\bar{x})^2)^{1/2}},$$

in which $\bar{y}=\hat{\pi}$ (proportion of successes in the sample).

At Test Score we are also interested in testing:

$$\begin{cases} H_{0}:\beta_1=0 \cr H_1:\beta_1\neq 0 \end{cases} $$

The p-value is defined as $P(|Z|> |ST|)$, where Z denotes the random variable of the standard normal distribution.

4.4.1.4 Confidence Intervals

4.4.1.4.1 Confidence Interval for parameters

The basis for constructing the confidence interval estimates for the parameters is the same statistical theory that we use for the model significance tests. In particular, a confidence interval for the slope and intercept are based on their respective Wald tests. The confidence interval of $100(1-\alpha)$% for parameter $\beta_1$ is:

$$IC(\beta_1,1-\alpha)= [\hat{\beta_1}-z_{1-\alpha/2}DP(\hat{\beta_1}); \quad \hat{\beta_1}+z_{1-\alpha/2}DP(\hat{\beta_1})].$$

And for the intercept:

$$IC(\beta_0,1-\alpha)= [\hat{\beta_0}-z_{1-\alpha/2}DP(\hat{\beta_0}); \quad \hat{\beta_0}+z_{1-\alpha/2}DP(\hat{\beta_0})],$$

in which $z_{1-\alpha/2}$ is the point of the standard normal corresponding to $100(1-\alpha/2)$%.

4.4.1.4.2 Confidence Interval for Logito

The logit is the linear part of the logistic regression model. The estimator for logit is: $$\hat{g}(x)=\hat{\beta_0}+\hat{\beta_1}x.$$

The variance estimator of the logit estimator requires obtaining the variance of the sum. In this case it is:

$$\hat{Var}[\hat{g}(x)]=\hat{Var}(\hat{\beta_0})+x^2\hat{Var}(\hat{\beta_1})+2x\hat{Cov}(\hat{\beta_0},\hat{\beta_1}). \tag{4.1.4.2.1}$$

The confidence interval for logit is: $$IC(g(x),1-\alpha)= [\hat{g}(x)-z_{1-\alpha/2}DP(\hat{g}(x)); \quad \hat{g}(x)+z_{1-\alpha/2}DP(\hat{g}(x))],$$

in which $DP(\hat{g}(x))$ is the square root of 4.1.4.2.1 and $z_{1-\alpha/2}$ is the point of the standard normal.

4.4.1.4.3 Confidence Interval for adjusted values

The logit estimator and its confidence interval provide the estimator of the fitted values. The confidence interval of the adjusted values is given by:

$$IC(\pi,1-\alpha)= \left[\dfrac{e^{\hat{g}(x)-z_{1-\alpha/2}DP(\hat{g}(x))}}{1+e^{\hat{g}(x)-z_{1-\alpha/2}DP(\hat{g}(x))}}; \quad \dfrac{e^{\hat{g}(x)+z_{1-\alpha/2}DP(\hat{g}(x))}}{1+e^{\hat{g}(x)+z_{1-\alpha/2}DP(\hat{g}(x))}}\right]. \tag{4.1.4.2.2}$$

4.4.1.4.4 Confidence Interval for the Odds Ratio

Let the limits of the confidence interval be $\beta_1$:

$\beta_{I}=\hat{\beta_1}-z_{1-\alpha/2}DP(\hat{\beta_1})$ and $\beta_{S}=\hat{\beta_1}+z_{1-\alpha/2}DP(\hat{\beta_1}).$

The confidence interval for the Odds Ratio is:

$$IC(\hbox{Odds Ratio},1-\alpha)= [e^{\beta_{I}}; \quad ~e^{\beta_{S}}]. \tag{4.1.4.2.3}$$

Example 4.1.4.1

We will construct a Wald confidence interval for $\beta_0$ and $\beta_1$ considering parameter estimates and their standard deviations already calculated in examples 4.1.2.1 and 4.1.2.2.1.

IC for $\beta_0$

$$IC(\beta_0,0,95) = [-2,0066-1,96 * 0,1498; \quad -2,0066+1,96 * 0,1498],$$

$$IC(\beta_0, 0,95)= [-2,0066-0,2936; \quad -2,0066+0,2936],$$

$$IC(\beta_0,0,95)= [-2,3002; \quad -1,713].$$

IC for $\beta_1$

$$IC(\beta_1,0,95)= [-0,0663-1,96 * 0,0091; \quad -0,0663+1,96 * 0,0091].$$

$$IC(\beta_1,0,95)= [-0,0663-0,01783; \quad -0,0663+0,01783].$$

$$IC(\beta_1,0,95)= [-0,08413; \quad -0,04847].$$

Example 4.1.4.2

Let’s construct a 95% confidence interval for the logit.

We consider the first observation, with $X$ (training hours) $=30$. The estimator for the logit is:

$$\hat{g}(x=30)=-2,0066-0,0663 * 30=-3,9956.$$

The variance estimator is:

$$\hat{Var}[\hat{g}(x=30)]=0,022432+900 * 0,000083+60 * (-0,001232)$$

$$\hat{Var}[\hat{g}(x=30)]=0,022432+0,0747-0,07392$$

$$\hat{Var}[\hat{g}(x=30)]=0,022432+0,0747-0,07392$$

$$\hat{Var}[\hat{g}(x=30)]=0,0232$$

Thus, the 95% confidence interval for logit for $x=30$ is:

$$IC(g(x=30),0,95)= [-3,9956-1,96 * 0,1523; \quad -3,9956+1,96 * 0,1523],$$

$$IC(g(x=30),0,95)= [-3,9956-0,2985; \quad -3,9956+0,2985],$$

$$IC(g(x=30),0,95)= [-4,2941; \quad -3,6971],$$

Doing analogously for each value of the explanatory variable, we have in Table 4.4.3 the confidence intervals for the logit.

X Lower Limit Upper Limit
30 -4,294 -3,697
30 -4,294 -3,697
30 -4,294 -3,697
29 -4,212 -3,647
28 -4,130 -3,596
27 -4,048 -3,546
26 -3,966 -3,495
26 -3,966 -3,495
25 -3,885 -3,443
24 -3,804 -3,391
23 -3,724 -3,339
20 -3,489 -3,176
20 -3,489 -3,176
20 -3,489 -3,176
17 -3,266 -3,002
17 -3,266 -3,002
17 -3,266 -3,002
16 -3,195 -2,940
15 -3,127 -2,875
13 -2,999 -2,738
12 -2,938 -2,666
11 -2,880 -2,592
11 -2,880 -2,592
11 -2,880 -2,592
10 -2,823 -2,517
10 -2,823 -2,517
9 -2,767 -2,440
8 -2,713 -2,361
8 -2,713 -2,361
5 -2,554 -2,122

Table 4.4.3: Confidence interval for logit

Example 4.1.4.3

We know from example 4.1.4.2 that the 95% confidence interval for $g(30)$ is $[-4,294; -3,697]$. Thus, using equation 4.1.4.2.2, we have the following confidence interval for the adjusted value:

$$IC(\pi(30),0,95)= \left[\frac{e^{-4,294}}{1+e^{-4,294}}; \quad \frac{e^{-3,697}}{1+e^{-3,697}}\right]$$

$$IC(\pi(30),0,95)= [0,01346; \quad 0,02420]$$

Doing analogously for each value of the explanatory variable, we have in Table 4.4.4 the confidence intervals for the adjusted values.

X Lower Limit Upper Limit
30 0,01346 0,02420
30 0,01346 0,02420
30 0,01346 0,02420
29 0,01460 0,02541
28 0,01583 0,02669
27 0,01716 0,02804
26 0,01859 0,02947
26 0,01859 0,02947
25 0,02013 0,03097
24 0,02179 0,03257
23 0,02356 0,03426
20 0,02963 0,04006
20 0,02963 0,04006
20 0,02963 0,04006
17 0,03677 0,04735
17 0,03677 0,04735
17 0,03677 0,04735
16 0,03934 0,05023
15 0,04199 0,05341
13 0,04748 0,06076
12 0,05030 0,06500
11 0,05317 0,06964
11 0,05317 0,06964
11 0,05317 0,06964
10 0,05612 0,07470
10 0,05612 0,07470
9 0,05913 0,08021
8 0,06223 0,08617
8 0,06223 0,08617
5 0,07213 0,10700

Table 4.4.4: Confidence Interval for adjusted values

Example 4.1.4.4

The 95% confidence interval for the Odds Ratio of the explanatory variable (Training Hours), given by equation 4.1.4.2.3, using the limits of the confidence interval for $\beta_1$ from example 4.1.4.1 is:

$$IC(\hbox{Odds Ratio};0,95)= [\exp(-0,08413); \exp(-0,04847)]$$

$$IC(\hbox{Odds Ratio};0,95)= [0,919; 0,953].$$

4.4.2 Multiple Logistic Regression

We present in Section 4.1 the logistic regression model considering only one explanatory variable. Just like in the linear regression model, we can adjust a model for the response variable taking into account more than one explanatory variable (covariate), which we call the Multiple Logistic Regression Model.

Thus, a multiple logistic regression model is used in the case of regression with more than one explanatory variable.

Consider a set of $p$ independent variables denoted as a vector ${X}=(X_1,X_2,X_3,\ldots,X_p)$. In this case the link function is

$$g(X)=\ln\left(\frac{\pi(X)}{1-\pi(X)}\right) = \beta_0+\beta_1 X_1+\beta_2 X_2 + \ldots + \beta_p X_p \tag{4.2.1}$$

and

$$E[Y]=\pi(X)=\frac{e^{g(X)}}{1+e^{g(X)}}. \tag{4.2.2}$$

4.4.2.1 Estimates of model parameters

To obtain estimates for vector $\beta=(\beta_0,\beta_1,\ldots,\beta_p)$ of the model parameters and the covariance matrix, the maximum likelihood method will be used, as follows:

$$L~(\beta_0,\beta_1,\ldots,\beta_p|(x_i;m_i;y_i))=\sum^n_{i=1} \left[ y_i~ g(X) -m_i \ln (1+e^{g(X)})\right], \tag{4.2.1.1}$$

where g(X) is given by 4.2.1.

Deriving (4.2.1.1) with respect to the parameters, we have:

$$\frac{\partial}{\partial\beta_0} L(\beta_0,\beta_1,\ldots,\beta_p) = \sum^n_{i=1} y_i - \sum^n_{i=1} m_i \frac{e^{g(X)}}{1 + e^{g(X)}}.$$

$$\frac{\partial}{\partial\beta_j} ~L(\beta_0,\beta_1,\ldots,\beta_p)=\sum^n_{i=1} y_i~x_j - \sum^n_{i=1} m_i x_j \frac{e^{g(X)}}{1 + e^{g(X)}}.$$

Equating it to zero and replacing the parameters with estimators, we have the following equations:

$$\sum^n_{i=1}~y_i~(1+ e^{g(X)}) - \sum^n_{i=1}m_i~e^{g(X)} = 0$$

$$\sum^n_{i=1}~y_i~x_i~(1+ e^{g(X)})-\sum^n_{i=1}m_i~x_i~e^{g(X)} = 0$$

The solution of these equations provides estimates of the model parameters, using iterative processes, analogous to the estimation of the parameters of the simple logistic regression model.

After obtaining estimates of the model parameters, we can calculate the adjusted probabilities:

$$\widehat{\pi}_i = \frac{e^{\hat{g}(X_i)}}{1 + e^{\hat{g}(X_i)}},$$

in which

$$\hat{g}(X_i)=\hat{\beta_0}+\hat{\beta_1} X_{1i} + \ldots + \hat{\beta_p} X_{pi}.$$

Example 4.2.1.1:

In a company, iron parts are manufactured and molded in sand molds. Among the pieces produced, those with a large amount of encrusted sand are considered Refuse. Sand Volatility and the RFV coefficient (Resistance to Green Fluid) influence the amount of encrusted sand. Using the data in Table (4.4.5), evaluate the significance of the variables and the interaction between them.

Note Quantity Produced Scrap Volatility RFV
1 832 270 1,906 5,642
2 996 152 1,766 7,63
3 1224 289 1,673 5,253
4 712 2 1,982 5,223
5 2072 11 2 5,064
6 544 14 2,12 5,395
7 700 5 2,085 6,138
8 3840 47 1,97 5,82
9 1940 101 2,15 4,498
10 1005 17 2,37 6,478
11 1260 26 2,37 5,826
12 1815 308 2,597 6,052
13 1340 79 2,44 5,839
14 1485 134 2,473 5,08
15 1585 127 2,493 5,313
16 1095 83 2,43 5,21
17 1370 81 3,42 5,04
18 1405 58 3,607 5,2222

Table 4.4.5: Sand mold data.

The following model is proposed for the example

$$\hbox{Probabilidade de refugo}=\pi_i=\dfrac{e^{\beta_0 + \beta_1 x_1 +\beta_2 x_2+\beta_3 x^2_1 + \beta_4 x^2_2 + \beta_5 x_1x_2}}{1+e^{\beta_0 + \beta_1 x_1 +\beta_2 x_2+\beta_3 x^2_1 + \beta_4 x^2_2 + \beta_5 x_1x_2}}$$

The model parameter estimates are:

$\widehat{\beta_0}$ = 30.3389 (Intercept)

$\widehat{\beta_1}$ = -14.1496 (Volatility)

$\widehat{\beta}_2$ = -6.26927 (RFV)

$\widehat{\beta}_3$ = 1.101 (Quadratic Effect of Volatility)

$\widehat{\beta}_4$ = 0.2819 (Quadratic effect of RFV)

$\widehat{\beta}_5$ = 1.5376 (Interaction between Volatility and RFV)

And the odds ratio estimates, as shown in the case of the simple logistic regression model, are:

$OR(\widehat{\beta_1})$ = $\exp(-14,1496) = 0,00$

$OR(\widehat{\beta}_2)$ = $\exp(-6,26927) = 0,00$

$OR(\widehat{\beta}_3)$ = $\exp(1,101) = 3,01$

$OR(\widehat{\beta}_4)$ = $\exp(0,2819) = 1,33$

$OR(\widehat{\beta}_5)$ = $\exp(1,5376) = 4,65$

The adjusted probability vector is

$$\widehat{\pi} = (0,076; 0,128; 0,131; 0,075; 0,076; 0,061; 0,072; 0,071; 0,068; 0,101; 0,061; 0,081;$$

$ 0,062; 0,040; 0,044; 0,044; 0,043; 0,079).$

4.4.2.1.1 Standard deviation estimation

The method of estimating the variances and covariances of the estimated coefficients follows the theory of maximum likelihood estimation. This theory ensures that the estimators are obtained from the matrix of second partial derivatives of the log-likelihood function. These partial derivatives have the following general form:

$$\frac{\partial^2L(\beta)}{\partial\beta_j^2}=-\sum_{i=1}^nm_ix_{ij}^{2}\pi_i(1-\pi_i). \quad \quad \tag{4.2.1.1.1}$$

$$\frac{\partial^2L(\beta)}{\partial\beta_j\partial\beta_l}=-\sum_{i=1}^nm_ix_{ij}x_{il}\pi_i(1-\pi_i), \quad \tag{ 4.2.1.1.2}$$

for j,l=0,1,…,p where $\pi_i$ simplify $\pi(x_i)$. Let the matrix be $(p+1)\times(p+1)$ which contains the negative terms of (4.2.1.1.1) and (4.2.1.1.2) denoted by $I(\beta)$ which is Fisher information matrix. The variances and covariances of the estimated coefficients are obtained from the inverse of the matrix: $Var(\beta)=I^{-1}(\beta)$. The variance of $\beta_j$, $Var(\beta_j)$, is the $j^{th}$ element of the diagonal of the matrix and the $Cov(\beta_j,\beta_l)$ is obtained through the matrix element referring to the line of $\beta_j$ and column $\beta_l$ or vice versa, since $Cov(\beta_j,\beta_l)=Cov(\beta_l,\beta_j).$ Variance and covariance estimators, $\hat{Var}(\hat{\beta})$, are obtained from $Var(\beta)$ in $\hat{\beta}$.

Furthermore, the estimated Fisher information matrix can be obtained by: $\hat{I}(\hat{\beta})=X^\prime VX$.

$$X=\begin{bmatrix}1 \quad x_{11} \quad \ldots \quad x_{1p} \cr 1 \quad x_{21} \quad \ldots \quad x_{2p} \cr \vdots \cr 1 \quad x_{n1} \quad \ldots \quad x_{np} \cr \end{bmatrix}_{n \times (p+1)} $$

and

$$V= \begin{bmatrix} m_1\widehat{\pi}_1(1-\widehat{\pi}_1) \quad 0 \quad ~~\ldots \quad 0 \cr 0 \quad ~~ m_2\widehat{\pi}_2(1-\widehat{\pi}_2) \quad ~~\ldots \quad 0 \cr \vdots \quad ~~\vdots \quad ~~\ddots \quad ~~\vdots \cr 0 \quad 0 \quad ~~\ldots \quad ~~m_n\widehat{\pi}_n(1-\widehat{\pi}_n) \cr \end{bmatrix}_{n \times n}$$

In this way, the standard deviation of the coefficient $\beta_j$ is: $$\hat{DP}(\hat{\beta}_j)=\sqrt{\hat{Var}(\hat{\beta_j})}. \tag{4.2.1.1.3}$$

Example 4.2.1.1.1

For the data in Example 4.2.1.1, we will calculate the estimate of the standard deviation of each parameter considered in the example in question.

The first step is to obtain the Fisher information matrix, according to 4.1.2.3,

$$X=\begin{bmatrix}1 \quad 1,91 \quad ~5,64 \quad ~3,63 \quad ~31,83 \quad 10,75 \cr 1 \quad 1,77 \quad ~7,63 \quad ~3,12 \quad ~58,22 \quad 13,47 \cr 1 \quad 1,67 \quad ~5,25 \quad ~2,80 \quad ~27,59 \quad ~8,79 \cr 1 \quad 1,98 \quad ~5,22 \quad ~3,93 \quad ~27,28 \quad 10,35 \cr 1 \quad ~2,00 \quad ~5,06 \quad ~4,00 \quad ~25,64 \quad 10,13 \cr 1 \quad ~2,12 \quad ~5,39 \quad ~4,49 \quad ~29,11 \quad 11,44 \cr 1 \quad ~2,08 \quad ~6,14 \quad ~4,35 \quad ~37,68 \quad 12,80 \cr 1 \quad 1,97 \quad ~5,82 \quad ~3,88 \quad ~33,87 \quad 11,47 \cr 1 \quad ~2,15 \quad ~4,50 \quad ~4,62 \quad ~20,23 \quad ~9,67 \cr 1 \quad ~2,37 \quad ~6,48 \quad ~5,62 \quad ~41,96 \quad 15,35 \cr 1 \quad ~2,37 \quad ~5,83 \quad ~5,62 \quad ~33,94 \quad 13,81 \cr 1 \quad ~2,60 \quad ~6,05 \quad ~6,74 \quad ~36,63 \quad 15,72 \cr 1 \quad ~2,44 \quad ~5,84 \quad ~5,95 \quad ~34,09 \quad 14,25 \cr 1 \quad ~2,47 \quad ~5,08 \quad ~6,12 \quad ~25,81 \quad 12,56 \cr 1 \quad ~2,49 \quad ~5,31 \quad ~6,22 \quad ~28,23 \quad 13,25 \cr 1 \quad ~2,43 \quad ~5,21 \quad ~5,90 \quad ~27,14 \quad 12,66 \cr 1 \quad ~3,42 \quad ~5,04 \quad 11,70 \quad ~25,40 \quad 17,24 \cr 1 \quad ~3,61 \quad ~5,22 \quad 13,01 \quad ~27,27 \quad 18,84 \cr \end{bmatrix}_{18 \times 6} $$

$$V=\begin{bmatrix}832\times 0,079518 \times (1 - 0,079518) \quad \quad 0 \quad ~\ldots \quad 0 \cr 0 \quad ~996\times 0,118598 \times (1-0,118598) \quad ~\ldots \quad 0 \cr \vdots \quad \quad \vdots \quad ~\ddots \cr 0 \quad 0 \quad ~\ldots \quad 1405\times 0,047904 \times (1-0,047904) \cr \end{bmatrix}_{18 \times 18}$$

or

$$V= \begin{bmatrix} 58,71 \quad 0 \quad ~\ldots \quad 0 \cr 0 \quad 111,16 \quad ~\ldots \quad 0 \cr \vdots \quad ~\vdots \quad ~\ddots \quad ~\vdots \cr 0 \quad 0 \quad ~\ldots \quad 101,81 \cr \end{bmatrix}_{18 \times 18}$$

$$\Sigma(\beta) = (X' V X)^{-1} =\left[ \begin{array}{ccc}13,47 \quad ~~-4,57 \quad ~~-3,05 \quad ~~ 0,23 \quad ~~ 0,15 \quad ~~ 0,63 \cr -4,57 \quad ~1,84 \quad ~~ 0,93 \quad ~~-0,11 \quad ~~-0,04 \quad ~~-0,23 \cr -3,05 \quad ~~ 0,93 \quad 0,73 \quad ~~-0,04 \quad ~~-0,04 \quad ~~-0,14 \cr 0,23 \quad ~~-0,11 \quad ~~-0,04 \quad 0,01 \quad ~~ 0,00 \quad ~~ 0,01 \cr 0,15 \quad ~~-0,04 \quad ~~-0,04 \quad ~~ 0,00 \quad 0,00 \quad ~~ 0,01 \cr 0,63 \quad ~~-0,23 \quad ~~-0,14 \quad ~~ 0,01 \quad ~~ 0,01 \quad 0,03 \cr \end{array} \right]$$

For $\beta_0=\sqrt{\sigma^2(\widehat{\beta_0})}=\sqrt{13,46607} =3,67$

For $\beta_1=\sqrt{\sigma^2(\widehat{\beta_1})}=\sqrt{1,836394}=1,36$

For $\beta_2=\sqrt{\sigma^2(\widehat{\beta}_2)}=\sqrt{0,731351}= 0,86$

For $\beta_3=\sqrt{\sigma^2(\widehat{\beta}_3)} = \sqrt{0,0104028}=0,10$

For $\beta_4=\sqrt{ \sigma^2(\widehat{\beta}_4)}=\sqrt{0,0021488}=0,05$

For $\beta_5=\sqrt{\sigma^2(\widehat{\beta}_5)}=\sqrt{0,0331131}=0,18$

4.4.2.2 Inference in the multiple logistic regression model

Just like in Inference in a simple logistic regression model, we can test the significance of the parameters using the Wald test, score and Likelihood Ratio (TRV).

4.4.2.2.1 Likelihood Ratio Test

The likelihood ratio test for the significance of the p coefficients of the model’s independent variables is performed in the same way as in the simple logistic regression model. The G test statistic is given by:

$$G=-2ln\left[\frac{\hbox{(verossimilhança sem a variável)}}{\hbox{(verossimilhança com a variável)}}\right].$$

or even:

$$G=-2ln(L_s)+2ln(L_c),$$

in which $L_s$ is the likelihood of the model without the covariate and $L_c$ is the likelihood of the model with the covariate.

In the case of multiple regression, we are interested in knowing whether at least one variable is significant for the model. Under the null hypothesis, the p coefficients are equal to zero, thus the G statistic has a Chi-Square distribution with p degrees of freedom. In that case $L_c$ is the likelihood of the model with the p explanatory variables and $L_s$ is the likelihood of the model with just the intercept.

4.4.2.2.2 Wald test

Let’s consider the following hypothesis:

$$\begin{cases} H_{0}:\beta_j=0 \cr H_1:\beta_j\neq 0 \end{cases} $$

To test the above hypothesis, the Wald statistic is obtained as follows:

$$W_j=\frac{\widehat{\beta}_j}{\widehat{DP}(\widehat{\beta}_j)}. \tag{4.2.2.2.1}$$

where the standard deviation is obtained from (4.2.1.1.3). If we don’t reject $H_0$ we have that the variable $X_j$ does not explain the response variable.

Equivalently, Wald test can also be obtained by multiplying the following vectors:

$$W=\widehat{\beta}^\prime [\widehat{I}(\widehat{\beta})]^{-1}\widehat{\beta}=\widehat{\beta}^\prime (X^\prime V X)\widehat{\beta}.$$

In which $\hat{I}(\beta)$ is the estimated Fisher information matrix, presented in the estimate of the standard deviation of the simple logistic regression model.

Example 4.2.2.1:

For the data in Example 4.2.1.1, we will test the significance of the parameters using the Likelihood Ratio and Wald test.

Remembering that the proposed model is:

$$\hbox{Probabilidade de refugo}=\pi_i=\dfrac{e^{\beta_0 + \beta_1 x_1 +\beta_2 x_2+\beta_3 x^2_1 + \beta_4 x^2_2 + \beta_5 x_1x_2}}{1+e^{\beta_0 + \beta_1 x_1 +\beta_2 x_2+\beta_3 x^2_1 + \beta_4 x^2_2 + \beta_5 x_1x_2}},$$

in which $x_1$ is the Volatility variable and $x_2$ is the variable RFV.

  • TRV (Likelihood Ratio test)

Using TRV, we will first test whether at least one variable is significant for the model. To do this, we need the log likelihood of the models with and without the variables under consideration.

The log likelihood without the variables is -1025.81 and with the variables is -928.15. Thus, the value of the test statistic is:

$$G=-2(-1025,81)-(-2(-928,15))= 195,33.$$

The p-value $P(\chi^{2}_{5}>\ G=195,33)= 0$.

We reject the null hypothesis. Thus, using the TRV, we have that at least one tested variable is significant for the model.

So, we will test each of the variables individually.

  • For the Volatility variable:

The log likelihood without the variables is -982.12 and with the variables is -928.15. Thus, the value of the test statistic is:

$$G=-2(-982,12 )-(-2(-928,15))= 107,94.$$

The p-value $P(\chi^{2}_{1}>\ G=107,94)=0$.

We reject the null hypothesis. Thus, using the TRV, we have that the Volatility variable is significant for the model.

  • For the variable RFV:

The log likelihood without the variables is -954.66 and with the variables is -928.15. Thus, the value of the test statistic is:

$$G=-2(-954,66)-(-2(-928,15))= 58,02.$$

The p-value $P(\chi^{2}_{1}>\ G=58,02)< 0,0001$.

We reject the null hypothesis. Thus, using the TRV, we have that the variable RFV is significant for the model.

  • For the squared volatility variable:

The log likelihood without the variables is -983.77 and with the variables is -928.15. Thus, the value of the test statistic is: $$G=-2(-983,77)-(-2(-928,15))= 111,24.$$

The p-value $P(\chi^{2}_{1}>\ G=111,24)= 0$.

Using the TRV, we reject the null hypothesis and therefore we have that the variable Volatility squared is significant for the model.

  • For the variable RFV squared:

The log likelihood without the variables is -946.26 and with the variables is -928.15. Thus, the value of the test statistic is:

$$G=-2(-946,26)-(-2(-928,15.))= 36,22.$$

The p-value $P(\chi^{2}_{1}>\ G=36,22)< 0,0001$.

Using TRV, we reject the null hypothesis and therefore we have that the variable RFV squared is significant for the model.

  • Volatility Variable * RFV

The log likelihood without the variables is -936.31 and with the variables is -928.15. Thus, the value of the test statistic is:

$$G=-2(-963,31)-(-2(-928,15))= 70,32.$$

The p-value $P(\chi^{2}_{1}>\ G=70,32)= 0$.

Using TRV, we reject the null hypothesis and therefore we have that the interaction of Volatility with RFV is significant for the model.

  • Wald test

The Wald test statistic is given by the expression (4.2.2.2.1), being

$W_0=\cfrac{\widehat{\beta_0}}{\widehat{DP}(\widehat{\beta_0})}=\cfrac{30,3389}{3,66962}= 8,27$

$W_1=\cfrac{\widehat{\beta_1}}{\widehat{DP}(\widehat{\beta_1})}=\cfrac{-14,1496}{1,35514}= -10,44$

$W_2=\cfrac{\widehat{\beta}_2}{\widehat{DP}(\widehat{\beta}_2)}=\cfrac{-6,26927}{0,855191}= -7,73$

$W_3=\cfrac{\widehat{\beta}_3}{\widehat{DP}(\widehat{\beta}_3)}=\cfrac{1,10101}{0,1019943}= 10,79$

$W_4=\cfrac{\widehat{\beta}_4}{\widehat{DP}(\widehat{\beta}_4)}=\cfrac{0,2819}{0,046355}=6,08$

$W_5=\cfrac{\widehat{\beta}_5}{\widehat{DP}(\widehat{\beta}_5)}=\cfrac{1,53769}{0,18197}= 8,45$

The standard deviation estimate used to calculate the Wald statistic is in “Standard Deviation Estimation”.

To assess the significance of the coefficients the following hypotheses are tested

$$\begin{cases} H_0:\beta_j=0 \cr H_1:\beta_j\neq 0\end{cases} \quad j=0,1,2,3,4,5$$

The p-value defined as $P(|Z|> w_j)$, $j=0, 1, 2, 3, 4, 5,$ when Z denotes the random variable of the standard normal distribution.

Thus, we have:

For $\beta_0 = P(|Z| > 8,27) = 0,000$

For $\beta_1 = P(|Z| > 10,44) = 0,000$

For $\beta_2 = P(|Z| > 7,73) = 0,000$

For $\beta_3 = P(|Z| > 10,79) = 0,000$

For $\beta_4 = P(|Z| > 6,08) = 0,000$

For $\beta_5 = P(|Z| > 8,45) = 0,000$

Assessing the p-value for the $\beta_j,$ $j=0,1,2,3,4,5,$ reject $H_0$ at the level of significance $\alpha = 0,05$ and it is concluded that the parameters are significant in the model.

The interaction between the variables and their quadratic effects can be seen in Figure 4.4.4.

Figura4.4.4.png

Figure 4.4.4: Response Surface for the probability of scrap parts.

We verified in Figure 4.4.4 that high values ​​of Volatility and low values ​​of RFV result in lower proportions of scrap.

4.4.2.3 Confidence Intervals in Multiple Logistic Regression

We discuss confidence intervals for the parameters, logit, adjusted values and odds ratios in the simple logistic regression model. The methods used in the case of only one covariate are the same as in the case of multiple regression.

4.4.2.3.1 Confidence Interval for parameters

The confidence interval for a parameter $\beta_j$ is based on their respective Wald test. The confidence interval of $100(1-\alpha)$% for parameter $\beta_j$ is:

$$IC(\beta_j,1-\alpha)= [\hat{\beta_j}-z_{1-\alpha/2}DP[(\hat{\beta_j})]; \quad \hat{\beta_j}+z_{1-\alpha/2}DP[(\hat{\beta_j})]].$$

In which obtaining the parameter estimate $\beta_j$ and its standard deviation is shown in 4.2.1.

Example 4.2.2.1

The proposed model is:

$$\hbox{Probabilidade de refugo}=\pi_i=\dfrac{e^{\beta_0 + \beta_1 x_1 +\beta_2 x_2+\beta_3 x^2_1 + \beta_4 x^2_2 + \beta_5 x_1x_2}}{1+e^{\beta_0 + \beta_1 x_1 +\beta_2 x_2+\beta_3 x^2_1 + \beta_4 x^2_2 + \beta_5 x_1x_2}},$$

in which $x_1$ is the Volatility variable and $x_2$ is the variable RFV.

Therefore, we will construct a Wald confidence interval for the parameters considering the parameter estimates and their standard deviations already calculated in examples 4.2.1.1 and 4.2.1.1.1.

  • For $\beta_0$

$$IC(\beta_0,0,95)= [30,339-1,96 * 3,67; \quad 30,339+1,96 * 3,67],$$

$$IC(\beta_0,0,95)= [30,339-7,1932; \quad 30,339+7,1932],$$

$$IC(\beta_0,0,95)= [23,14; \quad 37,53].$$

  • For $\beta_1$

$$IC(\beta_1,0,95)= [-14,1496-1,96 * 1,35514; \quad -14,1496 + 1,96 * 1,35514],$$

$$IC(\beta_1,0,95)= [-14,1496-2,65607; \quad -14,1496+2,65607],$$

$$IC(\beta_1,0,95)= [-16,8; \quad -11,50].$$

  • For $\beta_2$

$$IC(\beta_2,0,95)= [-6,26927-1,96 * 0,855191; \quad -6,26927+1,96 * 0,855191],$$

$$IC(\beta_2,0,95)= [-6,26927-1,67617; \quad -6,26927+1,67617],$$

$$IC(\beta_2,0,95)= [-7,94; \quad -4,59].$$

  • For $\beta_3$

$$IC(\beta_3,0,95)= [1,10101-1,96 * 0,101994; \quad 1,10101 + 1,96 * 0,101994],$$

$$IC(\beta_3,0,95)= [1,10101- 0,199908; \quad 1,10101+0,199908],$$

$$IC(\beta_3,0,95)= [0,90; \quad 1,30].$$

  • For $\beta_4$

$$IC(\beta_4,0,95)= [0,2819-1,96 * 0,046355; \quad 0,2819+1,96 * 0,046355],$$

$$IC(\beta_4,0,95)= [0,2819-0,090855; \quad 0,2819+0,090855],$$

$$IC(\beta_4,0,95)= [0,19; \quad 0,37].$$

  • For $\beta_5$

$$IC(\beta_5,0,95)= [1,53769 - 1,96 * 0,18197; \quad 1,53769 + 1,96 * 0,18197],$$

$$IC(\beta_5,0,95)= [1,53769 - 0,35666; \quad 1,53769 +0,35666],$$

$$IC(\beta_5,0,95)= [1,18; \quad 1,89].$$

4.4.2.3.2 Confidence Interval for Logito

The logit is the linear part of the logistic regression model. The estimator for logit is:

$$\hat{g}(X)=\hat{\beta_0}+\hat{\beta_1} X_1+\hat{\beta}_2 X_2 + \ldots +\hat{\beta}_p X_p \tag{4.2.2.2.1}$$

The variance estimator of the logit estimator requires obtaining the variance of the sum. The general case is:

$$\hat{Var}[\hat{g}(x)]=\sum_{j=0}^{p}x_j^{2}\hat{Var}(\hat{\beta}_j)+\sum_{j=0}^{p}\sum_{k=j+1}^{p}2x_{j}x_{k}\hat{Cov}(\hat{\beta}_j,\hat{\beta}_k). \tag{4.2.2.2.2}$$

The confidence interval for logit is: $$IC(g(x),1-\alpha)= [\hat{g}(x)-z_{1-\alpha/2}DP[\hat{g}(x)]; \quad \hat{g}(x)+z_{1-\alpha/2}DP[\hat{g}(x)]],$$

in which $DP[\hat{g}(x)]$ is the square root of 4.2.2.2.2 and $z_{1-\alpha/2}$ is the point of the standard normal.

4.4.2.3.3 Confidence Interval for adjusted values

The logit estimator and its confidence interval provide the estimator of the fitted values. The confidence interval of the adjusted values is given by:

$$IC(\pi,1-\alpha)= \left[\dfrac{e^{\hat{g}(x)-z_{1-\alpha/2}DP[\hat{g}(x)]}}{1+e^{\hat{g}(x)-z_{1-\alpha/2}DP[\hat{g}(x)]}}; \quad \dfrac{e^{\hat{g}(x)+z_{1-\alpha/2}DP[\hat{g}(x)]}}{1+e^{\hat{g}(x)+z_{1-\alpha/2}DP[\hat{g}(x)]}}\right]. \tag{4.2.2.3.1}$$

Example 4.2.2.3

Let’s calculate the confidence interval for the predicted value for the first observation that has the following values of the explanatory variables: Volatility=1.906, RFV=5.64, Volatility squared=3.6328, RFV squared=31.832, Interaction Volatility and RFV=10.7536.

$$\hat{g}(x)=30,3389-14,1496 * 1,906-6,2693 * 5,64+1,1010 * 3,6328+$$

$$+0,2819 * 31,832+1,5377 * 10,7536=-2,49.$$

$$DP[\hat{g}(x)]=0,003.$$

Thus, for the first observation, the 95% confidence interval of the predicted values is:

$$IC(\pi,0,95)= \left[\dfrac{e^{-2,49-(1,96 * 0,003)}}{1+e^{-2,49-(1,96 * 0,003)}}; \quad \dfrac{e^{-2,49+(1,96 * 0,003)}}{1+e^{-2,49+(1,96 * 0,003)}}\right].$$

$$IC(\pi,0,95)=[0,07; 0,08].$$

Similarly for the other observations, the 95% Confidence Interval for the adjusted values are in Table 4.4.6.

Adjusted Probability LI LS
0,076399885 0,070450452 0,082349318
0,127990657 0,107519976 0,148461338
0,131046731 0,115743286 0,146350177
0,074710904 0,070150594 0,079271214
0,07579158 0,070721074 0,080862087
0,060636055 0,056779495 0,064492615
0,071903929 0,066629812 0,077178046
0,071022609 0,065386177 0,076659042
0,067959741 0,05838268 0,077536802
0,101027497 0,089405118 0,112649877
0,060889841 0,05658044 0,065199242
0,080881681 0,072272112 0,089491249
0,061890438 0,057329439 0,066451437
0,040125901 0,035798741 0,044453061
0,044062237 0,040031392 0,048093083
0,04366689 0,039566594 0,047767186
0,04284874 0,036425365 0,049272115
0,078649613 0,06629152 0,091007705

Table 4.4.6: Confidence Interval of Adjusted Values

4.4.2.3.4 Confidence Interval for Odds Ratio

Let the limits of the confidence interval be $\beta_j$:

$\beta_{I}=\hat{\beta_j}-z_{1-\alpha/2}DP[(\hat{\beta_j})]$ and $\beta_{S}=\hat{\beta_j}+z_{1-\alpha/2}DP[(\hat{\beta_j})],$

where j=1,2,…p.

The confidence interval for the Odds Ratio is:

$$IC(\hbox{Odds Ratio},1-\alpha)= [e^{\beta_{I}}; \quad ~e^{\beta_{S}}]. \tag{4.2.2.4.1}$$

Example 4.2.2.4

Let’s calculate the confidence interval for the data in example 4.2.1.1.

  • For Volatility

$$\left[\exp(-14,1496-1,96 * 1,35514) \right.~;~~\left.\exp(-14,1496 + 1,96 * 1,35514)\right]$$

$$\left[\exp(-14,1496- 2,65607)\right.~;~~\left.\exp(-14,1496+ 2,65607)\right]$$

$$\left[5,027942e-08; \quad 1,019585e-05\right].$$

  • For RFV

$$\left[\exp(-6,26927-1,96 * 0,855191)\right.~;~~\left.\exp(-6,26927+1,96 * 0,855191)\right]$$

$$\left[\exp(-6,26927-1,67617)\right.~;~~\left.\exp(-6,26927+1,67617)\right]$$

$$\left[0,00035427; \quad 0,010121\right].$$

  • For the Quadratic Effect of Volatility

$$\left[\exp(1,10101-1,96 * 0,101994); \quad \exp(1,10101 + 1,96 * 0,101994) \right]$$

$$\left[\exp(1,10101- 0,199908) ; \quad \exp(1,10101+0,199908)\right]$$

$$\left[2,4623 ; \quad 3,6726 \right].$$

  • For the Quadratic Effect of RFV

$$\left[\exp(0,2819-1,96 * 0,046355) ; \quad \exp(0,2819+1,96 * 0,046355)\right]$$

$$\left[\exp(0,2819-0,090855) ; \quad \exp(0,2819+0,090855)\right]$$

$$\left[1,2105 ; \quad 1,4517\right].$$

  • For the Interaction between Volatility and RFV

$$\left[\exp(1,53769 - 1,96 * 0,18197) ; \quad \exp(1,53769 + 1,96 * 0,18197)\right]$$

$$\left[\exp(1,53769 - 0,35666) ; \quad \exp(1,53769 +0,35666)\right]$$

$$\left[3,2577 ; \quad 6,64822\right].$$

4.4.2.4 Categorical independent variables

4.4.2.4.1 Dichotomous Independent Variable

We will consider explanatory variables taking discrete values. For example, consider a single explanatory variable $X$ with levels A or B. To estimate the model parameters, these variables are replaced by numerical values, for example 0 for level A and 1 for level B. These values are called encoding the categories of the qualitative variable. Thus, the same theory developed for the logistic model considering continuous explanatory variables can be applied to these cases. Using the values in Table 4.4.7, the odds Ratio will be interpreted by:

$$OR=\cfrac{\cfrac{\pi(1)}{1 - \pi(1)}}{\cfrac{\pi(0)}{1 - \pi(0)}} = \cfrac{\cfrac{\cfrac{e^{\beta_0+\beta_1}}{1+e^{\beta_0+\beta_1}}}{\cfrac{1}{1+e^{\beta_0+\beta_1}}}}{\cfrac{\cfrac{e^{\beta_0}}{1+e^{\beta_0}}}{\cfrac{1}{1+e^{\beta_0}}}}=exp(\beta_1) \tag{4.2.4.1.1}$$

x=1 x=0
y=1 $\pi(1)=\cfrac{exp(\beta_0+\beta_1)}{1+exp(\beta_0+\beta_1)}$ $\pi(0)=\cfrac{exp(\beta_0)}{1+exp(\beta_0)}$
y=0 $1-\pi(1)=\cfrac{1}{1+exp(\beta_0+\beta_1)}$ $1-\pi(0)=\cfrac{1}{1+exp(\beta_0)}$
Total 1 1

Table 4.4.7: Logistic Regression Model Values when the independent variable is dichotomous.

So we can do some analysis,

$$OR> 1 \quad \Rightarrow~~\cfrac{\pi_{1}}{1-\pi_{1}}~~>~~\cfrac{\pi_{0}}{1-\pi_{0}}~~\Rightarrow~~\pi_B~~> ~~\pi_A$$

$$OR< 1 \quad \Rightarrow ~~ \cfrac{\pi_1}{1 - \pi_{1}}~~<~~\cfrac{\pi_{0}}{1 - \pi_{0}}~~\Rightarrow~~ \pi_B~~<~~\pi_A$$

Before making conclusions regarding the odds ratio found, it is important to consider the effect that the coding of the variable has on the value of the odds estimate. We saw that $\hat{OR}=exp(\hat{\beta_1})$. But this result is only valid when the independent variable is coded as 0 or 1.

The estimate of the log odds ratio for an independent variable with two levels a and b is:

$$ln[\hat{OR}(a,b)]=\hat{g}(x=a)-\hat{g}(x=b)$$

$$=(\hat{\beta_0}+\hat{\beta_1}.a)-(\hat{\beta_0}+\hat{\beta_1}.b)$$

$$=\hat{\beta_1}(a-b).$$

Thus, the estimated odds ratio is given by:

$$\hat{OR}(a,b)=exp[\hat{\beta_1}(a-b)].$$

The coding method also influences the limits of the confidence interval. Thus, the confidence interval is:

$$IC(OR,1-\alpha)= [exp(\hat{\beta_1}(a-b)-z_{1-\alpha/2}|a-b|DP[(\hat{\beta_1})]); \quad exp(\hat{\beta_1}(a-b)+z_{1-\alpha/2}|a-b|DP[(\hat{\beta_1})])].$$

In which $|a-b|$ is the absolute value of $(a-b)$. As long as we can control the coding of dichotomous variables (two categories), Hosmer and Lemeshow (1976) recommend coding them as 0 or 1.

4.4.2.4.2 Variables with more than two categories

Suppose that instead of two categories, the independent variable has more than two categories ($k> 2$). This variable could be, for example, race: white, black, yellow or others. Let’s assume that Table 4.4.8 is the cross-classification of the race variable (x) in relation to the response variable (y). It is worth noting that the data is fictitious.

white black yellow others Total
$y=1$ 5 20 15 10 50
$y=0$ 20 10 10 10 50
25 30 25 20 100

Table 4.4.8: Cross-classification of hypothetical race data in relation to the binary response variable.

Just as in the case of the dichotomous independent variable, we need to code the explanatory variable. But when we have more than two categories, we have encoded variables that are called dummy variables. Furthermore, in the case of a variable with more than two categories, we have to specify the reference one in which the odds ratio of the other categories are compared with it. In Table 4.4.9 we have the coding of the race variable.

D: Dummies Variables

Race D1 D2 D3
Yellow 0 0 0
White 1 0 0
Others 0 1 0
Black 0 0 1

Table 4.4.9: Coding of the race variable

It is worth mentioning that we have k categories of the explanatory variable, so we have k-1 dummy variables. Thus, the linear predictor is given by:

$$\beta_0+\beta_1D1+\beta_2D2+\beta_3D3.$$

The reference variable is the one in which the values of all dummies are 0, which in this case is the yellow race.

The comparison of the white and yellow breed is:

$$ln[\hat{OR}\hbox{(Branco,Amarelo)}]=\hat{g}\hbox{(Branco)}-\hat{g}\hbox{(Amarelo)}=$$

$$=[\hat{\beta_0}+\hat{\beta_1}(D1=1)+\hat{\beta}_2(D2=0)+\hat{\beta}_3(D3=0)]-[\hat{\beta_0}+\hat{\beta_1}(D1=0)+\hat{\beta}_2(D2=0)+\hat{\beta}_3(D3=0)]$$

$$=[\hat{\beta_0}+\hat{\beta_1}]-[\hat{\beta_0}]$$

$$=\hat{\beta_1}.$$

Thus, the Odds Ratio (White, Yellow) estimate is:

$$\hat{OR}\hbox{(Branco,Amarelo)}=exp(\hat{\beta_1}).$$

Now comparing the other breed in relation to the yellow one, we have:

$$ln[\hat{OR}\hbox{(Outros,Amarelo)}]=\hat{g}\hbox{(Outros)}-\hat{g}\hbox{(Amarelo)}=$$

$$=[\hat{\beta_0}+\hat{\beta_1}(D1=0)+\hat{\beta}_2(D2=1)+\hat{\beta}_3(D3=0)]-[\hat{\beta_0}+\hat{\beta_1}(D1=0)+\hat{\beta}_2(D2=0)+\hat{\beta}_3(D3=0)]$$

$$=[\hat{\beta_0}+\hat{\beta}_2]-[\hat{\beta_0}]$$

$$=\hat{\beta}_2.$$

Thus, the Odds Ratio estimate (Others, Yellow) is:

$$\hat{OR}\hbox{(Outros,Amarelo)}=exp(\hat{\beta}_2).$$

Similarly, we have:

$$\hat{OR}\hbox{(Preto,Amarelo)}=exp(\hat{\beta}_3).$$

Example 4.2.3.1

A DOE experiment was proposed to evaluate the influence of variables in a measurement system. After carrying out a brainstorming it was found that the most influential variables in the model were the preparer and the probe . To analyze this measurement system, a complete experiment was carried out with two factors and two levels. The collected data is organized in Table 4.4.10.

Concordance Non-Concordance Probe Preparer Total
928 32 A A 960
862 98 B B 960
830 130 A B 960
932 28 B A 960

Table 4.4.10: Measurement system data.

For this example, the following model was proposed:

$$\hbox{Probabilidade de falha}=\pi_i = \frac{\exp[\beta_0 + \beta_1~x_1 +\beta_2~x_2]}{1+\exp[\beta_0 + \beta_1~x_1 +\beta_2~x_2]}$$

Considering the variable $x_1$ = Preparer and $x_2$ = Probe, we have:

Levels Probe(x1) Preparer(x2)
A 0 0
B 1 1

Table 4.4.11: Coding of qualitative variables.

From the maximum likelihood function, the model parameters were obtained.

$\widehat{\beta_0}$ =$-3,30347$ (Intercept)

$\widehat{\beta_1}$ =$-0,27926$ (Probe - Level B)

$\widehat{\beta}_2$ =$1,43136$ (Preparator - Level B)

From table (4.4.11) we calculate the probability of failure of the measuring system.

For $x_1 = 0$ and $x_2 = 0$ (Level A - Probe and Level A - Preparer)

$$\hbox{Probabilidade de falha}=\pi_i = \frac{\exp[-3,30347 -0,27926~(0) +1,43136~(0)]}{1+\exp[-3,30347 -0,27926~(0) +1,43136~(0)]} = 0,03544$$

For $x_1 = 1$ and $x_2 = 0$ (Level B - Probe and Level A - Preparer)

$$\hbox{Probabilidade de falha}=\pi_i = \frac{\exp[-3,30347 -0,27926~(1) +1,43136~(0)]}{1+\exp[-3,30347 -0,27926~(1) +1,43136~(0)]} = 0,027041$$

For $x_1 = 0$ and $x_2 = 1$ (Level A - Probe and Level B - Preparer)

$$\hbox{Probabilidade de falha}=\pi_i = \frac{\exp[-3,30347 -0,27926~(0) +1,43136~(1)]}{1+\exp[-3,30347 -0,27926~(0) +1,43136~(1)]} = 0,13329$$

For $x_1 = 1$ and $x_2 = 1$ (Level B - Probe and Level B - Preparer)

$$\hbox{Probabilidade de falha}=\pi_i = \frac{\exp[-3,30347 -0,27926~(1) +1,43136~(1)]}{1+\exp[-3,30347 -0,27926~(1) +1,43136~(1)]} = 0,104202$$

And the estimates of the probability of occurrence of the event of interest are:

Probe Preparer Probability
A A 0,035452
B B 0,104202
A B 0,133298
B A 0,027048

Table 4.4.12: Probability of the event.

The odds ratio estimates are:

Probe: $\hat{OR}(B,A) = exp(\hat{\beta_1})=0,76$

Preparer: $\hat{OR}(B,A)=exp(\hat{\beta}_2)= 4,18$.

Before calculating the confidence interval for the odds ratio, it is necessary to calculate the estimates for the standard deviation, using the matrix $\Sigma(\beta)=[X’VX]^{-1}$:

$$\Sigma(\beta) = \left[ \begin{bmatrix} 1 \quad 1 \quad 1 \quad 1 \cr 0 \quad 1 \quad 0 \quad 1 \cr 0 \quad 1 \quad 1 \quad 0 \cr \end{bmatrix} \times \begin{bmatrix} 960 \ast 0,035(1-0,035) \quad 0 \quad \ldots \quad 0 \cr 0 \quad 960 \ast 0,104(1-0,104) \quad \ldots \quad 0 \cr 0 \quad 0 \quad 960 \ast 0,133(1-0,133) \quad 0 \cr \quad 0 \quad \ldots \quad 960 \ast 0,027(1-0,027) \end{bmatrix}_{4x4} \times \begin{bmatrix} 1 \quad 0 \quad 0 \cr 1 \quad 1 \quad 1 \cr 1 \quad 0 \quad 1 \cr 1 \quad 1 \quad 0 \cr \end{bmatrix}_{4x3} \right] ^{-1}= $$

$$= \begin{bmatrix} \mathbf{0,020177} \quad -0,00681 \quad -0,01713 \cr -0,00681 \quad \mathbf{0,015664} \quad -0,00019 \cr -0,01713 \quad -0,00019 \quad \mathbf{0,022204} \end{bmatrix}_{2x2}$$

The standard deviation estimates are:

For $\beta_0 = \sqrt{ \sigma^2(\widehat{\beta_0}) } = \sqrt{0,0201 } =0,142045$

For $\beta_1 = \sqrt{ \sigma^2(\widehat{\beta_1}) } = \sqrt{0,015662 } = 0,125156$

For $\beta_2 = \sqrt{ \sigma^2(\widehat{\beta}_2) } = \sqrt{0,02220 } = 0,149009$

The results of the Wald test statistic are:

$W_0=\cfrac{\widehat{\beta_0}}{\widehat{DP}(\widehat{\beta_0})}=\cfrac{-3,30347}{0,142045}=-23,26$

$W_1=\cfrac{\widehat{\beta_1}}{\widehat{DP}(\widehat{\beta_1})}=\cfrac{-0,279268}{0,125156}= -2,23$

$W_2=\cfrac{\widehat{\beta}_2}{\widehat{DP}(\widehat{\beta}_2)}=\cfrac{1,43136}{0,149009}= 9,61$

The significance of the parameters are tested considering the following hypotheses:

$$\begin{cases} H_0:\beta_j=0 \cr H_1:\beta_j \neq 0 \cr \end{cases} \quad ~j=0, 1, 2.$$

The p-values for hypothesis testing are:

For $\beta_0 = P(|Z| > 23,26) = 0,000$

For $\beta_1 = P(|Z| > 2,23) = 0,026$

For $\beta_2 = P(|Z| > 7,73) = 0,000$

Therefore, we reject $H_0$ to a level of significance $\alpha = 0,05$ and we conclude that the parameters $\beta_0$, $\beta_1$ and $\beta_2$ are significant in the model.

The confidence intervals for the Odds Ratio of the variables are:

For $\beta_1$ (Probe - type B)

$$\left[\exp(-0,2792 - 1,96 * (0,1251)) ; \quad \exp(-0,2792 + 1,96 * (0,1251)) \right]$$

$$\left[\exp(-0,2792 -0,2451) ; \quad \exp(-0,2792 +0,2451)\right]$$

$$\left[\exp(-0,5243) ; \quad \exp(-0,0341) \right]$$

$$\left[0,591 ; \quad 0,97\right]$$

For $\beta_2$ (Preparator - type B)

$$\left[\exp(1,4313 - 1,96 * (0,149)) ; \quad \exp(1,4313 + 1,96 * (0,149)) \right]$$

$$\left[\exp(1,4313 -0,2920) ; \quad \exp(1,4313 +0,2920) \right]$$

$$\left[\exp(1,1393) ; \quad \exp(1,723) \right]$$

$$\left[3,124 ; \quad 5,60 \right]$$

As the Odds Ratio Confidence Interval of probe level B in relation to level A is less than 1, we conclude that probe B has less chance of failure in the measurement system when compared to probe A.

As the Confidence Interval of the Odds Ratio of the preparer’s level B in relation to level A is greater than 1, we conclude that preparer B has a greater chance of failure in the measurement system when compared to preparer A.

4.4.2.5 Variable Selection

The traditional approach in building statistical models is to find the most parsimonious model that explains the data. The more variables in the model, the greater the error estimate becomes and the more dependent the model becomes on the observed data.

There are some techniques to assist in selecting variables for a Logistic Regression model. Let’s consider two of them: Stepwise Selection Method and All Possible Models.

4.4.2.5.1 Stepwise Selection

The Stepwise method for variable selection is widely used in linear regression.

Any procedure for selecting or excluding variables from a model is based on an algorithm that checks the importance of the variables, including or excluding them from the model based on a decision rule. Variable importance is defined in terms of a measure of statistical significance of the coefficient associated with the variable for the model. This statistic depends on the model’s assumptions. In Stepwise linear regression an F test is used as long as the errors have a normal distribution. In logistic regression, errors follow a binomial distribution and significance is ensured via the Likelihood Ratio Test. Thus, at each step of the procedure the most important variable, in statistical terms, is the one that produces the greatest change in the logarithm of the likelihood in relation to the model that does not contain the variable.

We have to follow the Stepwise method algorithm step by step;

  • Step 0: Suppose we have p candidate explanatory variables for the model. This step starts with adjusting just the intercept and let $L_0$ the log likelihood of this fit. After that, we adjusted the p models with only one explanatory variable. $L_{j}^{(0)}$ is the log likelihood of the model containing the variable $x_j$. The Likelihood Ratio test value of the model containing $x_j$ versus the model with just the intercept is $G_j^{(0)}=-2(L_0-L_j^{(0)})$ and the p-value is $p_j^{(0)}=P[\chi_{v}^2> G_j^{(0)}]$, where v=1 if $x_j$ is continuous and v=k-1 if $x_j$ is categorical with k categories.

Be $p_{e_1}^{(0)}$ the p-value associated with the test of the variable $x_1$ and furthermore, $p_{e_1}^{(0)}=min(p_j^{(0)})$, that is, it is the smallest p-value of all Likelihood Ratio tests. Se $p_{e_1}^{(0)}<\alpha_e$ then $x_1$ enters the model.

$\alpha_e$ is the level of significance to check whether the variable enters the model or not. Lee and Koval (1997) examined the question of significance for logistic regression. The results show that the choice $\alpha_e=0,05$ is very strict and therefore can exclude important variables from the model. It is recommended to choose a value of $\alpha_e$ between 0.15 and 0.20.

  • Step 1: We now adjust the model containing $x_1$. Be $L_{e_1}^{(1)}$ the log likelihood of this model. To check whether p-1 variables are important for the model, since $x_1$ is in it, we fit p-1 regression models containing $x_1$ and $x_j$. The log likelihood is denoted by $L_{e_1;j}^{(1)}$ and the Likelihood Ratio test statistic is: $G_j^{(1)}=-2(L_{e_1}^{(1)}-L_{e_1;j}^{(1)})$. Suppose $p_{e_2}^{(1)}=min(p_j^{(1)})$, that is, the p-value of the test associated with the variable $x_2$ is the smallest among all the others. If this p-value is less than $\alpha_e$ $x_2$ enters the model and we proceed to step 2, otherwise the algorithm ends and only the variable $x_1$ was included in the model.

  • Step 2: Step 2 begins with fitting the model containing $x_1$ and $x_2$. It is possible that, with the inclusion of $x_2$, $x_1$ becomes insignificant for the model. Therefore, in this step we test the significance of one of the variables given that the other is in the model. Be $L_{-e_j}^{(2)}$ the log likelihood of the model with $x_j$ removed. The likelihood ratio statistic is $G_{-e_j}^{(2)}=-2(L_{-e_j}^{(2)}-L_{e_1;e_2}^{(2)})$ and $p_{-e_j}^{(2)}$ is its p-value. To decide whether or not to remove any of the variables, we select the largest p-value. Let’s assume that the p-value of the variable $x_2$ be the largest, that is, $p_{r_2}^{(2)}=max(p_{-e_1}^{(2)},p_{-e_2}^{(2)})$. To see if the variable $x_2$ exits the model, we compare its p-value with an exit significance level, that is, $\alpha_r$. Se $p_{r_2}^{(2)}>\alpha_r$ then $x_2$ exits the model. However, we determine the value of $\alpha_r$ that is greater than $\alpha_e$ so that the program does not remove and include the same variable in the model in successive steps. In the Stepwise method in logistic regression models, it is recommended $\alpha_e=0,15$ and $\alpha_r=0,2.$

After checking variable deletion $x_2$ and assuming that it did not leave the model, that is, its p-value is not greater than $\alpha_r$, we fit p-2 logistic regression models containing $x_{e_1}$,$x_{e_2}$ and $x_j$ with j=1,2,..,p. Be $x_3$ the variable associated with the smallest p-value in the likelihood ratio test, that is, $p_{e_3}^{(2)}=min(p_j^{(2)}).$ If the p-value is less than $\alpha_e$, $x_3$ enters the model and we proceed to step 3, otherwise we stop here and the model is explained by $x_1$ and $x_2$.

  • Step 3: The procedure in step 3 is identical to that in step 2. The program adjusts the model by including the variable selected during the previous steps, checking whether the inclusion of this variable caused the other variables in the model to lose significance. The process continues in this same way until the last step, step S.

  • Step S: This step occurs when all p variables have entered the model or if all variables in the model have a p-value to exit less than $\alpha_r$ and variables not included in the model have a p-value greater than $\alpha_e$.

4.4.2.5.2 All possible models

In the context of multiple linear regression, we discuss the criteria $R^2_p$, $R^2_a$, $C_p$, $AIC$, $BIC$ and $PRESS$ for the selection of variables taking into account all possible models. In logistic regression, the criteria $AIC$ and $BIC$ are easily adapted. For this reason, we will focus on these two criteria to evaluate all possible models. These measurements are calculated as follows:

$$AIC=-2log_eL(\beta)+2p.$$

$$BIC=-2log_eL(\beta)+plog_e(n).$$

In which $log_eL(\beta)$ is the log likelihood of the model (see parameter estimates in multiple logistic regression model).

Another criterion is $-2log_eL(\beta)$ which is not penalized when we add predictors, as it does not depend on the number of covariates in the model. The AIC and BIC criteria are influenced by the number of explanatory variables, since when calculating the AIC we have the sum of $2p$ in the value of the criterion and in the BIC $plog_e(n)$.

4.4.3 Measures of model fit quality

We can evaluate the quality of the model fit by graphing the adjusted model, but there are measures, such as deviance, Pearson’s chi-square statistic and the Hosmer and Lemeshow test that help verify the quality of the model.

For the Deviance and Pearson chi-square tests, we need to identify, among the observations, those with the same values ​​for all covariates. So, be it $\mathbf {X}=(X_1,X_2,…,X_p)$ the set of explanatory variables of the model. Let J also be the distinct number of values that x assumes in the sample (combinations of different levels of covariates, called Covariate Patterns). The number of individuals in the sample with equal values $\mathbf{x}=\mathbf{x}_j$ is denoted by: $m_j$. Already $y_j$ is the number of positive individuals, that is, y=1, in $m_j$. Consequently, $\sum y_j=n_1$ which represents the total number of individuals with y=1.

For the Hosmer and Lemeshow test, it is not necessary for there to be combinations of covariate values.

Below we present each of these tests to evaluate the quality of the fit.

4.4.3.1 Pearson Residuals

In linear regression, measures of goodness of fit are functions of residuals defined as the difference between observed and fitted values. $(y-\hat{y})$. In logistic regression there are different ways to calculate this difference. To understand that the adjusted values in logistic regression are calculated for each Covariate Pattern (see definition in “Model Goodness of Fit Measures”) and depends on the probability estimates for each Covariate Pattern, we will denote the fitted values for the jth Covariate Pattern as $\hat{y}_j$ where:

$$\hat{y}_j=m_j\hat{\pi}_j,$$

in which $m_j$ is the number of observations in Covariate Pattern j and $\hat{\pi}_j$ is the adjusted probability of individuals in j.

Pearson’s measure for the difference between observed and predicted is:

$$r(y_j,\hat{\pi}_j)=\cfrac{(y_j-m_j\hat{\pi}_j)}{\sqrt{m_j\hat{\pi}_j(1-\hat{\pi}_j)}},$$

in which $y_j$ the number of individuals in j with y=1.

Thus, Pearson’s chi-square statistic is given by:

$$\chi^2=\sum_{j=1}^{J}{r(y_j,\hat{\pi}_j)}^2.$$

We can say that $\chi^2$ approaches, asymptotically, $\chi^2_{J-(p+1)},$ $p$ the number of covariates in the adjusted model and $J$ is the Covariate Pattern number. However, in some cases this approximation is bad (see Test restrictions).

Example 4.3.1.1

  • Simple Logistic Regression: Example 4.1.2.1

To calculate Pearson’s chi-square statistic to test whether the adjusted model is adequate, we have to calculate, for each group, the Pearson residual.

For the first group (as summarized data, the first “observation”), we have:

$$\hat{y}_1=m_1\hat{\pi}_1=200 * 0,01806=3,612, \quad y_1=2.$$

$$r(y_1,\hat{\pi}_1)=\cfrac{(y_1-m_1\hat{\pi}_1)}{\sqrt{m_1\hat{\pi}_1(1-\hat{\pi}_1)}}=\cfrac{(2-3,612)}{\sqrt{200 * 0,01806(0,98194)}}=\frac{-1,612}{1,8833}=-0,8559.$$

In a similar way, we calculated the Pearson residuals for the other groups and obtained the following values:

Groups (summary observations) Pearson residuals
1 -0,85599
2 -0,85599
3 -0,85599
4 -0,954
5 -0,55487
6 -0,18804
7 0,147992
8 0,147992
9 0,454625
10 0,294173
11 0,98504
12 0,429086
13 0,429086
14 0,429086
15 0,230969
16 0,230969
17 0,584557
18 0,379551
19 0,507824
20 0,079737
21 0,170431
22 -0,05228
23 -0,05228
24 0,24343
25 0,012207
26 0,012207
27 -0,219
28 -0,45045
29 -0,17915
30 -0,89921

Table 4.4.13: Pearson Residuals

With the residual values from Table 4.4.13, Pearson’s chi-square statistic is:

$$\chi^2=\sum_{j=1}^{30}{r(y_j,\hat{\pi}_j)}^2=7,3535.$$

The p-value $P(\chi^2_{28} > 7,3535)=0,99$ and therefore we do not reject the hypothesis that the adjusted model is adequate.

  • Multiple Logistic Regression: Example 4.2.1.

To obtain Pearson’s chi-square statistic to test whether the adjusted model is adequate, we have to calculate, for each group, the Pearson residual.

Thus, for the first group (as summarized data, the first “observation”), we have that:

$$\hat{y}_1=m_1\hat{\pi}_1=832 * 0,0764=63,56, \quad y_1=270.$$

$$r(y_1,\hat{\pi}_1)=\cfrac{(y_1-m_1\hat{\pi}_1)}{\sqrt{m_1\hat{\pi}_1(1-\hat{\pi}_1)}}=\cfrac{(270-63,56)}{\sqrt{832 * 0,0764(0,9236)}}=\frac{206,44}{7,66214}=26,94.$$

In a similar way, we calculated the Pearson residuals for the other groups and obtained the following values:

Groups (summary observations) Pearson residuals
1 26,94226
2 2,325756
3 10,89268
4 -7,29709
5 -12,1222
6 -3,41077
7 -6,6327
8 -14,1813
9 -2,78226
10 -8,84807
11 -5,97549
12 13,87763
13 -0,44592
14 9,839347
15 6,995839
16 5,203155
17 2,974618
18 -5,2033

Table 4.4.14: Pearson Residuals

With the residual values from Table 4.4.14, we have that Pearson’s chi-square statistic is:

$$\chi^2=\sum_{j=1}^{18}{r(y_j,\hat{\pi}_j)}^2=1830,15.$$

The p-value $(P(\chi^2_{12} > 1830,15))$ is 0 and therefore we reject the hypothesis that the adjusted model is adequate. Thus, we have evidence from Pearson’s chi-square test that the adjusted model is not adequate.

4.4.3.2 Deviance

The sum of the squares of the residuals (SQE) of the linear regression, in the logistic model, is called deviance (D), defined as:

$$d(y_j,\widehat{\pi}_j)=\pm\left[2\left[y_j~\ln \left(\frac{y_j}{m_j\widehat{\pi}_j} \right)+(m_j - y_j) ~\ln \left(\frac{(m_j -y_j)}{m_j\widehat{\pi}_j(1-\widehat{\pi}_j)} \right) \right]\right]^{1/2}. \tag{4.3.2.1}$$

Where the + or - sign is the same sign as $(y_j-m_j\hat{\pi}_j)$. Furthermore, $m_j$ is the number of observations in Covariate Pattern j, $\hat{\pi}_j$ is the adjusted probability of individuals in group j and

$y_j$ the number of individuals in j with y=1.

The test statistic is:

$$D=\sum_{j=1}^J{d(y_j,\hat{\pi}_j)}^2.$$

The D statistic, under the assumption that the fitted model is correct, has an asymptotic distribution $\chi^2$ with $J-(p+1)$ degrees of freedom.

Pearson Chi-Square and Deviance test restrictions

When the asymptotic results are based on the fact that n grows while maintaining the $m_j$ small (or making $m_j$ small), we call it n-asymptotic.

When $J< n$ is fixed and n grows causing the $m_j$ also grow, the asymptotic results based on the $m_j$ are called m-asymptotic.

So, when $J\approx n$, under n-asymptotic, the p-values calculated from the Deviance and Pearson’s chi-square tests, using the distribution $\chi^2$ with $(J-p-1)$ degrees of freedom are incorrect.

One solution is to create clusters that allow the use of m-asymptotic results.

It is worth mentioning that to perform the Hosmer and Lemeshow goodness-of-fit test it is not necessary to have a Covariate Pattern.

Example 4.3.2.1

  • Simple Logistic Regression: Example 4.1.2.1

To obtain the Deviance statistic to test whether the adjusted model is adequate, we have to calculate, using equation (4.4.15), for each group (as summarized data, the first “observation”), the Deviance residual.

Thus, we have the Deviance residual values:

Groups (observations) Deviance Waste
1 -0,93425
2 -0,93425
3 -0,93425
4 -1,05002
5 -0,58267
6 -0,19086
7 0,146409
8 0,146409
9 0,440923
10 0,288473
11 0,929236
12 0,418699
13 0,418699
14 0,418699
15 0,228179
16 0,228179
17 0,56749
18 0,372416
19 0,495682
20 0,079443
21 0,169152
22 -0,0524
23 -0,0524
24 0,240936
25 0,012201
26 0,012201
27 -0,22097
28 -0,45869
29 -0,18041
30 -0,92968

Table 4.4.15: Deviance Waste

With the residual values from Table 4.4.15, we have that the Deviance statistic is:

$$D=\sum_{j=1}^{30}{d(y_j,\hat{\pi}_j)}^2=7,8722.$$

The p-value $P(\chi^2_{28} > 7,8722)=0,99$. Therefore, we do not reject the hypothesis that the model is adequate.

  • Multiple Logistic Regression: Example 4.2.1.1

To obtain the Deviance statistic to test whether the adjusted model is adequate, we must calculate the Deviance residuals using equation (4.3.2.1).

Thus, the waste values are:

Groups (observations) Deviance Waste
1 20,72168
2 2,26703
3 9,965709
4 -9,65112
5 -15,6351
6 -3,83042
7 -8,40627
8 -17,3252
9 -2,89436
10 -10,7692
11 -6,8788
12 12,25469
13 -0,44928
14 8,503884
15 6,305022
16 4,730169
17 2,818639
18 -5,68624

Table 4.4.16: Deviance Waste

With the residual values in Table 4.4.16, we have that the Deviance statistic is:

$$D=\sum_{j=1}^{18}{d(y_j,\hat{\pi}_j)}^2=1753,714.$$

The p-value $P(\chi^2_{12} > 1753,714)=0$. Therefore, we reject the hypothesis that the model is adequate.

4.4.3.3 Hosmer and Lemeshow test

The Hosmer-Lemeshow test is widely used in logistic regression with the purpose of testing the goodness of fit, in other words, the test proves whether the proposed model can explain well what is observed. The test evaluates the adjusted model through the distances between the adjusted probabilities and the observed probabilities.

The goodness of the test is based on dividing the sample according to its adjusted probabilities based on the parameter values ​​estimated by logistic regression. The fitted values ​​are arranged from smallest to largest, and then separated into g groups of approximately equal size. Hosmer and Lemeshow (1980) propose that it be used $g=10$.

Suppose the clustering was done into 10 groups. In this way, the first group will be formed by observations with adjusted probabilities of up to $10%$. The second group will be formed by observations with adjusted probabilities of up to $10%$ following, i.e., probabilities between $10$ and $20%$. Thus the division is done until 10 groups are obtained.

In the literature there is little guidance on how to choose the number of groups. The simulations shown in Hosmer and Lemeshow (1980) were based on the use of $g> p+1$, where p is the number of covariates in the adjusted model. If the expected frequencies in some of the groups are very small the Hosmer-Lemeshow test statistic is calculated, however it may not be reliable. In this case, we must specify a smaller number of groups, however, less than 3 groups cannot be used, as with $(g<3)$ the test statistic is unable to be calculated.

Before calculating the test statistics, it is necessary to estimate the expected frequency within each group. To do this, we divide the response variable, which is dichotomous. For Y=1, the estimated expected frequency is given by the sum of the estimated probabilities of all individuals within that group. For Y=0, the estimated expected frequency is given by the sum of 1-probability estimates of all individuals within that group. Below is an example of a table that must be filled in with the expected frequencies to calculate the Hosmer and Lemeshow statistics.

Decile $Y=1$ Note $Y=1$ Esp $Y=0$ Note $Y=0$ Esp Total
1
2
3
4
5
6
7
8
9
10

Table 4.4.17: example to be filled in to calculate the Hosmer and Lemeshow statistics

Having the expected frequencies, we calculate the Hosmer and Lemeshow statistics, $\hat{C}$, which is obtained as follows:

$$\hat{C}=\sum_{k=1}^{g}\frac{({o_{k}-n^{'}_{k}\bar{\pi}_{k}})^2}{n^{'}_{k}\pi_{k}(1-\pi_{k})},$$

where:

  • $n^{'}_{k}$ is the number of individuals in the kth group.

  • $\bar{\pi_{k}}=\sum_{j=1}^{C_{k}}\frac{m_{j}\bar{\pi}_{j}}{n^{'}_{k}}$

  • $C_k$: the total number of level combinations within the kth decile.

  • $O_k=\sum_{j=1}^{C_{k}}y_j$: total number of responses within group k.

Hosmer and Lemeshow (1980) showed by simulation that the test statistic approximately follows a chi-square distribution with g−2 degrees of freedom, when the model is correctly specified.

4.4.4 Model Diagnosis

4.4.4.1 Leverage

As in the linear model, a metric for diagnosing outliers is leverage (diagonal of the hat matrix). In the linear model, the hat matrix is defined by:

$$H=X(X^\prime X)^{-1}X^\prime.$$

The elements of the main diagonal of the matrix H are called $h_{ii}.$

In the logistic regression model, J is the number of different combinations of covariate levels.

$X_{(j)(p+1)}$: array of all values ​​of all level combinations for all covariates.

$$H=V^{1/2}X(X^\prime VX)^{-1}X^\prime V^{1/2}.$$

$v_{j}=m_{j}\hat{\pi}(x_j)(1-\hat{\pi}(x_j)), \quad \quad \quad ~j=1,2,…,J.$

$h_i = m_j \hat{\pi} _j (1-\hat{\pi} _j) x^{^\prime }_{j}(X^\prime VX)^{-1}x^{^\prime}_j,$

in which $b_j=x^{^\prime }_{j}(X^\prime VX)^{-1}x^{^\prime }_j.$

So, $h_j=v_jb_j$.

In the case of linear regression, if $h_j> 2(p+1)/n$ then observation j is considered an outlier. The difference is that in this case the hat matrix depends only on the values of the covariates while in logistic regression, this matrix also depends on the estimated probabilities (through $v_j$).

The consequence of this is that an observation may be outliers in covariates, but not have a large value. $h_j$, if the adjusted probability is close to 0 or 1.

4.4.4.2 Pearson Residual

The Pearson residual is given by:

$$r_{Pi}=\frac{Y_i-\hat{\pi}_i}{\sqrt{\hat{\pi}_i(1-\hat{\pi}_i)}}$$

4.4.4.3 Studentized Pearson Residual

The Studentized Pearson residual has the following form:

$$r_{SPi}=\frac{r_{Pi}}{\sqrt{1-h_i}},$$

in which $h_i$ is the diagonal of the hat matrix.

4.4.4.4 Waste Deviance

The deviance residue is:

$$d_i=\pm\sqrt{-2[Y_ilog_e(\hat{\pi}_i)+(1-Y_i)log_e(1-\hat{\pi}_i)]}.$$

4.4.4.5 Influence Diagnosis

In addition to detecting outliers, it is also important to detect influential points, that is, points that significantly affect the model’s adjustment.

As in the linear model, we can use Cook’s distance to evaluate the general influence of observation i on the estimates of the regression coefficients. The Cook’s distance metric for observation i is:

$$D_i=\frac{r^{2}_{SPi}h_i}{(p+1)(1-h_i)}.$$

We notice that $ D_i $ is great when the residue $ e_i $ and/or leverage $ h_{ii} $ they are big. The criteria used to highlight influential observations is $ D_i~>1 $, thus, all distances greater than 1 are considered influential.

4.4.5 Prediction

When we have a binary response variable (1 if the individual is an event and 0 otherwise) it is necessary to choose a prediction rule ($\hat{Y}=0 \hbox{ ou } 1$), since $\hat{\pi}$ is between 0 and 1. It is intuitive to think that if the value of $\hat{\pi}_i$ is big, $\hat{Y}_i=1$ and if $\hat{\pi}_i$ is small, $\hat{Y}_i=0$. But how to determine the point that for values above it the individual is classified as an event ($\hat{Y}_i=1$) and values below it the individual is classified as non-event ($\hat{Y}_i=0$)? This point is known as the cutoff point.

A widely used way to determine the cutoff point is through the ROC Curve (Receiver Operating Characteristic Curve). The ROC curve plots $P(\hat{Y}=1|Y=1)$ (called sensitivity) versus $1-P(\hat{Y}=0|Y=0)$ (called 1-specificity) for all possible cutoff points between 0 and 1.

Below is an example of the ROC curve:

Figura4.4.5

Figure 4.4.5: ROC Curve

The choice of the cutoff point must be based on an optimal combination of both sensitivity and specificity, as we assume that classifying the individual as an event given that he is a non-event (false positive) and classifying the individual as a non-event given that he is an event (false negative) brings equivalent losses to the researcher. By analyzing the ROC curve, we chose the cutoff point referring to the combination of sensitivity and 1-specificity that comes closest to the upper left corner of the graph.

4.4.5.1 Prediction Performance Metrics

After adjusting a model and determining the cutoff point, it is important to evaluate the model’s discrimination power, that is, to discriminate events from non-events.

For this evaluation, metrics were created. They are: Accuracy, Sensitivity, Specificity, True Positive Predictive and True Negative Predictive. But before going specifically into these measures, we need to present the confusion matrix, given in Table 4.5.1. Its operation is simple: it is a contingency table in which the predicted value is in the row and the observed value (true value) in the column.

Observed Value (true value)
$Y=1$ $ Y=0$
Predicted Value $Y=1$ VP (true positive) FP (false positive)
Predicted Value $Y=0$ FN (false negative) VN (true negative)

Table 4.4.18: Confusion Matrix

4.4.5.1.1 Accuracy

It is the proportion of correct predictions, without considering what is positive and what is negative, but rather the total accuracy. It is given by:

$$ACC=(VP+VN)/(P+N),$$

where p is the number of events (Y=1, called positive here) and n is the number of non-events (Y=0, called negative here).

4.4.5.1.2 Sensitivity

It is the proportion of true positives, that is, it evaluates the model’s ability to classify an individual as an event $(\hat{Y}=1)$ given that it is actually an event (Y=1):

$$SENS=VP/(VP+FN).$$

4.4.5.1.3 Specificity

It is the proportion of true negatives, that is, it evaluates the model’s ability to predict an individual as a non-event $(\hat{Y}=0)$ given that it really is non-event (Y=0).

$$ESPEC=VN/(VN+FP).$$

4.4.5.1.4 True Positive Predictive

It is the proportion of true positives in relation to all positive predictions, that is, the individual being an event (Y=1) given that the model classified the individual as an event $(\hat{Y}=1)$

$$VPP=VP/(VP+FP).$$

4.4.5.1.5 True Negative Predictive

It is the proportion of true negatives in relation to all negative predictions, that is, the individual being a non-event (Y=0) given that the model classified him as a non-event $(\hat{Y}=0)$.

$$VPN=VN/(VN+FN).$$

↑