Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Create a custom function to calculate the R-squared value for a linear regression model.

Hard

Problem Statement

Create a custom function to calculate the R-squared value for a linear regression model.

Sample Input

Observed: c(3, -0.5, 2, 7)
Predicted: c(2.5, 0.0, 2, 8)

Sample Output

R-squared: 0.9486

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
# Predefined structure calculate_r_squared <- function(observed, predicted) { # Your logic here } # Call the function
Log in or sign up to run or submit your code.Log inSign up
Input
Observed: c(3, -0.5, 2, 7)
Predicted: c(2.5, 0.0, 2, 8)
Expected Output
R-squared: 0.9486