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 exercício faz parte do curso
Supervised Learning in R: Regression
Instruções do exercício
- Use cor()(docs) to get the correlation between the predictions and female unemployment. Assign it to the variablerhoand print it. Make sure you use Pearson correlation (the default).
- Square rhoand assign it torho2. Print it.
- Compare rho2to \(R^2\) from the model (usingglance()). Is it the same?
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# 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 <- ___(___)$___)