# --- Phase 1: Load Data --- # This script assumes you have already run the simulation and added the # results to your CSV file. # Check if the file exists before attempting to load it if (!file.exists('analyze.csv')) { stop("Error: 'analyze.csv' not found. Please create it and run the simulation first.") } # Load the CSV file with the simulation results df <- read.csv('analyze.csv', stringsAsFactors = FALSE) # Define the price points initial_price <- 4.50 new_price <- 5.50 # --- Phase 2: Analysis & Synthesis --- # Calculate the revenue impact based on the simulation data # Calculate initial weekly revenue per customer df$initial_revenue <- df$initial_visits_per_week * initial_price # Calculate projected new weekly revenue per customer df$new_revenue <- df$new_visits_per_week * new_price # Calculate total revenue before and after total_initial_revenue <- sum(df$initial_revenue) total_new_revenue <- sum(df$new_revenue) revenue_change <- total_new_revenue - total_initial_revenue percent_change <- (revenue_change / total_initial_revenue) * 100 # --- Phase 3: Reporting the Results --- # Display a clear summary of the simulation outcome. cat("==================================================\n") cat(" 'The Daily Grind' Price Simulation Report \n") cat("==================================================\n\n") cat("--- Customer Behavior Analysis (Sample) ---\n") # To make the output cleaner, we'll show a sample of the results print(head(df[, c('customer_id', 'persona_type', 'initial_visits_per_week', 'new_visits_per_week', 'rationale')])) cat("\n--- Revenue Impact Analysis ---\n") cat(sprintf("Initial Price per Latte: $%.2f\n", initial_price)) cat(sprintf("New Price per Latte: $%.2f\n\n", new_price)) cat(sprintf("Projected Initial Weekly Revenue: $%.2f\n", total_initial_revenue)) cat(sprintf("Projected New Weekly Revenue: $%.2f\n", total_new_revenue)) cat(sprintf("Net Change in Weekly Revenue: $%.2f\n", revenue_change)) cat(sprintf("Percentage Change: %.1f%%\n\n", percent_change)) cat("--- Conclusion ---\n") if (revenue_change > 0) { cat("The simulation predicts a net INCREASE in revenue despite losing some customers.\n") cat("The price increase on loyal customers outweighs the loss from price-sensitive segments.\n") } else { cat("The simulation predicts a net DECREASE in revenue.\n") cat("The loss of price-sensitive customers is not offset by the increased price for loyal ones.\n") } cat("Recommendation: Analyze the trade-off between short-term revenue gain/loss and long-term brand loyalty.\n") cat("==================================================\n")