Linear regression on the United States
A linear regression is a model that lets us examine how one variable changes with respect to another by fitting a best fit line. It is done with the lm() function in R.
Here, you'll fit a linear regression to just the percentage of "yes" votes from the United States.
Latihan ini adalah bagian dari kursus
Case Study: Exploratory Data Analysis in R
Petunjuk latihan
- Print the
US_by_yeardata to the console. - Using just the US data in
US_by_year, uselm()to run a linear regression predictingpercent_yesfromyear. Save this to a variableUS_fit. - Summarize
US_fitusing thesummary()function.
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
# Percentage of yes votes from the US by year: US_by_year
US_by_year <- by_year_country %>%
filter(country == "United States")
# Print the US_by_year data
# Perform a linear regression of percent_yes by year: US_fit
# Perform summary() on the US_fit object