library(tidyverse)
df <- data.frame(hour=c(5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23),
total=c(15507,132129,156909,81306,44413,51448,55308,63542,57564,54031,70319,53345,35137,15509,20134,5183,2554,20,203))
plot(df$hour, df$total)
fit1 <- lm(total~hour, data = df)
fit2 <- lm(total~poly(hour,2, raw = TRUE), data = df)
fit3 <- lm(total~poly(hour,3, raw = TRUE), data = df)
fit4 <- lm(total~poly(hour,4, raw = TRUE), data = df)
fit5 <- lm(total~poly(hour,5, raw = TRUE), data = df)
summary(fit1)$adj.r.squared
summary(fit2)$adj.r.squared
summary(fit3)$adj.r.squared
summary(fit4)$adj.r.squared
summary(fit5)$adj.r.squared
How do I determine the best fit for regression for my data
How can I calculate for critical points, global maxima and local maxima if any.
Tried using the adjusted r squares as the basis for selection of the best curve but my critical point do not correlate with the curve.
ggplot(df, aes(hour, total)) + geom_point() + geom_smooth(method = 'gam')
is arguably not bad. – alistaire