Skip to content
DeepForgeby svx
All problems
HardStatisticsst-088

Multiple R-Squared from Correlations

Problem

Return the multiple R-squared for two predictors from their correlations: (r_y1^2 + r_y2^2 - 2*r_y1*r_y2*r_12) / (1 - r_12^2). Return 0.0 when |r_12| >= 1, and clamp the result to [0, 1].

Hint

The predictor intercorrelation r_12 can inflate or deflate the explained variance.

Test cases

case 1
in: [0.7,0.5,0.3]
expected: 0.5824175824175825
case 2
in: [0.6,0.6,0]
expected: 0.72
case 3
in: [0.5,0.5,0.5]
expected: 0.3333333333333333
case 4
in: [0.9,0.9,1]
expected: 0
case 5
in: [0,0,0]
expected: 0
Starter codePython
def multiple_r_squared(r_y1, r_y2, r_12):
    # Your code here
    pass

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