Set up working directory

getwd()
## [1] "C:/Users/User/OneDrive/Documents/Desktop/MKTG Final Project"
setwd("C:/Users/User/OneDrive/Documents/Desktop/MKTG Final Project")

Step 1: Load The Datasets

# Load necessary libraries
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.4.1
## 
## 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(readr)

# Load/import the datasets
financials <- read_csv("~/Desktop/MKTG Final Project/Movie Dataset_Financials.csv")
## Rows: 651 Columns: 5
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): original_title, language, country
## dbl (2): budget (Millions), revenue (Millions)
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
str(financials)
## spc_tbl_ [651 × 5] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
##  $ original_title    : chr [1:651] "The Departed " "Exodus: Gods and Kings " "Spectre " "The X Files " ...
##  $ budget (Millions) : num [1:651] 1 2 110 2.9 190 135 1 2 74 2 ...
##  $ revenue (Millions): num [1:651] 0.01 0.05 295.24 0.3 1506.25 ...
##  $ language          : chr [1:651] "English" "English" "English" "English" ...
##  $ country           : chr [1:651] "USA" "UK" "UK" "USA" ...
##  - attr(*, "spec")=
##   .. cols(
##   ..   original_title = col_character(),
##   ..   `budget (Millions)` = col_double(),
##   ..   `revenue (Millions)` = col_double(),
##   ..   language = col_character(),
##   ..   country = col_character()
##   .. )
##  - attr(*, "problems")=<externalptr>
head(financials, n=10)
## # A tibble: 10 × 5
##    original_title      `budget (Millions)` `revenue (Millions)` language country
##    <chr>                             <dbl>                <dbl> <chr>    <chr>  
##  1 The Departed                        1                   0.01 English  USA    
##  2 Exodus: Gods and K…                 2                   0.05 English  UK     
##  3 Spectre                           110                 295.   English  UK     
##  4 The X Files                         2.9                 0.3  English  USA    
##  5 Star Wars: Episode…               190                1506.   French   France 
##  6 John Carter                       135                 533.   English  USA    
##  7 Rio                                 1                   0.4  English  USA    
##  8 The Expendables                     2                   0.57 English  USA    
##  9 Avengers: Age of U…                74                1157.   English  USA    
## 10 Cutthroat Island                    2                   1.05 English  USA
general_audience <- read_csv("~/Desktop/MKTG Final Project/Movie Dataset_General Audience.csv")
## Rows: 651 Columns: 13
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (7): original_title, type, genre, mpaa_rating, critics_rating, audience_...
## dbl (6): runtime, imdb_rating, imdb_num_votes, critics_score, audience_score...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
str(general_audience)
## spc_tbl_ [651 × 13] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
##  $ original_title : chr [1:651] "The Departed " "Exodus: Gods and Kings " "Spectre " "The X Files " ...
##  $ type           : chr [1:651] "Feature Film" "Feature Film" "Feature Film" "Feature Film" ...
##  $ genre          : chr [1:651] "Drama" "Drama" "Comedy" "Drama" ...
##  $ runtime        : num [1:651] 118 131 84 97 90 78 107 130 88 100 ...
##  $ mpaa_rating    : chr [1:651] "Unrated" "PG-13" "R" "PG" ...
##  $ imdb_rating    : num [1:651] 2.1 3.3 7.6 2.5 7.2 7.8 2.1 2.1 7.5 4.1 ...
##  $ imdb_num_votes : num [1:651] 9904 1010 22381 54363 35096 ...
##  $ critics_rating : chr [1:651] "Fresh" "Fresh" "Certified Fresh" "Rotten" ...
##  $ critics_score  : num [1:651] 10 43 91 27 81 91 30 33 90 56 ...
##  $ audience_rating: chr [1:651] "Upright" "Upright" "Upright" "Upright" ...
##  $ audience_score : num [1:651] 21 34 91 23 77 86 21 31 89 45 ...
##  $ best_pic_nom   : chr [1:651] "no" "no" "no" "no" ...
##  $ Facebook_Likes : num [1:651] 48 490 11700 230 172221 ...
##  - attr(*, "spec")=
##   .. cols(
##   ..   original_title = col_character(),
##   ..   type = col_character(),
##   ..   genre = col_character(),
##   ..   runtime = col_double(),
##   ..   mpaa_rating = col_character(),
##   ..   imdb_rating = col_double(),
##   ..   imdb_num_votes = col_double(),
##   ..   critics_rating = col_character(),
##   ..   critics_score = col_double(),
##   ..   audience_rating = col_character(),
##   ..   audience_score = col_double(),
##   ..   best_pic_nom = col_character(),
##   ..   Facebook_Likes = col_double()
##   .. )
##  - attr(*, "problems")=<externalptr>
head(general_audience, n=10)
## # A tibble: 10 × 13
##    original_title     type  genre runtime mpaa_rating imdb_rating imdb_num_votes
##    <chr>              <chr> <chr>   <dbl> <chr>             <dbl>          <dbl>
##  1 The Departed       Feat… Drama     118 Unrated             2.1           9904
##  2 Exodus: Gods and … Feat… Drama     131 PG-13               3.3           1010
##  3 Spectre            Feat… Come…      84 R                   7.6          22381
##  4 The X Files        Feat… Drama      97 PG                  2.5          54363
##  5 Star Wars: Episod… Feat… Horr…      90 R                   7.2          35096
##  6 John Carter        Docu… Docu…      78 Unrated             7.8            333
##  7 Rio                Feat… Drama     107 R                   2.1           9904
##  8 The Expendables    Feat… Drama     130 R                   2.1         122980
##  9 Avengers: Age of … Docu… Docu…      88 Unrated             7.5            880
## 10 Cutthroat Island   Feat… Drama     100 R                   4.1            739
## # ℹ 6 more variables: critics_rating <chr>, critics_score <dbl>,
## #   audience_rating <chr>, audience_score <dbl>, best_pic_nom <chr>,
## #   Facebook_Likes <dbl>

Step 2A: Merge The Datasets

# Merge the datasets on a common key (original_title is the common key)
merged_data <- merge(financials, general_audience, by = "original_title")
str(merged_data)
## 'data.frame':    665 obs. of  17 variables:
##  $ original_title    : chr  "10,000 B.C. " "102 Dalmatians " "2 Fast 2 Furious " "2012 " ...
##  $ budget (Millions) : num  12.6 45 16 3.5 16 50 50 26 65 8.5 ...
##  $ revenue (Millions): num  18.66 60.22 31.56 0.75 19.68 ...
##  $ language          : chr  NA "English" "English" "English" ...
##  $ country           : chr  NA "USA" "USA" "USA" ...
##  $ type              : chr  "Feature Film" "Feature Film" "Feature Film" "Feature Film" ...
##  $ genre             : chr  "Drama" "Drama" "Mystery & Suspense" "Comedy" ...
##  $ runtime           : num  134 108 97 98 111 106 87 83 100 86 ...
##  $ mpaa_rating       : chr  "R" "PG" "PG-13" "PG-13" ...
##  $ imdb_rating       : num  6.8 4.9 6.3 6.3 6 7.8 5.4 7.6 7 4.1 ...
##  $ imdb_num_votes    : num  9025 5136 54771 8646 103789 ...
##  $ critics_rating    : chr  "Fresh" "Rotten" "Rotten" "Certified Fresh" ...
##  $ critics_score     : num  60 5 40 44 51 75 35 50 70 53 ...
##  $ audience_rating   : chr  "Upright" "Spilled" "Spilled" "Spilled" ...
##  $ audience_score    : num  76 13 49 54 51 85 31 81 74 42 ...
##  $ best_pic_nom      : chr  "no" "no" "no" "no" ...
##  $ Facebook_Likes    : num  23343 84182 35296 445 21583 ...
head(merged_data, n = 1)
##   original_title budget (Millions) revenue (Millions) language country
## 1   10,000 B.C.               12.6              18.66     <NA>    <NA>
##           type genre runtime mpaa_rating imdb_rating imdb_num_votes
## 1 Feature Film Drama     134           R         6.8           9025
##   critics_rating critics_score audience_rating audience_score best_pic_nom
## 1          Fresh            60         Upright             76           no
##   Facebook_Likes
## 1          23343

Step 2B: Data Cleanup and Variable Transformation

Step 2B: Data Cleanup and Variable Transformation

In this step, we focus on cleaning the dataset and transforming variables to make the data more consistent and easier to analyze.

  1. Inspect Unique Genres:
    • We start by inspecting the unique genres present in the dataset using the unique function. This gives us an idea of the various genres we need to work with.
  2. Convert Genres into Categories:
    • We use the mutate and case_when functions from the dplyr package to convert the genre variable into a new categorical variable called GenreCategory.
    • The new categories are: “Exciting/Adventurous”, “Comedy”, “Serious/Emotional”, “Horror”, “Documentary”, “Artistic/Niche”, and “Other”.
    • This transformation helps in grouping similar genres together, making the analysis more streamlined and meaningful.
  3. View the Transformed Dataset:
    • We display the first 10 rows of the transformed dataset to verify the changes.

By converting the genres into broader categories, we simplify the analysis and ensure that each category has a sufficient number of movies for statistical analysis.

# Inspect unique genres
unique_genres <- unique(merged_data$genre)
print(unique_genres)
##  [1] "Drama"                     "Mystery & Suspense"       
##  [3] "Comedy"                    "Action & Adventure"       
##  [5] "Musical & Performing Arts" "Documentary"              
##  [7] "Other"                     "Science Fiction & Fantasy"
##  [9] "Horror"                    "Art House & International"
## [11] "Animation"
# Convert genres into categories
merged_data <- merged_data %>%
  mutate(GenreCategory = case_when(
    genre %in% c("Action & Adventure", "Science Fiction & Fantasy") ~ "Exciting/Adventurous",
    genre %in% c("Comedy") ~ "Comedy",
    genre %in% c("Drama", "Mystery & Suspense") ~ "Serious/Emotional",
    genre %in% c("Horror") ~ "Horror",
    genre %in% c("Documentary") ~ "Documentary",
    genre %in% c("Art House & International", "Musical & Performing Arts", "Animation") ~ "Artistic/Niche",
    genre %in% c("Other") ~ "Other",
    TRUE ~ "Other"
  ))

# View the transformed dataset
head(merged_data, n=10)
##             original_title budget (Millions) revenue (Millions) language
## 1             10,000 B.C.               12.6              18.66     <NA>
## 2          102 Dalmatians               45.0              60.22  English
## 3        2 Fast 2 Furious               16.0              31.56  English
## 4                    2012                3.5               0.75  English
## 5  300: Rise of an Empire               16.0              19.68  English
## 6                47 Ronin               50.0             240.36  English
## 7          50 First Dates               50.0              36.35  English
## 8        A Beautiful Mind               26.0              43.32  English
## 9       A Christmas Carol               65.0             235.67  English
## 10 A Good Day to Die Hard                8.5               5.77  English
##    country         type              genre runtime mpaa_rating imdb_rating
## 1     <NA> Feature Film              Drama     134           R         6.8
## 2      USA Feature Film              Drama     108          PG         4.9
## 3      USA Feature Film Mystery & Suspense      97       PG-13         6.3
## 4      USA Feature Film             Comedy      98       PG-13         6.3
## 5      USA Feature Film Action & Adventure     111       PG-13         6.0
## 6      USA Feature Film              Drama     106          PG         7.8
## 7      USA Feature Film             Comedy      87           R         5.4
## 8      USA Feature Film Action & Adventure      83           G         7.6
## 9      USA Feature Film              Drama     100           R         7.0
## 10     USA Feature Film Action & Adventure      86           R         4.1
##    imdb_num_votes  critics_rating critics_score audience_rating audience_score
## 1            9025           Fresh            60         Upright             76
## 2            5136          Rotten             5         Spilled             13
## 3           54771          Rotten            40         Spilled             49
## 4            8646 Certified Fresh            44         Spilled             54
## 5          103789          Rotten            51         Spilled             51
## 6           12450           Fresh            75         Spilled             85
## 7            6811          Rotten            35         Spilled             31
## 8           78862          Rotten            50         Upright             81
## 9            8320          Rotten            70         Spilled             74
## 10            739           Fresh            53         Upright             42
##    best_pic_nom Facebook_Likes        GenreCategory
## 1            no          23343    Serious/Emotional
## 2            no          84182    Serious/Emotional
## 3            no          35296    Serious/Emotional
## 4            no            445               Comedy
## 5            no          21583 Exciting/Adventurous
## 6            no          20965    Serious/Emotional
## 7            no          12952               Comedy
## 8            no          52827 Exciting/Adventurous
## 9            no          48878    Serious/Emotional
## 10           no           5481 Exciting/Adventurous

Step 2C: Data Visualization

Visualization of genre categories and their count

To understand the distribution of movies across different genres, we create a bar plot showing the count of movies in each GenreCategory.

  1. Create Genre Count Plot:
    • We use the ggplot2 package to create a bar plot.
    • The x-axis represents the GenreCategory, and the y-axis represents the count of movies in each category.
    • We use blue color to fill the bars and apply a minimal theme for a clean look.
    • The x-axis text is rotated for better readability.

This plot helps us visualize the number of movies in each genre category, providing insights into the distribution of movies across different genres. It is particularly useful for identifying genres with high or low production counts.

# Load necessary libraries
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.4.1
library(dplyr)

genre_count_plot <- ggplot(merged_data, aes(x = GenreCategory)) +
  geom_bar(fill = "blue") +
  theme_minimal() +
  labs(title = "Count of Movies in Each Genre Category", x = "Genre Category", y = "Count") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

print(genre_count_plot)

In this visualization, we can see the distribution of movies across different genre categories. This plot provides an overview of the dataset’s genre composition and highlights which genres are most and least represented.

Visualization of revenue by genre category

Next, we analyze the average revenue generated by movies in different genre categories.

  1. Calculate Average Revenue:
    • We group the dataset by GenreCategory and calculate the mean revenue for each category using the summarize function.
  2. Create Average Revenue Plot:
    • We create a bar plot using ggplot2.
    • The x-axis represents the GenreCategory, and the y-axis represents the mean revenue in millions.
    • We use light blue color to fill the bars and apply a minimal theme.
    • The x-axis text is rotated for better readability.

This plot allows us to compare the financial performance of movies across different genres. It highlights which genres tend to generate higher or lower revenues on average, providing valuable insights for financial planning and decision-making in the movie production industry.

average_revenue <- merged_data %>%
  group_by(GenreCategory) %>%
  summarize(mean_revenue = mean(`revenue (Millions)`, na.rm = TRUE))

average_revenue_plot <- ggplot(average_revenue, aes(x = GenreCategory, y = mean_revenue)) +
  geom_bar(stat = "identity", fill = "lightblue") +
  theme_minimal() +
  labs(title = "Average Revenue by Genre Category", x = "Genre Category", y = "Average Revenue (Millions)") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

print(average_revenue_plot)

In this visualization, we can observe the average revenue generated by movies in each genre category. This plot provides insights into which genres tend to generate higher revenue on average, helping us identify potentially more profitable genres.

Visualization of average critics scores by genre category

In this section, we visualize the average critics scores for movies across different genre categories. This analysis helps us understand how critics perceive movies in various genres and identify genres that tend to receive higher or lower ratings.

  1. Calculate Average Critics Scores:
    • We group the dataset by GenreCategory and calculate the mean critics score for each category.
  2. Plot Average Critics Scores:
    • We create a bar plot to visualize the average critics scores in each genre category.
    • The plot uses the GenreCategory variable on the x-axis and mean_critics_score on the y-axis.
    • We customize the plot with a minimal theme and adjust the x-axis text for better readability.

The resulting plot provides insights into the critics’ reception of movies across different genres. By analyzing this visualization, we can identify which genres tend to receive higher or lower critics scores, which may influence decisions on movie production and marketing strategies.

average_critics_score <- merged_data %>%
  group_by(GenreCategory) %>%
  summarize(mean_critics_score = mean(critics_score, na.rm = TRUE))

average_critics_score_plot <- ggplot(average_critics_score, aes(x = GenreCategory, y = mean_critics_score)) +
  geom_bar(stat = "identity", fill = "lightgreen") +
  theme_minimal() +
  labs(title = "Average Critics' Score by Genre Category", x = "Genre Category", y = "Average Critics' Score") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

print(average_critics_score_plot)

Visualization: Average Revenue by Critics Score and Audience Score

In this section, we analyze the relationship between movie scores (both critics and audience) and their average revenue. This analysis helps us understand how the perceived quality of a movie, as measured by scores, impacts its financial performance.

  1. Define Score Bins:
    • We create bins for the scores ranging from 0 to 100 in increments of 10. This helps in grouping the scores into ranges for a more aggregated analysis.
  2. Calculate Average Revenue for Each Critics Score Range:
    • We use the mutate function to create a new variable, CriticScoreBin, which categorizes the critics scores into the defined bins.
    • We then group the data by CriticScoreBin and calculate the average revenue for each bin.
    • A new variable ScoreType is added to indicate that these values are for the critics scores.
  3. Calculate Average Revenue for Each Audience Score Range:
    • Similarly, we create a new variable, AudienceScoreBin, to categorize the audience scores into the defined bins.
    • We group the data by AudienceScoreBin and calculate the average revenue for each bin.
    • The ScoreType variable is set to indicate that these values are for the audience scores.
  4. Combine the Data for Plotting:
    • We use the bind_rows function to combine the average revenue data for both critics and audience scores.
    • The combined data is prepared for plotting, with a unified structure.
  5. Create the Line Plot:
    • We use the ggplot2 package to create a line plot.
    • The x-axis represents the score bins, and the y-axis represents the average revenue in millions.
    • Different colors and line types are used to distinguish between critics scores and audience scores.
    • The plot is customized with a minimal theme and adjusted x-axis text for better readability.

The resulting plot allows us to compare how different ranges of critics and audience scores correlate with average revenue. This visualization provides insights into the impact of scores on the financial performance of movies and can help in understanding audience and critics’ influence on movie success.

# Visualization of revenue vs. critic score and viewer score
score_bins <- seq(0, 100, by = 10)

# Calculate average revenue for each critic score range
critic_avg_revenue <- merged_data %>%
  mutate(CriticScoreBin = cut(critics_score, breaks = score_bins, include.lowest = TRUE)) %>%
  group_by(CriticScoreBin) %>%
  summarize(AverageRevenue = mean(`revenue (Millions)`, na.rm = TRUE)) %>%
  mutate(ScoreType = "Critic")

# Calculate average revenue for each audience score range
audience_avg_revenue <- merged_data %>%
  mutate(AudienceScoreBin = cut(audience_score, breaks = score_bins, include.lowest = TRUE)) %>%
  group_by(AudienceScoreBin) %>%
  summarize(AverageRevenue = mean(`revenue (Millions)`, na.rm = TRUE)) %>%
  mutate(ScoreType = "Audience")

# Combine the data for plotting
avg_revenue_data <- bind_rows(
  critic_avg_revenue %>% rename(ScoreBin = CriticScoreBin),
  audience_avg_revenue %>% rename(ScoreBin = AudienceScoreBin)
)

# Create the line plot
avg_revenue_plot <- ggplot(avg_revenue_data, aes(x = ScoreBin, y = AverageRevenue, color = ScoreType, group = ScoreType)) +
  geom_line(size = 1) +
  geom_point(size = 2) +
  theme_minimal() +
  labs(title = "Average Revenue by Score Range", x = "Score Range", y = "Average Revenue (Millions)", color = "Score Type") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
print(avg_revenue_plot)

Step 3: Analyze how different factors are driving Overall Revenue (predictive analysis)

Multiple Linear Regression Analysis

In this section, we perform a multiple linear regression analysis to identify the factors that significantly impact box office revenue. We include several predictors such as critics score, audience score, budget, runtime, and genre category to build our model.

  1. Load Necessary Libraries:
    • We load the dplyr, ggplot2, and readr libraries to assist with data manipulation, visualization, and reading the data files.
  2. Perform Multiple Linear Regression:
    • We fit a linear regression model (extended_revenue_model) using lm(), where revenue (Millions) is the dependent variable. The independent variables include critics_score, audience_score, budget (Millions), runtime, and GenreCategory.
  3. Summarize the Regression Model:
    • We use summary(extended_revenue_model) to obtain the coefficients, standard errors, t-values, and p-values of the model. This summary helps in understanding the significance and impact of each predictor.
  4. Filter Non-Missing Rows:
    • We create a dataframe model_data that contains only the rows with non-missing values for all the variables used in the model. This ensures the accuracy of our predictions and residuals.
  5. Add Predicted Values and Residuals:
    • Using predict(), we add the predicted revenue values to model_data and calculate the residuals (differences between actual and predicted values) using residuals(). These are added as new columns to model_data.
  6. Create a Dataframe of Coefficients and Their Significance:
    • We extract the coefficients from the regression summary and store them in coefficients_data.
    • We add a column Significance to indicate whether each predictor is statistically significant (p-value < 0.05).
  7. Plot Coefficients:
    • We use ggplot2 to create a bar plot (coefficients_plot) showing the estimated effects of each predictor on box office revenue.
    • The x-axis represents the predictors, ordered by their estimates, and the y-axis represents the estimated effects in millions.
    • The fill color indicates the significance of each predictor, helping to visually identify the most impactful factors.

This analysis helps to identify key factors influencing box office revenue and their relative impact, providing valuable insights for decision-making in movie production and marketing.

# Load necessary libraries
library(dplyr)
library(ggplot2)
library(readr)

# Perform multiple linear regression with additional factors
extended_revenue_model <- lm(`revenue (Millions)` ~ critics_score + audience_score + `budget (Millions)` + runtime + GenreCategory, data = merged_data)

# Summarize the regression model
summary(extended_revenue_model)
## 
## Call:
## lm(formula = `revenue (Millions)` ~ critics_score + audience_score + 
##     `budget (Millions)` + runtime + GenreCategory, data = merged_data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -414.48  -67.04  -13.06   32.49 1472.20 
## 
## Coefficients:
##                                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                       -95.2941    45.3422  -2.102  0.03596 *  
## critics_score                       0.9538     0.4224   2.258  0.02426 *  
## audience_score                      1.4490     0.4703   3.081  0.00215 ** 
## `budget (Millions)`                 2.6104     0.1431  18.238  < 2e-16 ***
## runtime                            -0.1095     0.3300  -0.332  0.74017    
## GenreCategoryComedy                25.0403    31.0802   0.806  0.42073    
## GenreCategoryDocumentary           -0.1702    33.7557  -0.005  0.99598    
## GenreCategoryExciting/Adventurous  -0.5983    31.9242  -0.019  0.98505    
## GenreCategoryHorror                67.9462    41.9162   1.621  0.10550    
## GenreCategoryOther                 24.8498    46.9506   0.529  0.59679    
## GenreCategorySerious/Emotional     -2.0323    27.5882  -0.074  0.94130    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 154.9 on 653 degrees of freedom
##   (1 observation deleted due to missingness)
## Multiple R-squared:  0.4725, Adjusted R-squared:  0.4644 
## F-statistic:  58.5 on 10 and 653 DF,  p-value: < 2.2e-16
# Create a dataframe with non-missing rows used in the model
model_data <- merged_data %>%
  filter(!is.na(`revenue (Millions)`) & 
           !is.na(critics_score) & 
           !is.na(audience_score) & 
           !is.na(`budget (Millions)`) & 
           !is.na(runtime) & 
           !is.na(GenreCategory))

# Add predicted values to the model_data dataframe
model_data <- model_data %>%
  mutate(predicted_revenue = predict(extended_revenue_model, newdata = model_data))

# Add residuals to the model_data dataframe
model_data <- model_data %>%
  mutate(residuals = residuals(extended_revenue_model))

# Create a dataframe of coefficients and their significance
coefficients_data <- as.data.frame(summary(extended_revenue_model)$coefficients)
coefficients_data$Predictor <- rownames(coefficients_data)
rownames(coefficients_data) <- NULL
coefficients_data$Significance <- ifelse(coefficients_data$`Pr(>|t|)` < 0.05, "Significant", "Not Significant")

# Plot coefficients
coefficients_plot <- ggplot(coefficients_data, aes(x = reorder(Predictor, Estimate), y = Estimate, fill = Significance)) +
  geom_bar(stat = "identity") +
  coord_flip() +
  theme_minimal() +
  labs(title = "Impact of Predictors on Box Office Revenue", x = "Predictor", y = "Estimated Effect (Millions)", fill = "Significance")

print(coefficients_plot)

Box Plot of Revenue by Genre Category

In this section, we visualize the distribution of box office revenue across different genre categories using a box plot. This plot helps us understand the spread and central tendency of revenue within each genre, as well as identify any potential outliers.

  1. Load Necessary Libraries:
    • We load the ggplot2 and dplyr libraries to assist with data visualization and manipulation.
  2. Create the Box Plot:
    • We use ggplot2 to create a box plot (genre_revenue_plot) showing the distribution of revenue (Millions) for each GenreCategory.
    • The x-axis represents the genre categories, and the y-axis represents the box office revenue in millions.
  3. Customize the Plot:
    • We use theme_minimal() to give the plot a clean, minimalistic appearance.
    • The labs() function is used to add a title (“Box Office Revenue by Genre Category”) and labels for the x-axis (“Genre Category”) and y-axis (“Revenue (Millions)”).
    • The x-axis text is rotated 45 degrees for better readability using theme(axis.text.x = element_text(angle = 45, hjust = 1)).

This box plot allows us to quickly compare the revenue distributions across different genres, identify which genres tend to have higher or lower revenues, and spot any outliers. This visualization is crucial for understanding the financial performance of movies within different genre categories and making informed decisions about future productions.

# Box plot of revenue by genre category
genre_revenue_plot <- ggplot(model_data, aes(x = GenreCategory, y = `revenue (Millions)`)) +
  geom_boxplot() +
  theme_minimal() +
  labs(title = "Box Office Revenue by Genre Category", x = "Genre Category", y = "Revenue (Millions)") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))

print(genre_revenue_plot)

Correlation Heatmap

In this section, we analyze the correlations between key variables in our dataset. Understanding these correlations helps us identify how different factors are related to each other and to box office revenue.

  1. Calculate Correlation Matrix:
    • We use the cor() function to calculate the correlation matrix for selected variables: critics_score, audience_score, budget (Millions), revenue (Millions), and Facebook_Likes.
    • The use = "complete.obs" parameter ensures that only complete observations are used in the calculation, excluding any missing values.
  2. Plot Correlation Heatmap:
    • We load the reshape2 library to assist with data manipulation required for plotting.
    • The melt() function is used to transform the correlation matrix into a format suitable for ggplot2.
  3. Create the Heatmap:
    • Using ggplot2, we create a heatmap (correlation_heatmap) to visualize the correlation matrix.
    • The geom_tile() function is used to create the heatmap tiles.
    • The scale_fill_gradient2() function is used to color the tiles based on the correlation values, with blue representing negative correlations, red representing positive correlations, and white representing zero correlation.
  4. Customize the Plot:
    • We use theme_minimal() to give the plot a clean, minimalistic appearance.
    • The labs() function is used to add a title (“Correlation Heatmap”).
    • The x-axis text is rotated 45 degrees for better readability using theme(axis.text.x = element_text(angle = 45, hjust = 1)).

This heatmap provides a visual representation of the relationships between key variables in our dataset. Strong correlations can help identify the most influential factors affecting box office revenue, guiding further analysis and decision-making.

# Calculate correlation matrix
correlation_matrix <- model_data %>%
  select(critics_score, audience_score, `budget (Millions)`, `revenue (Millions)`, Facebook_Likes) %>%
  cor(use = "complete.obs")

# Plot correlation heatmap
library(reshape2)
correlation_data <- melt(correlation_matrix)

# Melt the correlation matrix for ggplot2
correlation_data <- melt(correlation_matrix)

# Create the correlation heatmap
correlation_heatmap <- ggplot(correlation_data, aes(x = Var1, y = Var2, fill = value)) +
  geom_tile() +
  scale_fill_gradient2(low = "blue", high = "red", mid = "white", midpoint = 0, limit = c(-1, 1), space = "Lab", name = "Correlation") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  labs(title = "Correlation Heatmap", x = "", y = "")

print(correlation_heatmap)

Step 4: Driving factors differing across genres

Serious/Emotional Genre Analysis

In this section, we focus on analyzing the Serious/Emotional genre to identify the top factors influencing box office revenue.

  1. Filter the Dataset:
    • We filter the merged dataset to include only movies categorized under the “Serious/Emotional” genre.
  2. Perform Multiple Linear Regression:
    • A multiple linear regression model (serious_emotional_model) is fitted using lm(), where revenue (Millions) is the dependent variable.
    • The independent variables include budget (Millions), language, country, type, genre, runtime, mpaa_rating, imdb_rating, imdb_num_votes, critics_rating, critics_score, audience_rating, audience_score, best_pic_nom, and Facebook_Likes.
  3. Summarize the Regression Model:
    • The summary of the regression model (serious_emotional_model_summary) provides details such as coefficients, standard errors, t-values, and p-values for each predictor.
    • This summary helps us understand the significance and impact of each factor on box office revenue.
  4. Extract Coefficients and P-values:
    • The coefficients and their corresponding p-values are extracted and stored in coefficients_data.
    • A new column Predictor is added to store the names of the predictors.
  5. Identify Top Factors:
    • We filter out the intercept and sort the remaining predictors by their p-values.
    • The top two significant predictors are identified and stored in top_factors.
  6. Print Top Factors:
    • Finally, we print the top factors that have the most significant impact on box office revenue for the Serious/Emotional genre.

This analysis helps us identify the key drivers of revenue within the Serious/Emotional genre, providing insights that can be used for strategic decision-making in movie production and marketing.

### Serious/Emotional ##########################################

# Filter the dataset for the Serious/Emotional genre
serious_emotional_data <- merged_data %>% filter(GenreCategory == "Serious/Emotional")

# Perform multiple linear regression for the Serious/Emotional genre including all relevant factors
serious_emotional_model <- lm(`revenue (Millions)` ~ 
                                `budget (Millions)` + language + country + type + genre + runtime + mpaa_rating + 
                                imdb_rating + imdb_num_votes + critics_rating + critics_score + 
                                audience_rating + audience_score + best_pic_nom + Facebook_Likes, 
                              data = serious_emotional_data)

# Summarize the regression model
serious_emotional_model_summary <- summary(serious_emotional_model)

# Get the coefficients and their p-values
coefficients_data <- as.data.frame(serious_emotional_model_summary$coefficients)
coefficients_data$Predictor <- rownames(coefficients_data)
rownames(coefficients_data) <- NULL

# Filter out the intercept and sort by p-value to identify the top 2 significant predictors
top_factors <- coefficients_data %>% 
  filter(Predictor != "(Intercept)") %>% 
  arrange(`Pr(>|t|)`) %>% 
  head(2)

# Print the top factors for Serious/Emotional
print(top_factors)
##       Estimate   Std. Error   t value     Pr(>|t|)           Predictor
## 1 0.0009735339 9.200073e-05 10.581806 8.581564e-23      Facebook_Likes
## 2 1.7146380323 1.904835e-01  9.001504 1.647408e-17 `budget (Millions)`

Exciting/Adventurous Genre Analysis

In this section, we focus on analyzing the Exciting/Adventurous genre to identify the top factors influencing box office revenue.

  1. Filter the Dataset:
    • We filter the merged dataset to include only movies categorized under the “Exciting/Adventurous” genre.
  2. Check Levels of Each Factor:
    • We define a function levels_summary to check the number of unique levels for each factor in the dataset. This helps us identify factors that have only one unique level, which we will exclude from our analysis.
  3. Identify and Exclude Single-Level Factors:
    • Using the levels_summary function, we create a list of factors (single_level_factors) that have only one level. These factors are not informative for regression analysis and are excluded from the list of relevant factors.
  4. Create the Regression Formula:
    • We create a formula string (formula) that includes all relevant factors for the regression analysis, excluding the single-level factors.
  5. Perform Multiple Linear Regression:
    • A multiple linear regression model (exciting_adventurous_model) is fitted using lm(), where revenue (Millions) is the dependent variable. The independent variables include budget (Millions), language, country, type, genre, runtime, mpaa_rating, imdb_rating, imdb_num_votes, critics_rating, critics_score, audience_rating, audience_score, best_pic_nom, and Facebook_Likes.
  6. Summarize the Regression Model:
    • The summary of the regression model (exciting_adventurous_model_summary) provides details such as coefficients, standard errors, t-values, and p-values for each predictor. This summary helps us understand the significance and impact of each factor on box office revenue.
  7. Extract Coefficients and P-values:
    • The coefficients and their corresponding p-values are extracted and stored in coefficients_data. A new column Predictor is added to store the names of the predictors.
  8. Identify Top Factors:
    • We filter out the intercept and sort the remaining predictors by their p-values. The top two significant predictors are identified and stored in top_factors.
  9. Print Top Factors:
    • Finally, we print the top factors that have the most significant impact on box office revenue for the Exciting/Adventurous genre.

This analysis helps us identify the key drivers of revenue within the Exciting/Adventurous genre, providing insights that can be used for strategic decision-making in movie production and marketing.

### Exciting/Adventurous ##########################################

# Filter the dataset for the Exciting/Adventurous genre
exciting_adventurous_data <- merged_data %>% filter(GenreCategory == "Exciting/Adventurous")

# Check levels of each factor in the Exciting/Adventurous genre dataset
levels_summary <- function(data) {
  factors <- c("`budget (Millions)`", "revenue (Millions)", "language", "country", "type", "genre", "runtime",
               "mpaa_rating", "imdb_rating", "imdb_num_votes", "critics_rating", "critics_score", 
               "audience_rating", "audience_score", "best_pic_nom", "Facebook_Likes")
  levels_info <- lapply(factors, function(factor) {
    levels_count <- length(unique(data[[factor]]))
    data.frame(Factor = factor, Levels = levels_count)
  })
  do.call(rbind, levels_info)
}

# Get summary of factor levels
factor_levels <- levels_summary(exciting_adventurous_data)
print(factor_levels)
##                 Factor Levels
## 1  `budget (Millions)`      0
## 2   revenue (Millions)     74
## 3             language      1
## 4              country      5
## 5                 type      1
## 6                genre      2
## 7              runtime     40
## 8          mpaa_rating      4
## 9          imdb_rating     37
## 10      imdb_num_votes     63
## 11      critics_rating      3
## 12       critics_score     46
## 13     audience_rating      2
## 14      audience_score     46
## 15        best_pic_nom      1
## 16      Facebook_Likes     74
# Identify and exclude single-level factors
single_level_factors <- factor_levels %>% filter(Levels == 1) %>% pull(Factor)
print(single_level_factors)
## [1] "language"     "type"         "best_pic_nom"
# List of all relevant factors including numeric ones, excluding single-level factors
all_factors <- c("`budget (Millions)`", "language", "country", "type", "genre", "runtime", "mpaa_rating", 
                 "imdb_rating", "imdb_num_votes", "critics_rating", "critics_score", 
                 "audience_rating", "audience_score", "best_pic_nom", "Facebook_Likes")

# Include only relevant factors and exclude single-level factors
relevant_factors <- setdiff(all_factors, single_level_factors)
print(relevant_factors)
##  [1] "`budget (Millions)`" "country"             "genre"              
##  [4] "runtime"             "mpaa_rating"         "imdb_rating"        
##  [7] "imdb_num_votes"      "critics_rating"      "critics_score"      
## [10] "audience_rating"     "audience_score"      "Facebook_Likes"
# Create formula string with backticks for factors
formula <- as.formula(paste("`revenue (Millions)` ~", paste(relevant_factors, collapse = " + ")))

# Perform multiple linear regression with the filtered factors
exciting_adventurous_model <- lm(formula, data = exciting_adventurous_data)

# Summarize the regression model
exciting_adventurous_model_summary <- summary(exciting_adventurous_model)
print(exciting_adventurous_model_summary)
## 
## Call:
## lm(formula = formula, data = exciting_adventurous_data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -192.35  -37.14    0.00   23.26  285.53 
## 
## Coefficients:
##                                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                    -2.552e+02  1.373e+02  -1.858 0.068475 .  
## `budget (Millions)`             1.566e+00  2.678e-01   5.846 2.85e-07 ***
## countryCanada                  -2.937e+01  8.943e+01  -0.328 0.743876    
## countryFrance                  -6.326e+01  8.947e+01  -0.707 0.482532    
## countryUK                      -6.535e+01  9.327e+01  -0.701 0.486449    
## countryUSA                     -3.125e+01  6.554e+01  -0.477 0.635405    
## genreScience Fiction & Fantasy -1.096e+01  3.229e+01  -0.340 0.735491    
## runtime                         1.360e+00  6.360e-01   2.139 0.036916 *  
## mpaa_ratingPG                   6.474e+01  4.197e+01   1.543 0.128686    
## mpaa_ratingPG-13                4.756e+01  4.317e+01   1.102 0.275319    
## mpaa_ratingR                    6.118e+00  4.162e+01   0.147 0.883671    
## imdb_rating                    -5.006e+00  1.350e+01  -0.371 0.712169    
## imdb_num_votes                 -3.114e-04  1.448e-04  -2.150 0.035967 *  
## critics_ratingFresh            -1.828e+01  4.457e+01  -0.410 0.683347    
## critics_ratingRotten            6.389e+00  5.117e+01   0.125 0.901080    
## critics_score                   1.364e+00  7.266e-01   1.877 0.065838 .  
## audience_ratingUpright         -3.147e+01  3.105e+01  -1.014 0.315186    
## audience_score                  2.682e+00  1.206e+00   2.224 0.030264 *  
## Facebook_Likes                  5.315e-04  1.472e-04   3.610 0.000662 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 82.59 on 55 degrees of freedom
## Multiple R-squared:  0.7858, Adjusted R-squared:  0.7157 
## F-statistic: 11.21 on 18 and 55 DF,  p-value: 1.666e-12
# Get the coefficients and their p-values
coefficients_data <- as.data.frame(exciting_adventurous_model_summary$coefficients)
coefficients_data$Predictor <- rownames(coefficients_data)
rownames(coefficients_data) <- NULL

# Filter out the intercept and sort by p-value to identify the top 2 significant predictors
top_factors <- coefficients_data %>% 
  filter(Predictor != "(Intercept)") %>% 
  arrange(`Pr(>|t|)`) %>% 
  head(2)

# Print the top factors for Exciting/Adventurous
print(top_factors)
##       Estimate   Std. Error  t value     Pr(>|t|)           Predictor
## 1 1.5658102619 0.2678452218 5.845952 2.849681e-07 `budget (Millions)`
## 2 0.0005315113 0.0001472246 3.610207 6.620757e-04      Facebook_Likes

Comedy Genre Analysis

In this section, we focus on analyzing the Comedy genre to identify the top factors influencing box office revenue.

  1. Filter the Dataset:
    • We filter the merged dataset to include only movies categorized under the “Comedy” genre.
  2. Check Levels of Each Factor:
    • We define a function levels_summary to check the number of unique levels for each factor in the dataset. This helps us identify factors that have only one unique level, which we will exclude from our analysis.
  3. Identify and Exclude Single-Level Factors:
    • Using the levels_summary function, we create a list of factors (single_level_factors) that have only one level. These factors are not informative for regression analysis and are excluded from the list of relevant factors.
  4. Create the Regression Formula:
    • We create a formula string (formula) that includes all relevant factors for the regression analysis, excluding the single-level factors.
  5. Perform Multiple Linear Regression:
    • A multiple linear regression model (comedy_model) is fitted using lm(), where revenue (Millions) is the dependent variable. The independent variables include budget (Millions), language, country, type, genre, runtime, mpaa_rating, imdb_rating, imdb_num_votes, critics_rating, critics_score, audience_rating, audience_score, best_pic_nom, and Facebook_Likes.
  6. Summarize the Regression Model:
    • The summary of the regression model (comedy_model_summary) provides details such as coefficients, standard errors, t-values, and p-values for each predictor. This summary helps us understand the significance and impact of each factor on box office revenue.
  7. Extract Coefficients and P-values:
    • The coefficients and their corresponding p-values are extracted and stored in coefficients_data. A new column Predictor is added to store the names of the predictors.
  8. Identify Top Factors:
    • We filter out the intercept and sort the remaining predictors by their p-values. The top two significant predictors are identified and stored in top_factors.
  9. Print Top Factors:
    • Finally, we print the top factors that have the most significant impact on box office revenue for the Comedy genre.

This analysis helps us identify the key drivers of revenue within the Comedy genre, providing insights that can be used for strategic decision-making in movie production and marketing.

### Comedy ##########################################

# Filter the dataset for the Comedy genre
comedy_data <- merged_data %>% filter(GenreCategory == "Comedy")

# Check levels of each factor in the Comedy genre dataset
levels_summary <- function(data) {
  factors <- c("`budget (Millions)`", "revenue (Millions)", "language", "country", "type", "genre", "runtime",
               "mpaa_rating", "imdb_rating", "imdb_num_votes", "critics_rating", "critics_score", 
               "audience_rating", "audience_score", "best_pic_nom", "Facebook_Likes")
  levels_info <- lapply(factors, function(factor) {
    levels_count <- length(unique(data[[factor]]))
    data.frame(Factor = factor, Levels = levels_count)
  })
  do.call(rbind, levels_info)
}

# Get summary of factor levels
factor_levels <- levels_summary(comedy_data)
print(factor_levels)
##                 Factor Levels
## 1  `budget (Millions)`      0
## 2   revenue (Millions)     89
## 3             language      3
## 4              country      8
## 5                 type      2
## 6                genre      1
## 7              runtime     33
## 8          mpaa_rating      4
## 9          imdb_rating     43
## 10      imdb_num_votes     68
## 11      critics_rating      3
## 12       critics_score     53
## 13     audience_rating      2
## 14      audience_score     48
## 15        best_pic_nom      2
## 16      Facebook_Likes     87
# Identify and exclude single-level factors
single_level_factors <- factor_levels %>% filter(Levels == 1) %>% pull(Factor)
print(single_level_factors)
## [1] "genre"
# List of all relevant factors including numeric ones, excluding single-level factors
all_factors <- c("`budget (Millions)`", "language", "country", "type", "genre", "runtime", "mpaa_rating", 
                 "imdb_rating", "imdb_num_votes", "critics_rating", "critics_score", 
                 "audience_rating", "audience_score", "best_pic_nom", "Facebook_Likes")

# Include only relevant factors and exclude single-level factors
relevant_factors <- setdiff(all_factors, single_level_factors)
print(relevant_factors)
##  [1] "`budget (Millions)`" "language"            "country"            
##  [4] "type"                "runtime"             "mpaa_rating"        
##  [7] "imdb_rating"         "imdb_num_votes"      "critics_rating"     
## [10] "critics_score"       "audience_rating"     "audience_score"     
## [13] "best_pic_nom"        "Facebook_Likes"
# Create formula string with backticks for factors
formula <- as.formula(paste("`revenue (Millions)` ~", paste(relevant_factors, collapse = " + ")))

# Perform multiple linear regression with the filtered factors
comedy_model <- lm(formula, data = comedy_data)

# Summarize the regression model
comedy_model_summary <- summary(comedy_model)
print(comedy_model_summary)
## 
## Call:
## lm(formula = formula, data = comedy_data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -439.53  -21.71    0.00   25.45  583.57 
## 
## Coefficients: (1 not defined because of singularities)
##                          Estimate Std. Error t value Pr(>|t|)    
## (Intercept)            -2.687e+02  2.655e+02  -1.012    0.315    
## `budget (Millions)`     2.052e+00  3.841e-01   5.341 1.27e-06 ***
## languageFrench         -1.941e+01  1.519e+02  -0.128    0.899    
## languageJapanese        1.699e+02  1.883e+02   0.902    0.370    
## countryCanada          -6.557e+01  9.716e+01  -0.675    0.502    
## countryFrance          -1.764e+01  1.003e+02  -0.176    0.861    
## countryGermany          6.214e+01  1.399e+02   0.444    0.658    
## countryJapan           -2.265e+01  1.628e+02  -0.139    0.890    
## countryNew Zealand      2.198e+02  1.535e+02   1.432    0.157    
## countryUK               2.785e+01  1.042e+02   0.267    0.790    
## countryUSA              9.341e+00  7.579e+01   0.123    0.902    
## typeFeature Film        9.926e+01  9.768e+01   1.016    0.313    
## runtime                 3.039e-01  1.354e+00   0.224    0.823    
## mpaa_ratingPG           5.572e+01  1.305e+02   0.427    0.671    
## mpaa_ratingPG-13        3.577e+01  1.265e+02   0.283    0.778    
## mpaa_ratingR            4.323e+01  1.288e+02   0.336    0.738    
## imdb_rating            -1.067e+00  1.768e+01  -0.060    0.952    
## imdb_num_votes         -2.034e-04  1.921e-04  -1.059    0.294    
## critics_ratingFresh     3.403e+01  5.516e+01   0.617    0.539    
## critics_ratingRotten   -1.143e+01  5.982e+01  -0.191    0.849    
## critics_score           6.249e-01  1.081e+00   0.578    0.565    
## audience_ratingUpright -3.193e+01  4.834e+01  -0.661    0.511    
## audience_score          1.669e+00  1.676e+00   0.996    0.323    
## best_pic_nomyes                NA         NA      NA       NA    
## Facebook_Likes          8.844e-04  1.963e-04   4.505 2.83e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 120.1 on 65 degrees of freedom
## Multiple R-squared:  0.7646, Adjusted R-squared:  0.6813 
## F-statistic: 9.178 on 23 and 65 DF,  p-value: 8.564e-13
# Get the coefficients and their p-values
coefficients_data <- as.data.frame(comedy_model_summary$coefficients)
coefficients_data$Predictor <- rownames(coefficients_data)
rownames(coefficients_data) <- NULL

# Filter out the intercept and sort by p-value to identify the top 2 significant predictors
top_factors <- coefficients_data %>% 
  filter(Predictor != "(Intercept)") %>% 
  arrange(`Pr(>|t|)`) %>% 
  head(2)

# Print the top factors for Comedy
print(top_factors)
##       Estimate   Std. Error  t value     Pr(>|t|)           Predictor
## 1 2.0516594523 0.3841315997 5.341033 1.265400e-06 `budget (Millions)`
## 2 0.0008844395 0.0001963212 4.505064 2.827283e-05      Facebook_Likes

Horror Genre Analysis

In this section, we focus on analyzing the Horror genre to identify the top factors influencing box office revenue.

  1. Filter the Dataset:
    • We filter the merged dataset to include only movies categorized under the “Horror” genre.
  2. Check Levels of Each Factor:
    • We define a function levels_summary to check the number of unique levels for each factor in the dataset. This helps us identify factors that have only one unique level, which we will exclude from our analysis.
  3. Identify and Exclude Single-Level Factors:
    • Using the levels_summary function, we create a list of factors (single_level_factors) that have only one level. These factors are not informative for regression analysis and are excluded from the list of relevant factors.
  4. Create the Regression Formula:
    • We create a formula string (formula) that includes all relevant factors for the regression analysis, excluding the single-level factors.
  5. Perform Multiple Linear Regression:
    • A multiple linear regression model (horror_model) is fitted using lm(), where revenue (Millions) is the dependent variable. The independent variables include budget (Millions), language, country, type, genre, runtime, mpaa_rating, imdb_rating, imdb_num_votes, critics_rating, critics_score, audience_rating, audience_score, best_pic_nom, and Facebook_Likes.
  6. Summarize the Regression Model:
    • The summary of the regression model (horror_model_summary) provides details such as coefficients, standard errors, t-values, and p-values for each predictor. This summary helps us understand the significance and impact of each factor on box office revenue.
  7. Extract Coefficients and P-values:
    • The coefficients and their corresponding p-values are extracted and stored in coefficients_data. A new column Predictor is added to store the names of the predictors.
  8. Identify Top Factors:
    • We filter out the intercept and sort the remaining predictors by their p-values. The top two significant predictors are identified and stored in top_factors.
  9. Print Top Factors:
    • Finally, we print the top factors that have the most significant impact on box office revenue for the Horror genre.

This analysis helps us identify the key drivers of revenue within the Horror genre, providing insights that can be used for strategic decision-making in movie production and marketing.

### Horror ##########################################

# Filter the dataset for the Horror genre
horror_data <- merged_data %>% filter(GenreCategory == "Horror")

# Check levels of each factor in the Horror genre dataset
levels_summary <- function(data) {
  factors <- c("`budget (Millions)`", "revenue (Millions)", "language", "country", "type", "genre", "runtime",
               "mpaa_rating", "imdb_rating", "imdb_num_votes", "critics_rating", "critics_score", 
               "audience_rating", "audience_score", "best_pic_nom", "Facebook_Likes")
  levels_info <- lapply(factors, function(factor) {
    levels_count <- length(unique(data[[factor]]))
    data.frame(Factor = factor, Levels = levels_count)
  })
  do.call(rbind, levels_info)
}

# Get summary of factor levels
factor_levels <- levels_summary(horror_data)
print(factor_levels)
##                 Factor Levels
## 1  `budget (Millions)`      0
## 2   revenue (Millions)     23
## 3             language      2
## 4              country      4
## 5                 type      1
## 6                genre      1
## 7              runtime     17
## 8          mpaa_rating      3
## 9          imdb_rating     19
## 10      imdb_num_votes     20
## 11      critics_rating      3
## 12       critics_score     21
## 13     audience_rating      2
## 14      audience_score     18
## 15        best_pic_nom      1
## 16      Facebook_Likes     23
# Identify and exclude single-level factors
single_level_factors <- factor_levels %>% filter(Levels == 1) %>% pull(Factor)
print(single_level_factors)
## [1] "type"         "genre"        "best_pic_nom"
# List of all relevant factors including numeric ones, excluding single-level factors
all_factors <- c("`budget (Millions)`", "language", "country", "type", "genre", "runtime", "mpaa_rating", 
                 "imdb_rating", "imdb_num_votes", "critics_rating", "critics_score", 
                 "audience_rating", "audience_score", "best_pic_nom", "Facebook_Likes")

# Include only relevant factors and exclude single-level factors
relevant_factors <- setdiff(all_factors, single_level_factors)
print(relevant_factors)
##  [1] "`budget (Millions)`" "language"            "country"            
##  [4] "runtime"             "mpaa_rating"         "imdb_rating"        
##  [7] "imdb_num_votes"      "critics_rating"      "critics_score"      
## [10] "audience_rating"     "audience_score"      "Facebook_Likes"
# Create formula string with backticks for factors
formula <- as.formula(paste("`revenue (Millions)` ~", paste(relevant_factors, collapse = " + ")))

# Perform multiple linear regression with the filtered factors
horror_model <- lm(formula, data = horror_data)

# Summarize the regression model
horror_model_summary <- summary(horror_model)
print(horror_model_summary)
## 
## Call:
## lm(formula = formula, data = horror_data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -90.461 -48.210  -9.264  52.918 121.117 
## 
## Coefficients: (1 not defined because of singularities)
##                          Estimate Std. Error t value Pr(>|t|)  
## (Intercept)             1.378e+03  6.042e+02   2.280   0.0566 .
## `budget (Millions)`     3.931e+00  1.245e+00   3.157   0.0160 *
## languageFrench          3.023e+00  3.042e+02   0.010   0.9923  
## countryFrance                  NA         NA      NA       NA  
## countryUK              -3.346e+02  2.345e+02  -1.427   0.1967  
## countryUSA             -4.043e+02  2.554e+02  -1.583   0.1575  
## runtime                -5.744e+00  4.182e+00  -1.374   0.2119  
## mpaa_ratingR           -2.098e+02  1.325e+02  -1.583   0.1574  
## mpaa_ratingUnrated     -4.866e+01  2.000e+02  -0.243   0.8147  
## imdb_rating             4.510e+01  6.057e+01   0.745   0.4808  
## imdb_num_votes         -5.918e-04  1.532e-03  -0.386   0.7108  
## critics_ratingFresh    -5.387e+02  1.592e+02  -3.385   0.0117 *
## critics_ratingRotten   -2.460e+02  1.396e+02  -1.762   0.1214  
## critics_score          -3.490e+00  3.480e+00  -1.003   0.3494  
## audience_ratingUpright  3.791e+02  1.564e+02   2.424   0.0458 *
## audience_score         -5.808e+00  5.651e+00  -1.028   0.3383  
## Facebook_Likes          5.347e-04  8.100e-04   0.660   0.5303  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 111.4 on 7 degrees of freedom
## Multiple R-squared:  0.9657, Adjusted R-squared:  0.8922 
## F-statistic: 13.13 on 15 and 7 DF,  p-value: 0.001047
# Get the coefficients and their p-values
coefficients_data <- as.data.frame(horror_model_summary$coefficients)
coefficients_data$Predictor <- rownames(coefficients_data)
rownames(coefficients_data) <- NULL

# Filter out the intercept and sort by p-value to identify the top 2 significant predictors
top_factors <- coefficients_data %>% 
  filter(Predictor != "(Intercept)") %>% 
  arrange(`Pr(>|t|)`) %>% 
  head(2)

# Print the top factors for Horror
print(top_factors)
##      Estimate Std. Error   t value   Pr(>|t|)           Predictor
## 1 -538.698203 159.165062 -3.384525 0.01168633 critics_ratingFresh
## 2    3.930783   1.245251  3.156620 0.01600357 `budget (Millions)`

Documentary Genre Analysis

In this section, we focus on analyzing the Documentary genre to identify the top factors influencing box office revenue.

  1. Filter the Dataset:
    • We filter the merged dataset to include only movies categorized under the “Documentary” genre.
  2. Check Levels of Each Factor:
    • We define a function levels_summary to check the number of unique levels for each factor in the dataset. This helps us identify factors that have only one unique level, which we will exclude from our analysis.
  3. Identify and Exclude Single-Level Factors:
    • Using the levels_summary function, we create a list of factors (single_level_factors) that have only one level. These factors are not informative for regression analysis and are excluded from the list of relevant factors.
  4. Create the Regression Formula:
    • We create a formula string (formula) that includes all relevant factors for the regression analysis, excluding the single-level factors.
  5. Perform Multiple Linear Regression:
    • A multiple linear regression model (documentary_model) is fitted using lm(), where revenue (Millions) is the dependent variable. The independent variables include budget (Millions), language, country, type, genre, runtime, mpaa_rating, imdb_rating, imdb_num_votes, critics_rating, critics_score, audience_rating, audience_score, best_pic_nom, and Facebook_Likes.
  6. Summarize the Regression Model:
    • The summary of the regression model (documentary_model_summary) provides details such as coefficients, standard errors, t-values, and p-values for each predictor. This summary helps us understand the significance and impact of each factor on box office revenue.
  7. Extract Coefficients and P-values:
    • The coefficients and their corresponding p-values are extracted and stored in coefficients_data. A new column Predictor is added to store the names of the predictors.
  8. Identify Top Factors:
    • We filter out the intercept and sort the remaining predictors by their p-values. The top two significant predictors are identified and stored in top_factors.
  9. Print Top Factors:
    • Finally, we print the top factors that have the most significant impact on box office revenue for the Documentary genre.

This analysis helps us identify the key drivers of revenue within the Documentary genre, providing insights that can be used for strategic decision-making in movie production and marketing.

### Documentary ##########################################

# Filter the dataset for the Documentary genre
documentary_data <- merged_data %>% filter(GenreCategory == "Documentary")

# Check levels of each factor in the Documentary genre dataset
levels_summary <- function(data) {
  factors <- c("`budget (Millions)`", "revenue (Millions)", "language", "country", "type", "genre", "runtime",
               "mpaa_rating", "imdb_rating", "imdb_num_votes", "critics_rating", "critics_score", 
               "audience_rating", "audience_score", "best_pic_nom", "Facebook_Likes")
  levels_info <- lapply(factors, function(factor) {
    levels_count <- length(unique(data[[factor]]))
    data.frame(Factor = factor, Levels = levels_count)
  })
  do.call(rbind, levels_info)
}

# Get summary of factor levels
factor_levels <- levels_summary(documentary_data)
print(factor_levels)
##                 Factor Levels
## 1  `budget (Millions)`      0
## 2   revenue (Millions)     54
## 3             language      1
## 4              country      5
## 5                 type      2
## 6                genre      1
## 7              runtime     35
## 8          mpaa_rating      5
## 9          imdb_rating     29
## 10      imdb_num_votes     43
## 11      critics_rating      3
## 12       critics_score     38
## 13     audience_rating      2
## 14      audience_score     37
## 15        best_pic_nom      2
## 16      Facebook_Likes     53
# Identify and exclude single-level factors
single_level_factors <- factor_levels %>% filter(Levels == 1) %>% pull(Factor)
print(single_level_factors)
## [1] "language" "genre"
# List of all relevant factors including numeric ones, excluding single-level factors
all_factors <- c("`budget (Millions)`", "language", "country", "type", "genre", "runtime", "mpaa_rating", 
                 "imdb_rating", "imdb_num_votes", "critics_rating", "critics_score", 
                 "audience_rating", "audience_score", "best_pic_nom", "Facebook_Likes")

# Include only relevant factors and exclude single-level factors
relevant_factors <- setdiff(all_factors, single_level_factors)
print(relevant_factors)
##  [1] "`budget (Millions)`" "country"             "type"               
##  [4] "runtime"             "mpaa_rating"         "imdb_rating"        
##  [7] "imdb_num_votes"      "critics_rating"      "critics_score"      
## [10] "audience_rating"     "audience_score"      "best_pic_nom"       
## [13] "Facebook_Likes"
# Create formula string with backticks for factors
formula <- as.formula(paste("`revenue (Millions)` ~", paste(relevant_factors, collapse = " + ")))

# Perform multiple linear regression with the filtered factors
documentary_model <- lm(formula, data = documentary_data)

# Summarize the regression model
documentary_model_summary <- summary(documentary_model)
print(documentary_model_summary)
## 
## Call:
## lm(formula = formula, data = documentary_data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -232.90  -70.62   -9.94   23.65  921.25 
## 
## Coefficients: (1 not defined because of singularities)
##                          Estimate Std. Error t value Pr(>|t|)  
## (Intercept)            -3.488e+02  2.870e+02  -1.216   0.2323  
## `budget (Millions)`     1.096e+00  9.428e-01   1.163   0.2527  
## countryCanada           3.362e+02  4.125e+02   0.815   0.4206  
## countryGermany          1.584e+02  3.491e+02   0.454   0.6527  
## countryUK               2.037e+02  2.809e+02   0.725   0.4733  
## countryUSA              2.178e+02  2.299e+02   0.947   0.3499  
## typeFeature Film       -1.528e+02  1.823e+02  -0.838   0.4075  
## runtime                -3.954e-01  1.161e+00  -0.341   0.7355  
## mpaa_ratingPG           3.136e+01  1.650e+02   0.190   0.8503  
## mpaa_ratingPG-13        6.681e+01  2.018e+02   0.331   0.7426  
## mpaa_ratingR            1.107e+02  1.844e+02   0.601   0.5520  
## mpaa_ratingUnrated      1.104e+02  1.565e+02   0.705   0.4852  
## imdb_rating            -1.736e+00  4.421e+00  -0.393   0.6970  
## imdb_num_votes          2.713e-04  1.374e-03   0.197   0.8446  
## critics_ratingFresh     1.064e+02  8.484e+01   1.255   0.2179  
## critics_ratingRotten    1.040e+02  2.218e+02   0.469   0.6420  
## critics_score          -2.472e+00  5.164e+00  -0.479   0.6352  
## audience_ratingUpright         NA         NA      NA       NA  
## audience_score          3.733e+00  5.036e+00   0.741   0.4636  
## best_pic_nomyes         1.210e+02  3.584e+02   0.338   0.7377  
## Facebook_Likes          1.025e-03  3.986e-04   2.572   0.0145 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 214.1 on 35 degrees of freedom
##   (1 observation deleted due to missingness)
## Multiple R-squared:  0.4138, Adjusted R-squared:  0.09551 
## F-statistic:   1.3 on 19 and 35 DF,  p-value: 0.2443
# Get the coefficients and their p-values
coefficients_data <- as.data.frame(documentary_model_summary$coefficients)
coefficients_data$Predictor <- rownames(coefficients_data)
rownames(coefficients_data) <- NULL

# Filter out the intercept and sort by p-value to identify the top 2 significant predictors
top_factors <- coefficients_data %>% 
  filter(Predictor != "(Intercept)") %>% 
  arrange(`Pr(>|t|)`) %>% 
  head(2)

# Print the top factors for Documentary
print(top_factors)
##       Estimate   Std. Error  t value   Pr(>|t|)           Predictor
## 1 1.025095e-03 3.986069e-04 2.571695 0.01452564      Facebook_Likes
## 2 1.064440e+02 8.484046e+01 1.254637 0.21792452 critics_ratingFresh

Artistic/Niche Genre Analysis

In this section, we analyze the Artistic/Niche genre to identify the top factors influencing box office revenue.

  1. Filter the Dataset:
    • We filter the merged dataset to include only movies categorized under the “Artistic/Niche” genre.
  2. Check Levels of Each Factor:
    • We define a function levels_summary to check the number of unique levels for each factor in the dataset. This helps us identify factors that have only one unique level, which we will exclude from our analysis.
  3. Identify and Exclude Single-Level Factors:
    • Using the levels_summary function, we create a list of factors (single_level_factors) that have only one level. These factors are not informative for regression analysis and are excluded from the list of relevant factors.
  4. Create the Regression Formula:
    • We create a formula string (formula) that includes all relevant factors for the regression analysis, excluding the single-level factors.
  5. Perform Multiple Linear Regression:
    • A multiple linear regression model (artistic_niche_model) is fitted using lm(), where revenue (Millions) is the dependent variable. The independent variables include budget (Millions), language, country, type, runtime, mpaa_rating, imdb_rating, imdb_num_votes, critics_rating, critics_score, audience_rating, audience_score, best_pic_nom, and Facebook_Likes.
  6. Summarize the Regression Model:
    • The summary of the regression model (artistic_niche_model_summary) provides details such as coefficients, standard errors, t-values, and p-values for each predictor. This summary helps us understand the significance and impact of each factor on box office revenue.
  7. Extract Coefficients and P-values:
    • The coefficients and their corresponding p-values are extracted and stored in coefficients_data. A new column Predictor is added to store the names of the predictors.
  8. Identify Top Factors:
    • We filter out the intercept and sort the remaining predictors by their p-values. The top two significant predictors are identified and stored in top_factors.
  9. Print Top Factors:
    • Finally, we print the top factors that have the most significant impact on box office revenue for the Artistic/Niche genre.

This analysis helps us identify the key drivers of revenue within the Artistic/Niche genre, providing insights that can be used for strategic decision-making in movie production and marketing.

### Artistic/Niche ##########################################

# Filter the dataset for the Artistic/Niche genre
artistic_niche_data <- merged_data %>% filter(GenreCategory == "Artistic/Niche")

# Check levels of each factor in the Artistic/Niche genre dataset
levels_summary <- function(data) {
  factors <- c("`budget (Millions)`", "revenue (Millions)", "language", "country", "type", "runtime",
               "mpaa_rating", "imdb_rating", "imdb_num_votes", "critics_rating", "critics_score", 
               "audience_rating", "audience_score", "best_pic_nom", "Facebook_Likes")
  levels_info <- lapply(factors, function(factor) {
    levels_count <- length(unique(data[[factor]]))
    data.frame(Factor = factor, Levels = levels_count)
  })
  do.call(rbind, levels_info)
}

# Get summary of factor levels
factor_levels <- levels_summary(artistic_niche_data)
print(factor_levels)
##                 Factor Levels
## 1  `budget (Millions)`      0
## 2   revenue (Millions)     34
## 3             language      1
## 4              country      4
## 5                 type      2
## 6              runtime     30
## 7          mpaa_rating      5
## 8          imdb_rating     21
## 9       imdb_num_votes     31
## 10      critics_rating      3
## 11       critics_score     28
## 12     audience_rating      2
## 13      audience_score     28
## 14        best_pic_nom      1
## 15      Facebook_Likes     35
# Identify and exclude single-level factors
single_level_factors <- factor_levels %>% filter(Levels == 1) %>% pull(Factor)
print(single_level_factors)
## [1] "language"     "best_pic_nom"
# List of all relevant factors including numeric ones, excluding single-level factors
all_factors <- c("`budget (Millions)`", "language", "country", "type", "runtime", "mpaa_rating", 
                 "imdb_rating", "imdb_num_votes", "critics_rating", "critics_score", 
                 "audience_rating", "audience_score", "best_pic_nom", "Facebook_Likes")

# Include only relevant factors and exclude single-level factors
relevant_factors <- setdiff(all_factors, single_level_factors)
print(relevant_factors)
##  [1] "`budget (Millions)`" "country"             "type"               
##  [4] "runtime"             "mpaa_rating"         "imdb_rating"        
##  [7] "imdb_num_votes"      "critics_rating"      "critics_score"      
## [10] "audience_rating"     "audience_score"      "Facebook_Likes"
# Create formula string with backticks for factors
formula <- as.formula(paste("`revenue (Millions)` ~", paste(relevant_factors, collapse = " + ")))

# Perform multiple linear regression with the filtered factors
artistic_niche_model <- lm(formula, data = artistic_niche_data)

# Summarize the regression model
artistic_niche_model_summary <- summary(artistic_niche_model)
print(artistic_niche_model_summary)
## 
## Call:
## lm(formula = formula, data = artistic_niche_data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -146.20  -36.20    0.00   29.63  133.95 
## 
## Coefficients:
##                          Estimate Std. Error t value Pr(>|t|)    
## (Intercept)             6.687e+01  2.337e+02   0.286   0.7785    
## `budget (Millions)`     1.654e+00  6.281e-01   2.633   0.0181 *  
## countryGermany          2.137e+02  1.480e+02   1.444   0.1680    
## countryNew Line        -1.290e+02  1.434e+02  -0.899   0.3819    
## countryUSA             -9.602e+01  1.063e+02  -0.903   0.3798    
## typeFeature Film        5.134e+01  5.489e+01   0.935   0.3635    
## runtime                -6.223e-01  1.889e+00  -0.329   0.7461    
## mpaa_ratingPG           1.090e+02  7.543e+01   1.444   0.1679    
## mpaa_ratingPG-13        7.555e+01  1.104e+02   0.685   0.5034    
## mpaa_ratingR            4.622e+01  8.306e+01   0.556   0.5856    
## mpaa_ratingUnrated      8.934e+01  9.142e+01   0.977   0.3430    
## imdb_rating             5.044e+00  3.673e+01   0.137   0.8925    
## imdb_num_votes         -1.729e-04  2.755e-04  -0.628   0.5391    
## critics_ratingFresh    -1.022e+01  6.411e+01  -0.159   0.8753    
## critics_ratingRotten   -1.084e+02  1.089e+02  -0.996   0.3342    
## critics_score          -1.301e+00  2.275e+00  -0.572   0.5752    
## audience_ratingUpright -2.965e+01  6.359e+01  -0.466   0.6473    
## audience_score          1.071e+00  2.819e+00   0.380   0.7089    
## Facebook_Likes          1.127e-03  1.617e-04   6.968 3.17e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 86.49 on 16 degrees of freedom
## Multiple R-squared:  0.8975, Adjusted R-squared:  0.7822 
## F-statistic: 7.784 on 18 and 16 DF,  p-value: 7.322e-05
# Get the coefficients and their p-values
coefficients_data <- as.data.frame(artistic_niche_model_summary$coefficients)
coefficients_data$Predictor <- rownames(coefficients_data)
rownames(coefficients_data) <- NULL

# Filter out the intercept and sort by p-value to identify the top 2 significant predictors
top_factors <- coefficients_data %>% 
  filter(Predictor != "(Intercept)") %>% 
  arrange(`Pr(>|t|)`) %>% 
  head(2)

# Print the top factors for Artistic/Niche
print(top_factors)
##      Estimate  Std. Error  t value     Pr(>|t|)           Predictor
## 1 0.001126647 0.000161679 6.968419 3.166682e-06      Facebook_Likes
## 2 1.653541624 0.628102438 2.632599 1.809997e-02 `budget (Millions)`

Step 6: Predicting Box Office Sales and Evaluating Advertising Campaign Impact

In this section, we will predict the box office sales for a movie given specific conditions and evaluate the impact of an advertising campaign on the predicted revenue.

  1. Define Model Coefficients:
    • We use coefficients from the overall analysis. These include:
      • Intercept: -80.75 (example intercept from Serious/Emotional genre).
      • Critics Score Coefficient: 0.9735339.
      • Facebook Likes Coefficient: 0.0009735339.
      • Budget Coefficient: 1.7146380323.
      • Runtime Coefficient: 0.5546 (example coefficient, adjust as needed).
      • IMDb Rating Coefficient: -8.425 (example coefficient, adjust as needed).
  2. Ensure All Necessary Coefficients are Included:
    • We combine all the coefficients into a vector named coefficients to ensure we have all necessary parameters for our prediction model.

This setup will be used to predict the box office sales under given conditions and assess the effect of an advertising campaign on revenue.

# Define model coefficients from the overall analysis
intercept <- -80.75  # Example intercept from Serious/Emotional genre
coef_critics_score <- 0.9735339
coef_facebook_likes <- 0.0009735339
coef_budget <- 1.7146380323
coef_runtime <- 0.5546  # Example coefficient, adjust as needed
coef_imdb_rating <- -8.425  # Example coefficient, adjust as needed

# Ensure all necessary coefficients are included
coefficients <- c(intercept, coef_critics_score, coef_facebook_likes, coef_budget, coef_runtime, coef_imdb_rating)

Step 6a: Predicting Box Office Sales with Given Values

In this step, we predict the box office sales for a movie given specific values for the predictors. The values used for prediction are as follows:

  • Critics Score: 55
  • Facebook Likes: 1,250
  • Budget: $20 million
  • Runtime: 120 minutes
  • IMDb Rating: 7.0

These values will be used along with the model coefficients to calculate the predicted revenue.

critics_score <- 55
facebook_likes <- 1250
budget <- 20  # Example budget
runtime <- 120  # Example runtime
imdb_rating <- 7.0  # Example IMDb rating

# Calculate predicted revenue
predicted_revenue <- intercept + 
  (coef_critics_score * critics_score) + 
  (coef_facebook_likes * facebook_likes) +
  (coef_budget * budget) +
  (coef_runtime * runtime) +
  (coef_imdb_rating * imdb_rating)

cat("Predicted box office sales for the movie:", predicted_revenue, "million dollars\n")
## Predicted box office sales for the movie: 15.88104 million dollars

Step 6b: Impact of Advertising Campaign

In this step, we assess the impact of an advertising campaign on the predicted box office revenue. The scenario involves increasing the movie budget and the number of Facebook likes as a result of the campaign.

Scenario Details:

  • Current Budget: $10 million
  • New Budget: $20 million
  • Current Facebook Likes: 1,250
  • Expected Increase in Facebook Likes: 10,000% (100 times increase)

Using these values, we calculate the new predicted revenue and determine the improvement in revenue due to the campaign.

current_budget <- 10
new_budget <- 20
current_facebook_likes <- 1250
expected_increase_factor <- 100
new_facebook_likes <- current_facebook_likes * expected_increase_factor

# Calculate new predicted revenue after the campaign
new_predicted_revenue <- intercept + 
  (coef_budget * new_budget) + 
  (coef_facebook_likes * new_facebook_likes) +
  (coef_runtime * runtime) +  # Assuming runtime remains the same
  (coef_imdb_rating * imdb_rating) +  # Assuming IMDb rating remains the same
  (coef_critics_score * critics_score)  # Assuming critics score remains the same

cat("Predicted box office sales after the advertising campaign:", new_predicted_revenue, "million dollars\n")
## Predicted box office sales after the advertising campaign: 136.3559 million dollars
# Calculate the improvement in revenue
revenue_improvement <- new_predicted_revenue - predicted_revenue
cat("Expected improvement in revenue:", revenue_improvement, "million dollars\n")
## Expected improvement in revenue: 120.4748 million dollars