How to Calculate Cronbach’s Alpha in Python


Chronbach’s Alpha is a way to measure the internal consistency of a questionnaire or survey.

Cronbach’s Alpha ranges between 0 and 1, with higher values indicating that the survey or questionnaire is more reliable.

The following example shows how to calculate Cronbach’s Alpha in Python.

Example: Calculating Cronbach’s Alpha in Python

Suppose a restaurant manager wants to measure overall satisfaction among customers, so she sends out a survey to 10 customers who can rate the restaurant on a scale of 1 to 3 for various categories.

The following pandas DataFrame shows the results of the survey:

import pandas as pd

#enter survey responses as a DataFrame
df = pd.DataFrame({'Q1': [1, 2, 2, 3, 2, 2, 3, 3, 2, 3],
                   'Q2': [1, 1, 1, 2, 3, 3, 2, 3, 3, 3],
                   'Q3': [1, 1, 2, 1, 2, 3, 3, 3, 2, 3]})

#view DataFrame
df

        Q1	Q2	Q3
0	1	1	1
1	2	1	1
2	2	1	2
3	3	2	1
4	2	3	2
5	2	3	3
6	3	2	3
7	3	3	3
8	2	3	2
9	3	3	3

To calculate Cronbach’s Alpha for the survey responses, we can use the cronbach_alpha() function from the pingouin library.

First, we’ll install the pingouin library:

pip install pingouin

Next, we’ll use the cronbach_alpha() function to calculate Cronbach’s Alpha:

import pingouin as pg

pg.cronbach_alpha(data=df)

(0.7734375, array([0.336, 0.939]))

Cronbach’s Alpha turns out to be 0.773.

The 95% confidence interval for Cronbach’s Alpha is also given: [.336, .939].

Note: This confidence interval is extremely wide because our sample size is so small. In practice, it’s recommended to use a sample size of at least 20. We used a sample size of 10 here for simplicity sake.

The default confidence interval is 95%, but we can specify a different confidence level using the ci argument:

import pingouin as pg

#calculate Cronbach's Alpha and corresponding 99% confidence interval
pg.cronbach_alpha(data=df, ci=.99)

(0.7734375, array([0.062, 0.962]))

The value for Cronbach’s Alpha remains the same, but the confidence interval is much wider since we used a higher confidence level.

The following table describes how different values of Cronbach’s Alpha are usually interpreted:

Cronbach’s Alpha Internal consistency
0.9 ≤ α Excellent
0.8 ≤ α < 0.9 Good
0.7 ≤ α < 0.8 Acceptable
0.6 ≤ α < 0.7 Questionable
0.5 ≤ α < 0.6 Poor
α < 0.5 Unacceptable

Since we calculated Cronbach’s Alpha to be 0.773, we would say that the internal consistency of this survey is “Acceptable.”

Bonus: Feel free to use this Cronbach’s Alpha Calculator to find Cronbach’s Alpha for a given dataset.

Leave a Reply

Your email address will not be published.