Analysis of AirPassengers

The “AirPassengers” dataset in R contains the monthly totals of international airline passengers from 1949 to 1960. It is a time series dataset, which means it contains data points collected at regular intervals (monthly, in this case) over a period of time. The dataset consists of only one variable, which represents the number of international airline passengers in thousands.

summary(AirPassengers)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   104.0   180.0   265.5   280.3   360.5   622.0

Time Series Plot will help us identify any trends and seasonal patterns in the data.

# Create a time series plot
plot(AirPassengers, main = "Airline Passengers Over Time",
     xlab = "Year-Month", ylab = "Number of Passengers")

Decomposition of Time Series

this Perform a time series decomposition to separate the data into its trend, seasonal, and remainder components. This helps in understanding the underlying patterns in the data.

# Decompose the time series
decomposed <- decompose(AirPassengers)
plot(decomposed)

Forecasting

We can use time series forecasting methods to predict future passenger numbers. The forecast package in R provides various forecasting methods.

# Load the forecast package
library(forecast)
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
# Fit an exponential smoothing model and make forecasts
fit <- ets(AirPassengers)
forecasted_values <- forecast(fit, h = 12)  # Forecast for the next 12 months
plot(forecasted_values, main = "Airline Passengers Forecast")

Histogram

A histogram to visualize the distribution of the passenger data.

# Load necessary libraries
library(ggplot2)

# Create a time series plot
ggplot(data = AirPassengers, aes(x = AirPassengers)) +
  geom_histogram(binwidth = 10, fill = "blue", color = "black") +
  labs(
    title = "Distribution of Airline Passengers",
    x = "Number of Passengers",
    y = "Frequency"
  )
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.

Box Plot

A box plot to visualize the summary statistics and identify potential outliers.

# Create a box plot
ggplot(data = AirPassengers, aes(y = AirPassengers)) +
  geom_boxplot(fill = "pink", color = "black") +
  labs(
    title = "Box Plot of Airline Passengers",
    y = "Number of Passengers"
  )
## Don't know how to automatically pick scale for object of type <ts>. Defaulting
## to continuous.

Pie chat

# Convert AirPassengers to a data frame
passenger_data <- data.frame(Year = as.integer(time(AirPassengers)), Passengers = as.vector(AirPassengers))

# Calculate the annual mean of passengers
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
annual_means <- passenger_data %>%
  group_by(Year) %>%
  summarize(MeanPassengers = mean(Passengers))

# Load necessary libraries
library(ggplot2)

# Create a pie chart
ggplot(data = annual_means, aes(x = "", y = MeanPassengers, fill = as.factor(Year))) +
  geom_bar(stat = "identity") +
  coord_polar(theta = "y") +
  labs(
    title = "Mean Airline Passengers by Year",
    fill = "Year"
  )

I calculated the annual means of passengers and create a pie chart where each slice represents a year, and the size of each slice corresponds to the mean number of passengers in that year. This pie chart gives you a visual representation of how the mean passenger count varies from year to year.