Modelling Risk: the Absolute and the Relative
By: Dr Andreas Ochs
Tags: Data Science, R, Statistics, Modelling, Risk

What is the risk of a new creditor to default on their loan? what is the “risk” of watching a certain movie on Netflix given a certain viewing history? What is my risk of dying given a certain diagnosis and how is this affected by a certain treatment? Risks are all around us, and quantifying these risks is becoming increasingly popular. Providing the right kind of analysis to these key questions is crucial to making the right decisions.

While the concepts surrounding risks are fairly straightforward, they are often confused even by seasoned analysts. For instance, the concepts of risk and odds are often used interchangeably in everyday language but have different meanings in a statistical context. A certain exposure or treatment can have vast effects on ones relative risk compared to another treatment, but at the same time the impact on the absolute risk might be miniscule. Getting these things separated properly is key to interpreting the results correctly and making the right decisions.

In this piece I lay out each concept in detail, contrast them with each other and illustrate how they are computed using a hypothetical dataset and code for deriving the measures in R. It is structured into three parts. The first part contrasts absolute and relative risks as concepts. The second part introduces the concepts of risk and odds more formally and illustrates how to derive the measures in R. The third part introduces he concepts of risk and odds ratios and illustrates how these measures can be derived from generalised linear models.

Being a biostatistician by training the example dataset is a medical one in which 200 patients have been observed and it has been recorded if they have experienced a certain event (say a headache, a heart attack, you name it). 100 of these hypothetical patients have been exposed to a certain treatment (say aspirin, a statin…), while the remaining 100 patients have not been exposed to this treatment. While inherently medical, the same logic can be applied to a range of different settings: which user watched a certain movie (the event) and who of those had previously watched another, specific movie (the treatment). Which creditor has defaulted (the event), and which user had a given credit history (the treatment).

You can get the code to generate the dataset I use here and all other code presented in this piece from my Github page.

The absolute and the relative

Absolute and relative risks are related but distinct concepts. Absolute risk captures the absolute probability of an event happening, for instance, the probability of an individual to obtain a certain qualification. The probability of a creditor to default. The probability of a patient to die from a disease.

The relative risk is a concept that compares the risks or probabilities of two or more groups relative to one another. For instance, what is the probability of a male student to obtain a certain qualification compared to a female. What is the relative risk of a creditor to default on their loan when they had a history of credit default compared to creditors without such a history. What is the risk of dying from lung cancer among smokers compared to non-smokers?

It is important to see that the absolute risk can be small but the relative risk much larger. For instance, the risk of defaulting on a loan is much higher given a certain credit history compared to creditors without such history. However, the overall and absolute risk of defaulting might be low even for those with unfavourable credit history.

Both these concepts have merit in statistical analysis but they will provide evidence for different types of decisions. Let us begin by looking into absolute risks some more.

Modelling absolute risks and odds

In non-technical terms, a risk is the chance that something will happen. The terms risks and odds are often used interchangeably in everyday language. Most people have more intuitive understanding of risks (and the underlying concept of probabilities) with odds only really used in gambling. In more technical discussions, however both terms have distinct meanings and both the concept of odds is an important one to understand as it is commonly used in statistical techniques to model binary outcomes and thus risks. This is for a number of computational reasons. Let us begin by defining both risks and odds and the relationship between both concepts.

A Risk is the probability that an event or outcome occurs. More technically, it is the change of the outcome of interest occurring as a fraction of all possible outcomes. Formulaically we can say:

Where P(p) is the probability of the outcome, p is the number of times the outcome did occur, q is the number of times the event did not occur, and N is the number of cases observed in total. As such, it is defined as the number of events that occurred divided by the sum of the number of events that did occur and the number of events that did not occur. Or, the number of events divided by the total number of cases.

Risks can range from 0 to 1, where the risk equals 0 if the event can never occur and 1 if the event is certain to occur (that is, it can never not occur). They can also be expressed as percentages ranging from 0–100%.

Odds are defined as the probability of an event occurring relative to it not occurring. Formulaically we can say:

Odds can range from 0 to infinity, where odds equal to 0 mean that an event can never occur (similar to a risk of 0), and infinity means that an event is certain to occur (similar to a risk of 1). This unboundedness on the upper end is a major reason why odds are used for computation rather than the bounded risks. When you now log the odds (to get log-odds) you also remove the lower bound and have a measure that can range from -∞ to +∞, similar to continuous outcomes.

The relationship between risks and odds

While it is important to distinguish between risks and odds, both concepts are inherently related — for once, they are derived from the same parameters (p and q). As such, odds can also be expressed in terms of risks or probabilities, and vice versa.

You can derive odds from risks by dividing the risk of the event happening by the risk of the event not happening (that is 1 minus the risk of the event happening). This is just another way of expressing p/q since the denominator of the risk is always equal to N (or p+q).

We can rearrange this formula to solve for risk (P(X)) and can thus compute the risk of the event happening by dividing the odds of the event happening by 1 plus the event happening.

From this we can see that a risk of 0.5 equates to odds of 1 because O(X)=0.5/(1–0.5)=1.

It is also worth noting that when risks are small the difference between odds and risks is small as well as O(X)=P(X)/(1-P(X))≈P(X) when P(X) approaches 0.

Computing Risks and Odds

Let us apply this knowledge to our data example. We can get the frequencies of the events from our data frame (called x ) as follows:

addmargins(table(x$events))

I will illustrate two ways of computing risks and odds from the data. Firstly, the simple arithmetic approach plugging the numbers into the above formulae. Secondly by using generalised linear regression models.

We have observed a total of 200 cases (that is our N). Out of these 66 had the event of interest (that is our p), and 134 (or N-p) did not have the event (that is our q). We can compute risk and odds as follows:

We see that the risk of having the outcome is 33% within the population we recorded data for. In other words, roughly 1 in 3 persons had the outcome.

The odds of having the outcome are 0.49. In other words, people in the study are half as likely to have the outcome than not to have the outcome.

The second way of computing odds and risks is by fitting a binomial regression model. Below shows a generalised linear regression model:

where x₁,₂,ᵢ are right hand side variables, β₁,₂,ᵢ are coefficients and β₀ the intercept. g(y) is the link function. The link function is used to relate the expected value of the left hand side to the linear predictors on the right. It transforms probabilities of the outcome event to a continuous unbounded scale. A number of different link functions are used in different models. Logistic regression, the standard approach for modelling binary outcomes, uses the logit link function:

Where π is the probability of the outcome and log the natural logarithm. Now that does look familiar, doesn’t it? It is the log of the odds computed from risks. This means that a logistic model generates log-odds, which can be converted to odds using the exponential.

To model this, we use the glm command, from the binomial family and specify the link to be logit (this is the default with binomial, but it’s good to be explicit). I use ~1 as constant as there are no covariates.

binom_logit <- glm(event~1, data=x, family=binomial(link="logit"))

To now get the log odds of the outcome for each case we use predict with the type equal to link.

binom_logit_link <- predict(binom_logit, type="link").

This returns a vector of numbers with the predicted log-odds for each record. Note that the log-odds are the same for each patient as there are no predictors on the right-hand side. Exponentiating the log odds exp(binom1_link) will return the odds of the outcome for each record, which is 0.4925373. This is identical to the odds computed above.

To compute the risks we have to change the link function from logit to log as we simply want to obtain π. To do this we fit a binomial model with the log link function (log(π)), like so:

binom_log <- glm(event~1, data=x, family=binomial(link="log"))

and then predict with type link:

binom_log_link <- predict(binom_log, type="link")

Exponentiating this gives the absolute risk of having the outcome of 0.33, which again is identical to the risk computed above.

Note that there is an alternative way of obtaining absolute risks, which is by predicting the type “response”, which will return the absolute risks (0.33) from both models.

Modelling relative risks and odds

Now that we know how to obtain absolute risks from data, we move on to exploring relative risks and relative odds. Measures of relative risks and odds are commonly used to contrast the difference in risks between individuals belonging to two or more groups; therefore they are effect measures. Commonly used measures in this realm are relative risk ratios and odds ratios. By intuition they are ratios of two risks or two odds.

Before we get into details let us look at our data, where half the cases have been exposed to the treatment, while the other half has not. The 2x2 table looks like this:

Within the exposed group (treatment==1) of 100 people, 29 had the outcome, and 71 did not. Within the unexposed group (treatment==0) of 100 people, 37 had the outcome, and 63 did not.

The risk ratio is the ratio of the risk of the exposed group and the risk of the unexposed group. Formulaically, we say:

From the data we see that the risk of the exposed group is 29/100=0.29 and the risk of the unexposed group is 37/100=0.37. Therefore, the risk ratio is 0.29/0.37=0.784. The risk ratio of less than 1 indicates that the exposed group is at lower risk relative to the unexposed group.

A Odds ratios is therefore the ratio of odds of the exposed group (that group we want to measure the effect of) and the odds of the unexposed group. Formulaically, we say:

As such, the odds of the exposed group (treatment==1) are 29/71=0.408. The odds of the unexposed group (treatment==0) are 37/63=0.587. The ratio of this is 0.408/0.587=0.695. The odds ratio smaller than 1 indicates that the event is less likely in the exposed group than it is in the unexposed group. We say that the exposed group is 0.7 times as likely to have the outcome compared to the unexposed group.

Computing Risks Ratios and Odds Ratios

This section outlines how to compute risk ratios and odds ratios using regression models. We do so by fitting a generalised linear model as before, but this time replacing the constant with the treatment indicator. First to obtain the risk ratios, we fit the following generalised linear model with log link function

binom_trt_log <- glm(event~treatment, data=x, family=binomial(link="log"))

Extracting and exponentiating the coefficient, by using:

exp(coef(binom_trt_log))

We obtain two coefficients:

The interpretation of these coefficients warrants caution: The coefficient associated with the treatment variable is the relative risk of the exposed group compared to the not exposed group and therefore the risk ratio of the two groups.

The coefficient associated with the intercept is the risk when the covariates equal 0. In our case this is therefore the absolute risk of the outcome of the unexposed group.

To obtain the absolute risk of the exposed group we multiply the coefficient of the intercept with that of the treatment variable and obtain 0.37*0.7837=0.29. Note that we multiply the coefficients because the model is built on the logarithmic scale so that y=exp(a)*exp(b)=exp(a+b).

Alternatively, we can also obtain the absolute risks of both groups by predicting and then exponentiating the link function, which will give the absolute risk for each patient.

To obtain odds ratios, we fit a logistic model in the similar fashion:

binom_trt_logit <- glm(event~treatment, data=x, family=binomial(link="logit"))

Extracting and exponentiating the coefficient, by using:

exp(coef(binom_trt_logit))

We obtain two coefficients, which are interpreted to be the odds ratio of the treatment (0.695) and the odds of the unexposed group (0.587).

Similar to the logit model, we can obtain (absolute) odds by multiplying the coefficients or predicting and exponentiating the link function.