My presentation will be on simple linear regressions
2025-10-16
My presentation will be on simple linear regressions
library(ggplot2)
ggplot(trees,
aes(x=Height, y=Volume))
+ geom_point()
+ geom_smooth(method="lm",
color="darkgreen")
+ labs(title="Linear Regression of Volume on Girth",
x ="Tree Height (ft)",
y="Tree Volume (ft^3)")
library(plotly)
model = lm(mpg ~ hp + qsec, data=mtcars)
horsepowerseq = seq(min(mtcars$hp), max(mtcars$hp), length.out = 30)
timeseq = seq(min(mtcars$qsec), max(mtcars$qsec), length.out=30)
grid = expand.grid(hp = horsepowerseq, qsec = timeseq)
grid$mpg_est = predict(model, newdata = grid)
matr = matrix(grid$mpg_est,
nrow=length(horsepowerseq),
ncol=length(timeseq))
p = plot_ly() %>%
add_markers(
data = mtcars,
x = ~hp,
y = ~qsec,
z= ~mpg,
marker = list(size=8),
name = "Observed Data"
) %>%
add_surface(
x=horsepowerseq,
y=timeseq,
z=matr,
name = "Regression Plane"
) %>%
layout(
title="Predicting Fuel Efficiency",
scene = list(
xaxis = list(title="Horsepower"),
yaxis = list(title="1/4 Mile Time"),
zaxis = list(title = "MPG")
)
)
p