ComenzarEmpieza gratis

Correlation and R-squared

The linear correlation of two variables, \(x\) and \(y\), measures the strength of the linear relationship between them. When \(x\) and \(y\) are respectively:

  • the outcomes of a regression model that minimizes squared-error (like linear regression) and
  • the true outcomes of the training data,

then the square of the correlation is the same as \(R^2\). You will verify that in this exercise.

unemployment and unemployment_model are available for you to use.

Este ejercicio forma parte del curso

Supervised Learning in R: Regression

Ver curso

Instrucciones del ejercicio

  • Use cor() (docs) to get the correlation between the predictions and female unemployment. Assign it to the variable rho and print it. Make sure you use Pearson correlation (the default).
  • Square rho and assign it to rho2. Print it.
  • Compare rho2 to \(R^2\) from the model (using glance()). Is it the same?

Ejercicio interactivo práctico

Prueba este ejercicio completando el código de muestra.

# unemployment is available
summary(unemployment)

# unemployment_model is available
summary(unemployment_model)

# Get the correlation between the prediction and true outcome: rho and print it
(rho <- ___)

# Square rho: rho2 and print it
(rho2 <- ___)

# Get R-squared from glance and print it
(rsq_glance <- ___(___)$___)
Editar y ejecutar código