# Significance between odd ratios

I´m fairly new to the tools of statistics and I need some help. I´m working in R. I have a list of students, their age, sex, test results(continuous variable) and education (a categorical variable. 0 if student has no education, 1 if student has education). This is stored in the data frame df.

I have assigned each student an age group depending on their age. The groups are 5-10,11-15, 16-20, 21-25. So now I have a new categorical variable with 4 levels.

I have done logistic regression for each age group. I did the test in R like this:

model1 = glm(education ~ test results + sex + age, data = df, family = binomial())


From the logistic regression result I compute the odds ratio (exp(coefficient)) for the test results variable. For each age group I got an odds ratio and confidence interval. There are some differences in the odds ratio between age groups. The odd ratio gets closer to 1 with higher age group. I interpret this in the following way; as the age of students is higher there is less effect from education on test result. My question is how can I test if the difference in odds ratios is significant, i.e. what test can I use in R ?

Here is a subset of the data:

student sex age testScore education ageGroup

1        1   10   0.12       1        1

2        1    8   0.08       1        1

3        2   16   0.85       0        3

4        2   20   0.12       0        3

5        1   22   1.02       0        4

6        2   18   0.98       1        3

7        1   19   0.46       1        3

8        1   16   0.83       0        3

9        2   12   0.26       1        2

10       2   14   0.46       0        2


I have been searching books and the web without success, can´t seem to find an example that I can relate to. Any suggestions would be appreciated.

• I think you have to be careful with your interpretation. When you interpret a variable in a (logistic) regression model of the form Y ~ X1+X2+X3 all the interpretations of a variable's coefficients assume that the rest of the variables remain constant/stable. I don't get what "as the age of students is higher there is less effect from education on test result" exactly means. I think you should, first, focus on what exactly you want to investigate and then use a statistical model or a test to find out. Nov 5, 2015 at 11:05
• My interpretation of the odd ratio was just a thought on the side. What I want to investigate is the relation between the education and test score for each of the age groups. The odds ratios I get do tell you something. Its the question, are the odds ratios significantly different, I want answered. Nov 5, 2015 at 11:14
• Great. This is a very well formulated question. So, I think you don't need sex in the model and I guess you could investigate the interaction education ~ test results:age. But, the easiest and most straightforward approach in terms of interpretation is to do a logistic model of education ~ test results for each age group. If you have a sample of data, or if you can create some fake data, similar to the actual ones, I'll be able to help you more. Nov 5, 2015 at 11:20
• PS: Interpreting the coefficients/odds ratios of the independent variable age on the dependent variable education like you did above will tell you how age affects education when test results remain constant. This is not what you want to investigate here. Nov 5, 2015 at 11:26
• Added an example of the data Nov 5, 2015 at 13:29

Based on the data you provided let's see what the model you described above does. Note that the sample of data is very small and I can't get any statistically significant coefficients, but I'll ignore that (in this case) when I try to interpret the model's output.

  dt = read.table(text = "student sex age testScore education ageGroup

1        1   10   0.12       1        1

2        1    8   0.08       1        1

3        2   16   0.85       0        3

4        2   20   0.12       0        3

5        1   22   1.02       0        4

6        2   18   0.98       1        3

7        1   19   0.46       1        3

8        1   16   0.83       0        3

9        2   12   0.26       1        2

10       2   14   0.46       0        2", header=T)

# create factor variables
dt$ageGroup = as.factor(dt$ageGroup)
dt$education = as.factor(dt$education)

summary(glm(education ~ testScore+sex+ageGroup, data = dt, family = binomial()))

# Coefficients:
#               Estimate Std. Error z value Pr(>|z|)
# (Intercept)   19.2260  4612.1501   0.004    0.997
# testScore      0.3885     2.9652   0.131    0.896
# sex           -0.6988     1.8748  -0.373    0.709
# ageGroup2    -17.9683  4612.1504  -0.004    0.997
# ageGroup3    -18.7778  4612.1502  -0.004    0.997
# ageGroup4    -37.4896  7988.5385  -0.005    0.996


You can see that ageGroup1 is missing because it's the baseline for comparions with the other groups. So, you can interpret the output as "when sex and testScore remain the same, ageGroup1 is correlated with a higher probability of having education = 1, then it's ageGroup2, then 3 and 4". This is easy if you compare the coefficients. Eg. -17.9683 is the difference between ageGroup 2 and 1, so 1 is better than 2.

However, this is not what you want. You said "investigate the relation between the education and test score for each of the age groups". To put that in a more statistical perspective, or in terms of how the model understands that investigation, this is the same as "within each age group is there evidence of a true (statistically significant) relationship between testScore and education? Is it positive or negative?" The easiest way is to create a model for each ageGroup. As an example I'm considering ageGroup 3.

summary(glm(education ~ testScore, data = dt[dt\$ageGroup==3,], family = binomial()))

# Coefficients:
#              Estimate Std. Error z value Pr(>|z|)
# (Intercept)   -1.246      2.294  -0.543    0.587
# testScore      1.268      3.085   0.411    0.681


So, within that group testScore is positively correlated with the probability of having education = 1. For 1 unit increase in testScore the odds of having education = 1 increase by 255% {As exp(1.268) = 3.55}.

Let me know if you have more questions and I can update my answer to be more clear. I'd suggest you spend some time on interpreting logistic regression coefficients of a continuous, or categorical, variable.

• Thanks a lot for your answer. It is very clear and I have learned a lot from it. OK. So I create a model for each age group as you did. Let´s say that the odds increase as I go from age group 1 to 4. How would I test if those odds are significantly different ? Nov 5, 2015 at 14:52
• Each time you create a model you're within an age group. So, that model doesn't know/care that there are other age groups. In other words you can't compare age groups but test scores. So, you will be able to say if the odds increase for a 1 unit increase of testScore. And that could be found by checking the p value of that coefficient in column Pr(>|z|). When you say "from age group 1 to 4" that contradicts your objective that said "relation between the education and test score for each of the age groups". Is it possible that you want something else? Nov 5, 2015 at 15:01