Skip to content
DeepForgeby svx
All problems
MediumStatisticsst-346

Adjusted R Squared from R2

Problem

Adjusted R^2 penalizes predictors: 1 - (1 - R^2) * (n - 1) / (n - p - 1).

Given R^2, the sample size n, and the number of predictors p, return the adjusted value.

Hint

Use the residual degrees of freedom in the denominator.

Test cases

case 1
in: [0.9,100,1]
expected: 0.8989795918367347
case 2
in: [0.5,10,3]
expected: 0.25
case 3
in: [0.8,50,5]
expected: 0.7772727272727273
Starter codePython
def adjusted_r_squared_from_r2(r2, n, p):
    # Your code here
    pass

3 test cases · run your code against them in the editor