INTRODUCTION

This report is Project 2 for MKTG3P98

DATA SUMMARY

Set up working directory.

getwd()
## [1] "/Users/charlesmba/Desktop"
setwd("/Users/charlesmba")

Install Packages.

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
library(ggplot2)

Read the CSV files.

New_Car_Total <- read.csv("/Users/charlesmba/Desktop/New_Car_Total.csv")

Defining a vector of Chrysler models

Chrysler_models <- c( "Chrysler Jeep")

Defining a vector of Ford models

Ford_models <- c( "Ford Expedition", "Ford Explorer")

Defining a vector of Toyota models

toyota_models <- c( "Toyota Corolla", "Toyota Rav4", "Toyota Highlander")

Filtering the dataset for the specified models

selected_models <- c(Ford_models, toyota_models, Chrysler_models)
filtered_data <- New_Car_Total %>%
  filter(Model %in% selected_models)

Separating the data into different regions

regions <- c("European", "Asian", "American", "Middle eastern")
region_data <- lapply(regions, function(region) {
  filtered_data %>% filter(Region == region)
})
names(region_data) <- regions

Extracting MPG data for region and model variables

mpg_data <- lapply(region_data, function(data) {
  data %>%
    select(Region, Model, MPG) %>%
    filter(!is.na(MPG))
})

changing into a dataframe for plotting

mpg_df <- do.call(rbind, mpg_data)

Plotting the data, jitter to prevent overlapping

ggplot(mpg_df, aes(x = Region, y = MPG, color = Model)) +
  geom_point(position = position_jitter(width = 0.2, height = 0), size = 3, alpha = 0.7) +
  labs(title = "MPG Distribution by Region",
       x = "Region",
       y = "MPG") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

Extracting mean Value Perception data for each region and model.

mean_valu_percp <- lapply(region_data, function(data) {
  if(nrow(data) > 0) {
    data %>%
      group_by(Model) %>%
      summarise(Mean_Valu_Percp_1 = mean(Valu_Percp_1, na.rm = TRUE))
  } else {
    data.frame(Model = character(), Mean_Valu_Percp_1 = numeric())
  }
})

Converting to data frame for plotting

mean_valu_percp_df <- do.call(rbind, lapply(names(mean_valu_percp), function(region) {
  data <- mean_valu_percp[[region]]
  if(nrow(data) > 0) {
    data.frame(Region = region, data)
  } else {
    data.frame(Region = character(), Model = character(), Mean_Valu_Percp_1 = numeric())
  }
}))

Plotting the data

ggplot(mean_valu_percp_df, aes(x = Region, y = Mean_Valu_Percp_1, fill = Model)) +
  geom_bar(stat = "identity", position = position_dodge()) +
  labs(title = "Mean Value Perception by Region and Car Model",
       x = "Region",
       y = "Mean Value Perception (1 to 10)") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

Filtering the dataset for Chrysler cars only

chrysler_data <- New_Car_Total %>%
  filter(grepl("Chrysler", Model))

Separating data into different regions

regions2 <- c("European", "Asian", "American", "Middle eastern")
region_data2 <- lapply(regions, function(region) {
  chrysler_data %>% filter(Region == region)
})

showing values (check)

names(region_data) <- regions

Extracting payment method column for each region and counting values

pay_meth_counts <- lapply(region_data, function(data) {
  table(factor(data$Pay_Meth, levels = 1:3), useNA = "ifany")
})

Converting count into a data frame for plotting

pay_meth_df <- do.call(rbind, lapply(names(pay_meth_counts), function(region) {
  counts <- pay_meth_counts[[region]]
  data.frame(Region = region, Pay_Meth = as.numeric(names(counts)), Count = as.vector(counts))
}))

Plotting data

ggplot(pay_meth_df, aes(x = Pay_Meth, y = Count, fill = Region)) +
  geom_bar(stat = "identity", position = "dodge") +
  labs(title = "Regional Payment Method Distribution (Chryslers)", 
       x = "Payment Method", 
       y = "Count") +
  theme_minimal() 

Extracting Age column for each region and counting values

Age_counts <- lapply(region_data, function(data) {
  table(factor(data$Age, levels = 18:60), useNA = "ifany")
})

Converting count into a data frame for plotting

Age_df <- do.call(rbind, lapply(names(Age_counts), function(region) {
  counts <- Age_counts[[region]]
  data.frame(Region = region, Pay_Meth = as.numeric(names(counts)), Count = as.vector(counts))
}))

Plotting data

ggplot(Age_df, aes(x = Pay_Meth, y = Count, fill = Region)) +
  geom_bar(stat = "identity", position = "dodge") +
  labs(title = "Regional Age Distribution for Chrysler Cars", 
       x = "Age", 
       y = "Count") +
  theme_minimal() 

Creating new mean column for Enjoyment

chrysler_data$Enj_mean <- (chrysler_data$Enj_1 + chrysler_data$Enj_2) / 2

Creating new mean column for Future Purchase

chrysler_data$Futu_Pur_mean <- (chrysler_data$Futu_Pur_1 + chrysler_data$Futu_Pur_2) / 2

Creating new mean column for Word of Mouth

chrysler_data$WOM_mean <- (chrysler_data$WOM_1 + chrysler_data$WOM_2) / 2

Creating new mean column for Value Perception

chrysler_data$Valu_Percp_mean <- (chrysler_data$Valu_Percp_1 + chrysler_data$Valu_Percp_2) / 2

Plotting the correlation between Enjoyment and Future Purchase

ggplot(chrysler_data, aes(x = Enj_mean, y = Futu_Pur_mean)) +
  geom_point() +
  geom_smooth(method = "lm", col = "blue") +
  labs(title = "Correlation between Enjoyment and Future Purchase",
       x = "Mean Enjoyment",
       y = "Mean Future Purchase") +
  theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'

Plotting the correlation between Enjoyment and Word of Mouth

ggplot(chrysler_data, aes(x = Enj_mean, y = WOM_mean)) +
  geom_point() +
  geom_smooth(method = "lm", col = "blue") +
  labs(title = "Correlation between Enjoyment and Word of Mouth",
       x = "Mean Enjoyment",
       y = "Mean Word of Mouth") +
  theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'

Plotting the correlation between Future Purchase and Value Perception

ggplot(chrysler_data, aes(x = Futu_Pur_mean, y = Valu_Percp_mean)) +
  geom_point() +
  geom_smooth(method = "lm", col = "blue") +
  labs(title = "Correlation between Future Purchase and Value Perception",
       x = "Mean Future Purchase",
       y = "Mean Value Perception") +
  theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'

Plotting the correlation between Enjoyment and Future Purchase by Region

ggplot(chrysler_data, aes(x = Enj_mean, y = Futu_Pur_mean)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE, color = "blue") +
  facet_wrap(~ Region) +
  labs(title = "Correlation between Enjoyment and Future Purchase by Region",
       x = "Mean Enjoyment",
       y = "Mean Future Purchase") +
  theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'

Plotting the correlation between Enjoyment and Word of Mouth by Region

ggplot(chrysler_data, aes(x = Enj_mean, y = WOM_mean)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE, color = "blue") +
  facet_wrap(~ Region) +
  labs(title = "Correlation between Enjoyment and Word of Mouth by Region",
       x = "Mean Enjoyment",
       y = "Mean Word of Mouth") +
  theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'

Plotting the correlation between Future Purchase and Value Perception by Region

ggplot(chrysler_data, aes(x = Futu_Pur_mean, y = Valu_Percp_mean)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE, color = "blue") +
  facet_wrap(~ Region) +
  labs(title = "Correlation between Future Purchase and Value Perception by Region",
       x = "Mean Future Purchase",
       y = "Mean Value Perception") +
  theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'

Plotting the correlation between Enjoyment and Future Purchase by Insurance Type

ggplot(chrysler_data, aes(x = Enj_mean, y = Futu_Pur_mean, color = Insur_Type)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE) +
  labs(title = "Correlation between Enjoyment and Future Purchase by Insurance Type",
       x = "Mean Enjoyment",
       y = "Mean Future Purchase") +
  theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'

Plotting the correlation between Enjoyment and Word of Mouth by Insurance Type

ggplot(chrysler_data, aes(x = Enj_mean, y = WOM_mean, color = Insur_Type)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE) +
  labs(title = "Correlation between Enjoyment and Word of Mouth by Insurance Type",
       x = "Mean Enjoyment",
       y = "Mean Word of Mouth") +
  theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'

Plotting the correlation between Future Purchase and Value Perception by Insurance Type

ggplot(chrysler_data, aes(x = Futu_Pur_mean, y = Valu_Percp_mean, color = Insur_Type)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE) +
  labs(title = "Correlation between Future Purchase and Value Perception by Insurance Type",
       x = "Mean Future Purchase",
       y = "Mean Value Perception") +
  theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'