This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.
plot(cars)
Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Ctrl+Alt+I.
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Ctrl+Shift+K to preview the HTML file).
The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.
# Load necessary libraries
library(tidyverse) # Data manipulation and visualization
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.2 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.2 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.0
## ✔ purrr 1.0.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(lubridate) # Date manipulation
library(forecast) # Time series forecasting
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
library(ggplot2) # Data visualization
library(zoo) # Time series objects
##
## Attaching package: 'zoo'
##
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
bike_data <- read.csv(“bike_rental_data.csv”)
head(bike_data)
bike_data\(date <- as.Date(bike_data\)date)
bike_data <- na.omit(bike_data)
str(bike_data)
ts_bikes <- ts(bike_data$rentals, start = c(2011, 1), frequency = 365)
decomposed_ts <- decompose(ts_bikes)
plot(decomposed_ts)
ts_bikes <- ts(bike_data$rentals, start = c(2011, 1), frequency = 365)
decomposed_ts <- decompose(ts_bikes)
plot(decomposed_ts)
arima_model <- auto.arima(ts_bikes)
summary(arima_model)
forecasted_values <- forecast(arima_model, h = 12)
autoplot(forecasted_values) + labs(title = “Forecast of Bike Rentals for the Next Year”, x = “Time”, y = “Forecasted Rentals”)