DATA 606 - Statistics & Probability - Fall 2023

Linear Regression Part 2

Click here to open the slides (PDF).

library(ggplot2) library(tibble) N <- 10000 x <- rnbinom(N, 10, .5)

df <- tibble(x = x, logx = log(x + 1), x2 = max(x) - x, logx2 = log(x2 + 1), sqauredx = x2^2)

ggplot(df, aes(x = x)) + # geom_density(color = ‘blue’) + # geom_density(color = ‘red’, aes(x = logx)) + # geom_density(color = ‘green’, aes(x = x2)) + geom_density(color = ‘maroon’, aes(x = sqauredx))

data(mtcars)

lm(mpg ~ wt, data = mtcars)

ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + geom_smooth(method = ‘lm’, formula = y ~ x, se = FALSE, color = ‘maroon’) + geom_smooth(method = ‘loess’, formula = y ~ x, se = FALSE, color = ‘blue’, linetype = 3, span = 0.2) + geom_smooth(method = ‘loess’, formula = y ~ x, se = FALSE, color = ‘blue’, linetype = 2, span = 0.75)

df <- data.frame(x = c(‘Yes’, ‘No’), y = c(100, 95))

ggplot(df, aes(x = x, y = y)) + geom_bar(stat = ‘identity’) ggplot(df, aes(x = x, y = y)) + geom_bar(stat = ‘identity’) + coord_cartesian(ylim=c(90,100))