├── README.md └── linear_regression_demo.R /README.md: -------------------------------------------------------------------------------- 1 | This is the code from the StatQuest... 2 | * Linear Regression in R: https://youtu.be/u1cc1r_Y7M0 3 | -------------------------------------------------------------------------------- /linear_regression_demo.R: -------------------------------------------------------------------------------- 1 | ## Here's the data from the video 2 | mouse.data <- data.frame( 3 | weight=c(0.9, 1.8, 2.4, 3.5, 3.9, 4.4, 5.1, 5.6, 6.3), 4 | size=c(1.4, 2.6, 1.0, 3.7, 5.5, 3.2, 3.0, 4.9, 6.3)) 5 | 6 | mouse.data # print the data to the screen in a nice format 7 | 8 | ## plot a x/y scatter plot with the data 9 | plot(mouse.data$weight, mouse.data$size) 10 | 11 | ## create a "linear model" - that is, do the regression 12 | mouse.regression <- lm(size ~ weight, data=mouse.data) 13 | ## generate a summary of the regression 14 | summary(mouse.regression) 15 | 16 | ## add the regression line to our x/y scatter plot 17 | abline(mouse.regression, col="blue") 18 | --------------------------------------------------------------------------------