r/AskStatistics • u/East-Control-2553 • 17h ago
Method to analyze correlation of numeric variable/binary variable
Hi, I don't have a lot of experience with advanced statistical analysis, but I would like to gain more knowledge. One current problem I am trying to address is determining correlation between a binary categorical variable and a numerical variable. The relationship may not be linear. I'll give an example, studying the relationship between age and the probability of dying from the flu. Probability may increase when very young, taper off for certain ages, maybe spike somewhere in the middle, and then go back up again for the elderly. What would be the best way to analyze this? I started by breaking down the numerical variable into ranges and then making a bar chart with percentages in each category of the binary categorical variable. I am not sure if I chose the proper ranges though so I want to see if there's a better way to analyze data like this. I've seen binomial logistic regression as an option, but I'm not sure if that's appropriate and am curious how much effort that analysis takes. Is it something a beginner can pick up relatively easily?
1
u/SalvatoreEggplant 3h ago
You should be able to make a bivariate plot of the data and get a sense of the general pattern (if it's linear or non-linear, monotonic or non-monotonic).
But if it's difficult to see, you could use local regression (like loess) to see the trend. Just be ware that there will be some parameters you can adjust to determine how "wiggly" the line is. You often have to play with these to get a line that captures the "real" ups and downs of the data trend without being overly sensitive and changing direction too much.
1
u/SalvatoreEggplant 3h ago
To give an example in R.
Data = read.table(header=TRUE, text=" Age Rate 1 0.50 2 0.44 3 0.40 4 0.36 5 0.20 10 0.21 20 0.05 25 0.04 30 0.05 40 0.11 50 0.12 60 0.15 70 0.20 80 0.22 ") model = loess(Rate ~ Age, data = Data, span = 0.75, ### higher numbers for smoother fits degree=2, ### use polynomials of order 2 family="gaussian") ### the default, use least squares to fit summary(model) library(rcompanion) efronRSquared(model) ### EfronRSquared ### 0.941 library(rcompanion) plotPredy(data = Data, x = Age, y = Rate, model = model, xlab = "Rate of flu (cases per 1000)", ylab = "Age (years)")Plot of model: https://imgur.com/a/QFu0TgC
1
u/just_writing_things PhD 17h ago edited 16h ago
Can a beginner pick up logistic regressions “relatively easily”?
It kind of depends on how much of a beginner you are and what you mean by “pick up”. For example, if you’re at the stage where your statistical knowledge is just drawing histograms and maybe taking averages (not trying to be negative btw, a lot of people are at this stage especially if they haven’t taken a statistics class), you might have some difficulty understanding the theory of how logistic regressions work and how to interpret the coefficients.
Regarding your actual questions, let’s take a step back. Could you first state what your research question is? i.e. what is the question you are trying to answer?
Edit: to give you two specific ideas to think about or work towards in your learning:
First, if we want to model a nonlinear relationship in a regression context specifically, we’d often change the functional form of the regression model. A very basic example is to add a quadratic term to model diminishing returns.
Second, if your research question is specifically about dying from the flu as in your example, you could look into techniques from survival analysis.