# Chapter 26 Logistic Regression Analysis

## 26.1 Intro

Logistic regression analysis can be useful to obtain a model to predict a dichotomous dependent variable (als known as a binary or logical variable) as a function of one or more predictor variables and estimate how well that dependent variable can be predicted using the predictor variables.

### 26.1.1 Example dataset

This example uses the Rosetta Stats example dataset “pp15” (see Chapter 1 for information about the datasets and Chapter 3 for an explanation of how to load datasets).

### 26.1.2 Variable(s)

From this dataset, this example uses variables gender_bi as dependent variable (the participant’s gender) and xtcUseDosePref (the MDMA dose a participant prefers in milligrams) and weight_other (a participants’ weight in kilograms) as predictors.

## 26.2 Input: jamovi

In the “Analyses” tab, click the “Regression” button and from the menu that appears, in th e“Logistic Regression” section, select “2 Outcomes (Binomial)” as shown in Figure 26.1. Figure 26.1: Opening the linear regression menu in jamovi

In the box at the left, select the dependent variable and move it to the box labelled “Dependent variable” using the button labelled with the rightward-pointing arrow as shown in Figure 26.2. Figure 26.2: Selecting the dependent variable for the regression analysis in jamovi

In the box at the left, select any continuous predictors and move them to the box labelled “Covariates” using the button labelled with the rightward-pointing arrow as shown in Figure 26.3. If there are categorical predictors, move them to the box labelled “Factors”. Figure 26.3: Selecting the continuous predictros for the regression analysis in jamovi

The results will immediately be shown in the right-hand “Results” panel. You can scroll down to specify additional analyses, for example, to request more details about the regression coeffictents you can open the “Model Coefficients” section as shown in Figure 26.4. Figure 26.4: Selecting the categorical predictors for the regression analysis in jamovi

For example, to order the odds ratios and their confidence intervals, check the corresponding check boxes as shown in Figure 26.5. Figure 26.5: Selecting the predictor for the regression analysis in jamovi

## 26.3 Input: R

### 26.3.1 R: base R

In base R, the glm (generalized linear model) function can be called with argument family = binomial(link = "logit") to perform a logistic regression. The summary function can then be used to show the most important results.

result <-
glm(
gender_bi ~
xtcUseDosePref +
weight_other,
data = dat,
);
summary(result);

### 26.3.2 R: rosetta

In the rosetta package, the logRegr function wraps base R’s glm function to present output similar to that provided by other statistics programs in one command.

rosetta::logRegr(
gender_bi ~
xtcUseDosePref +
weight_other,
data=dat
);

With multiple predictors, if collinearity=TRUE, collinearity diagnostics are ordered. If there is only one predictor, you can request a visualisation of the raw data, the (binned) means, and the logistic curve by using plot=TRUE.

rosetta::logRegr(
gender_bi ~
xtcUseDosePref,
data = dat,
plot = TRUE
);

## 26.4 Input: SPSS

In SPSS, the REGRESSION command is used (don’t forget the period at the end (.), the command terminator):

LOGISTIC REGRESSION VARIABLES gender_bi
/METHOD=ENTER xtcUseDosePref weight_other.
.

## 26.5 Output: jamovi Figure 26.6: Logistic regression analysis output in jamovi

## 26.6 Output: R

### 26.6.1 R: base R


Call:
glm(formula = gender_bi ~ xtcUseDosePref + weight_other, family = binomial(link = "logit"),
data = pp15)

Deviance Residuals:
Min       1Q   Median       3Q      Max
-2.5760  -0.7852   0.3836   0.7113   1.6096

Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept)    -6.615057   1.805922  -3.663 0.000249 ***
xtcUseDosePref  0.017874   0.004902   3.646 0.000266 ***
weight_other    0.070162   0.024616   2.850 0.004369 **
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for binomial family taken to be 1)

Null deviance: 162.31  on 134  degrees of freedom
Residual deviance: 121.02  on 132  degrees of freedom
(694 observations deleted due to missingness)
AIC: 127.02

Number of Fisher Scoring iterations: 6

### 26.6.2 R: rosetta

## Warning in rosetta::logRegr(gender_bi ~ xtcUseDosePref + weight_other, data =
## pp15, : You requested a plot, but for now plots are only available for logistic
## regression analyses with one predictor.

### 26.6.3 Logistic regression analysis

 Formula: gender_bi ~ xtcUseDosePref + weight_other Sample size: 135 Predicting: Male Cox & Snell R-squared: .26 Nagelkerke R-squared: .38 Test for significance: (of full model) ChiSq = 41.29, p < .001

Female
Female 39
Male 96

Female Male
Female 21 18
Male 9 87

#### 26.6.3.3 Regression coefficients

(log odds values, called ‘B’ in SPSS)

95% conf. int. estimate se z p
(Intercept) [-10.48; -3.36] -6.62 1.81 -3.66 <.001
xtcUseDosePref [0.01; 0.03] 0.02 0.00 3.65 <.001
weight_other [0.03; 0.12] 0.07 0.02 2.85 .004

#### 26.6.3.4 Regression coefficients as odds ratios

(ORs, called ‘Exp(B)’ in SPSS)

95% conf. int. Odds Ratio point estimate
(Intercept) [0; 0.03] 0.00
xtcUseDosePref [1.01; 1.03] 1.02
weight_other [1.03; 1.13] 1.07

## 26.7 Output: SPSS Figure 26.7: The output of the logistic regression analysis in SPSS part 1 Figure 26.8: The output of the logistic regression analysis in SPSS part 2