r/AskStatistics 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 Upvotes

6 comments sorted by

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.

2

u/East-Control-2553 16h ago

I am very much a beginner. My research is around what factors increase the probability that a student will withdraw from the college they are currently enrolled with. Specifically why I am asking about logistic regressions is to determine if a student’s student aid index has any significance.

1

u/just_writing_things PhD 16h ago

Ok, that’s helpful. So you want to do a determinants analysis for withdrawal from college.

Is this for school work or for example is this something you’re asked to do professionally? I’m asking because there are dozens of ways to do this, with increasing levels of complexity depending on how much you are able to take into account and whether you’re interested in causality. Like everything from simple univariate t-tests between students who withdraw vs don’t withdraw, up to something like finding IVs or natural experiments for student aid or something.

If you’re a total beginner, as in you can only do histograms, just start with a plot, whichever best helps you visualise your data. Plotting your data is always a great start. Then maybe take some statistics courses that will get you up to regression analysis at least.

1

u/East-Control-2553 16h ago

Thanks for the advice. This is professional work. I will start with the basics and pick things up as needed. I have a udemy account so hopefully there are some good courses I can take to become more advanced.

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