hotel_data
install.packages(‘dplyr’)
install.packages(‘stargazer’)
install.packages(‘ggplot2’)
install.packages(‘tidyr’)
install.packages(“rlang”)
library(dplyr)
library(stargazer)
library(ggplot2)
library(tidyr)
library(rlang)
hotel_data\(eliteStatus = factor(hotel_data\)eliteStatus) hotel_data\(visitPurpose = factor(hotel_data\)visitPurpose)
satisfaction_data_long <- hotel_data %>% gather(key = “SatisfactionVariable”, value = “Score”, starts_with(“sat”))
satisfaction_means <- satisfaction_data_long %>% group_by(SatisfactionVariable) %>% summarise(MeanScore = mean(Score, na.rm = TRUE))
plot_0 <- ggplot(satisfaction_means, aes(x = SatisfactionVariable, y = MeanScore, fill = MeanScore)) + geom_col() + scale_fill_gradient(low = “lightblue”, high = “blue”) + labs(title = “Mean Customer Satisfaction Scores”, x = “Satisfaction Variables”, y = “Mean Score”) + theme(plot.title = element_text(hjust = 0.5), # Center the title panel.background = element_blank(), # Remove background axis.text.x = element_text(angle = 90, vjust = 0.5)) # Adjust x-axis labels
plot1 = ggplot(satisfaction_data_long, aes(x = Score)) + geom_histogram(bins = 30, fill = “blue”, color = “black”) + facet_wrap(~ SatisfactionVariable, scales = “free_x”) + labs(title = “Distribution of Satisfaction Scores”, x = “Score”, y = “Frequency”)
non_satisfaction_data <- hotel_data %>% select_if(is.numeric) %>% select(-starts_with(“sat”))
non_satisfaction_data_long <- non_satisfaction_data %>% pivot_longer(cols = everything(), names_to = “Variable”, values_to = “Value”)
plot2 = ggplot(non_satisfaction_data_long, aes(x = Value)) + geom_histogram(bins = 30, fill = “blue”, color = “black”) + facet_wrap(~ Variable, scales = “free_x”) + labs(title = “Distribution of Various Hotel Variables”, x = “Value”, y = “Frequency”)
hotel_data\(log_avgFoodSpendPerNight <- log(hotel_data\)avgFoodSpendPerNight + 1) hotel_data\(log_distanceTraveled <- log(hotel_data\)distanceTraveled + 1) hotel_data\(log_nightsStayed <- log(hotel_data\)nightsStayed + 1)
transformed_data_long <- hotel_data %>% select(log_avgFoodSpendPerNight, log_distanceTraveled, log_nightsStayed) %>% pivot_longer(cols = everything(), names_to = “TransformedVariable”, values_to = “TransformedValue”)
plot3 <- ggplot(transformed_data_long, aes(x = TransformedValue)) + geom_histogram(bins = 30, fill = “blue”, color = “black”) + facet_wrap(~ TransformedVariable, scales = “free_x”) + labs(title = “Distribution of Log-Transformed Variables”, x = “Log-Transformed Value”, y = “Frequency”)
install.packages(“corrplot”)
library(corrplot)
satisfaction_vars <- hotel_data %>% select(starts_with(“sat”))
corr_matrix <- cor(satisfaction_vars, use = “complete.obs”)
corplot1 <- corrplot(corr_matrix, method = “color”, type = “upper”, order = “hclust”, tl.col = “black”, tl.srt = 45, tl.cex = 0.6, addCoefAsPercent = FALSE)
l_mod1 <- lm(satOverall~satCleanRoom + satFrontStaff + satPerks + satDiningPrice, data=hotel_data)
l_mod1sum <- stargazer(l_mod1,type=“text”)
install.packages(‘stats’) library(stats)
anova_model1 <- aov(satOverall ~ eliteStatus, data = hotel_data)
TukeyHSD(anova_model1)
plot4 <- ggplot(hotel_data, aes(x = eliteStatus, y = satOverall, fill = eliteStatus)) + geom_violin(trim = FALSE, color = “blue”) + scale_fill_manual(values = c(“lightblue”, “blue”, “deepskyblue”, “royalblue”)) + labs(title = “Overall Satisfaction by Elite Status”, x = “Elite Status”, y = “Overall Satisfaction”) + theme_minimal() + # Removes background and applies a minimal theme theme(plot.title = element_text(hjust = 0.5), # Center the title legend.title = element_blank()) # Remove the legend title
Plot shows:
• Platinum members are most likely to score their overall satisfaction a 6 or higher – as expected.
• Platinum members also have a reasonably well spread out set of values, with no single score standing out (unlike for Gold and NoStatus where 4 is the most common score).
• No Platinum or Gold members rated their overall satisfaction as a 1.
hotel_data\(totalcustomerspend=(hotel_data\)avgRoomSpendPerNight+hotel_data\(avgFoodSpendPerNight+hotel_data\)avgWifiSpendPerNight)*hotel_data$nightsStayed
average_spend_per_purpose <- hotel_data %>% group_by(visitPurpose) %>% summarise(AverageSpend = mean(totalcustomerspend, na.rm = TRUE))
plot5 <- ggplot(average_spend_per_purpose, aes(x = visitPurpose, y = AverageSpend, fill = visitPurpose)) + geom_bar(stat = “identity”) + scale_fill_manual(values = c(“lightblue”, “blue”, “deepskyblue”, “royalblue”, “skyblue”, “dodgerblue”)) + labs(title = “Average Total Customer Spend by Visit Purpose”, x = “Visit Purpose”, y = “Average Total Spend”) + theme_minimal() + theme(plot.title = element_text(hjust = 0.5), axis.text.x = element_text(angle = 45, hjust = 1), legend.title = element_blank())
l_mod2 <- lm(totalcustomerspend~satCleanRoom + satFrontStaff + satPerks + satDiningPrice + satCleanBath + satCleanCommon + satDiningStaff + satHouseStaff + satValetStaff + satRoomPrice + satWifiPrice + satParkingPrice + satCloseTransp + satCloseEvents + satPoints + satRecognition + satOverall, data= hotel_data)
summary(l_mod2)
average_spend_by_purpose_status <- hotel_data %>% group_by(visitPurpose, eliteStatus) %>% summarise(AverageSpend = mean(totalcustomerspend, na.rm = TRUE))
plot6 <- ggplot(average_spend_by_purpose_status, aes(x = visitPurpose, y = AverageSpend, fill = eliteStatus)) + geom_bar(stat = “identity”, position = position_dodge()) + coord_flip() + labs(title = ““, x =”Visit Purpose”, y = “Average Total Spend”) + scale_fill_brewer(palette = “Blues”) + theme_minimal() + theme(plot.title = element_text(hjust = 0.5))
```