Load the data
ice_cream <- read.csv('https://raw.githubusercontent.com/Kingtilon1/DATA607/main/Ice%20Cream%20Sales%20-%20temperatures.csv')
glimpse(ice_cream)
## Rows: 365
## Columns: 2
## $ Temperature <int> 39, 40, 41, 42, 43, 43, 44, 44, 45, 45, 45, 46, 46, …
## $ Ice.Cream.Profits <dbl> 13.17, 11.88, 18.82, 18.65, 17.02, 15.88, 19.07, 19.…
scatter_plot <- plot_ly(data = ice_cream, x = ~Temperature, y = ~Ice.Cream.Profits, type = "scatter", mode = "markers",
marker = list(color = ~Ice.Cream.Profits, colorscale = "Viridis")) %>%
layout(title = "Ice Cream Sales vs. Temperature",
xaxis = list(title = "Temperature"),
yaxis = list(title = "Ice Cream Sales"))
scatter_plot
lm_model <- lm(Ice.Cream.Profits ~ Temperature, data = ice_cream)
summary(lm_model)
##
## Call:
## lm(formula = Ice.Cream.Profits ~ Temperature, data = ice_cream)
##
## Residuals:
## Min 1Q Median 3Q Max
## -6.9404 -1.3804 0.0956 1.5976 8.7716
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -33.698166 0.702173 -47.99 <2e-16 ***
## Temperature 1.192009 0.009594 124.25 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.427 on 363 degrees of freedom
## Multiple R-squared: 0.977, Adjusted R-squared: 0.977
## F-statistic: 1.544e+04 on 1 and 363 DF, p-value: < 2.2e-16
ice_cream$Predicted <- predict(lm_model)
ice_cream$Residuals <- residuals(lm_model)
residual_plot <- ggplot(ice_cream, aes(x = Temperature, y = Residuals)) +
geom_point() +
geom_hline(yintercept = 0, linetype = "dashed", color = "red") +
labs(title = "Residuals vs. Temperature",
x = "Temperature",
y = "Residuals")
residual_plot