I think it is useful to be able to look at a formula with no context and reason about what it might mean. A few facets of this formula signal to me what might be happening.
The $n-2$ is a signal to me that this has something to do with a simple linear regssion, where the degrees of freedom equals the sample size $(n)$ minus the number of regression parameters fit $(2$, one for the slope and one for the intercept$)$, as that is the only time I can think of where something is divided by $n-2$ or has $n-2$ degrees of freedom. That the result is $t$-distributed signals to me that this should have to do with a regression coefficient, since OLS linear regression coefficients are $t$-distributed under the null hypothesis that they equal zero.
Then the use of Pearson correlation $(r)$ signals to me that this will be related to the slope, as the strength of the Pearson correlation between two variables is related to the strength of how well one variable predicts the other beyond always predicting the mean of that variable (an intercept-only model).
Indeed, a simulation suggests this detective work to be correct.
library(MASS)
set.seed(2023)
N <- 5
R <- 1000
diff_t <- rep(NA, R)
for (i in 1:R){
# Simulate some correlated data
#
X <- MASS::mvrnorm(N, c(0, 0), matrix(c(
1, 0.8,
0.8, 1
), 2, 2))
x <- X[, 1]
y <- X[, 2]
# Fit a regression
#
L <- lm(y ~ x)
# Extract the slope t-stat from the regression
#
t_regression <- summary(L)$coef[2, 3]
# Calculate the Pearson correlation
#
r <- cor(x, y)
# Calculate the value from the formula in the question
#
t_formula <- r /
(
sqrt(
(1 - r^2)/
(N - 2)
)
)
# Calculate the difference between the slope t-stat from the regression
# function and calculated according to the formula given in the question
#
diff_t[i] <- t_regression - t_formula
}
# Summarize the findings: how different the values are
#
summary(diff_t)
################################################################################
#
# OUTPUT
#
################################################################################
> summary(diff_t)
Min. 1st Qu. Median Mean 3rd Qu. Max.
-4.114e-12 -8.900e-16 0.000e+00 9.298e-14 6.700e-16 9.828e-11
That the numbers are basically always equal (within the limits of equality when it comes to doing math on a computer) suggests my line of thinking to be reasonable, and I am quite comfortable taking the formula to be an alternative to the usual t-stat calculation in an ordinary least squares linear regression.