Project purpose

This analysis uses a saved random half-sample of the beauty-product dataset. The project examines whether price, customer engagement, product category, and cruelty-free status are associated with product ratings. Because the data are observational, the results describe associations rather than cause-and-effect relationships.

1. Load packages and data

library(ggplot2)
library(dplyr)

# Use the saved sample shown in the presentation.
df <- read.csv("Kaggle_Analysis_7500.csv")

# Check the data before analyzing it.
head(df)
##   Source_Row       Product_Name                   Brand    Category
## 1       6307      Magic Bronzer Anastasia Beverly Hills   Lip Liner
## 2       1780    Magic Lip Gloss              Patrick Ta    Lipstick
## 3       6153        Ultra Serum Anastasia Beverly Hills     Mascara
## 4       9617  Perfect Face Mask                  E.l.f. Highlighter
## 5      11211 Divine Highlighter                Clinique    Cleanser
## 6      14502     Ultra CC Cream      Yves Saint Laurent       Blush
##   Usage_Frequency Price_USD Rating Number_of_Reviews Product_Size Skin_Type
## 1          Weekly    146.79    4.6              1746        100ml       Dry
## 2           Daily     17.81    1.1              6039        100ml Sensitive
## 3      Occasional    119.74    4.4              9866         30ml Sensitive
## 4           Daily    105.73    1.4              6763        250ml      Oily
## 5         Monthly    148.14    1.8              3715        250ml      Oily
## 6         Monthly     98.82    4.4              5282        250ml      Oily
##   Gender_Target Packaging_Type Main_Ingredient Cruelty_Free Country_of_Origin
## 1        Female          Spray Hyaluronic Acid        False             Japan
## 2        Unisex            Jar       Aloe Vera        False               USA
## 3        Unisex            Jar       Vitamin C         True           Germany
## 4        Female          Stick        Glycerin         True            France
## 5        Female            Jar Hyaluronic Acid        False                UK
## 6        Female            Jar  Salicylic Acid         True            France
str(df)
## 'data.frame':    7500 obs. of  15 variables:
##  $ Source_Row       : int  6307 1780 6153 9617 11211 14502 13106 10637 103 4055 ...
##  $ Product_Name     : chr  "Magic Bronzer" "Magic Lip Gloss" "Ultra Serum" "Perfect Face Mask" ...
##  $ Brand            : chr  "Anastasia Beverly Hills" "Patrick Ta" "Anastasia Beverly Hills" "E.l.f." ...
##  $ Category         : chr  "Lip Liner" "Lipstick" "Mascara" "Highlighter" ...
##  $ Usage_Frequency  : chr  "Weekly" "Daily" "Occasional" "Daily" ...
##  $ Price_USD        : num  146.8 17.8 119.7 105.7 148.1 ...
##  $ Rating           : num  4.6 1.1 4.4 1.4 1.8 4.4 4.9 2.9 4.9 2.9 ...
##  $ Number_of_Reviews: int  1746 6039 9866 6763 3715 5282 1078 1326 9617 4870 ...
##  $ Product_Size     : chr  "100ml" "100ml" "30ml" "250ml" ...
##  $ Skin_Type        : chr  "Dry" "Sensitive" "Sensitive" "Oily" ...
##  $ Gender_Target    : chr  "Female" "Unisex" "Unisex" "Female" ...
##  $ Packaging_Type   : chr  "Spray" "Jar" "Jar" "Stick" ...
##  $ Main_Ingredient  : chr  "Hyaluronic Acid" "Aloe Vera" "Vitamin C" "Glycerin" ...
##  $ Cruelty_Free     : chr  "False" "False" "True" "True" ...
##  $ Country_of_Origin: chr  "Japan" "USA" "Germany" "France" ...
summary(df)
##    Source_Row       Product_Name        Brand           Category   
##  Min.   :    4   Length   :7500   Length   :7500   Length   :7500  
##  1st Qu.: 3664   N.unique : 120   N.unique :  40   N.unique :  24  
##  Median : 7388   N.blank  :   0   N.blank  :   0   N.blank  :   0  
##  Mean   : 7445   Min.nchar:  11   Min.nchar:   4   Min.nchar:   5  
##  3rd Qu.:11207   Max.nchar:  22   Max.nchar:  23   Max.nchar:  14  
##  Max.   :15001                                                     
##   Usage_Frequency   Price_USD          Rating      Number_of_Reviews
##  Length   :7500   Min.   : 10.00   Min.   :1.000   Min.   :  52     
##  N.unique :   4   1st Qu.: 45.95   1st Qu.:2.000   1st Qu.:2621     
##  N.blank  :   0   Median : 80.61   Median :3.000   Median :5028     
##  Min.nchar:   5   Mean   : 80.58   Mean   :2.991   Mean   :5031     
##  Max.nchar:  10   3rd Qu.:115.15   3rd Qu.:4.000   3rd Qu.:7498     
##                   Max.   :149.99   Max.   :5.000   Max.   :9999     
##     Product_Size      Skin_Type      Gender_Target    Packaging_Type
##  Length   :7500   Length   :7500   Length   :7500   Length   :7500  
##  N.unique :   6   N.unique :   5   N.unique :   3   N.unique :   6  
##  N.blank  :   0   N.blank  :   0   N.blank  :   0   N.blank  :   0  
##  Min.nchar:   4   Min.nchar:   3   Min.nchar:   4   Min.nchar:   3  
##  Max.nchar:   5   Max.nchar:  11   Max.nchar:   6   Max.nchar:   7  
##                                                                     
##   Main_Ingredient    Cruelty_Free  Country_of_Origin
##  Length   :7500   Length   :7500   Length   :7500   
##  N.unique :   7   N.unique :   2   N.unique :   8   
##  N.blank  :   0   N.blank  :   0   N.blank  :   0   
##  Min.nchar:   7   Min.nchar:   4   Min.nchar:   2   
##  Max.nchar:  15   Max.nchar:   5   Max.nchar:  11   
## 

2. Original and analysis sample sizes

original_n <- 15000L
analysis_data <- df
stopifnot(nrow(analysis_data) == 7500L)

cat("Original sample size:", original_n, "\n")
## Original sample size: 15000
cat("Analysis sample size:", nrow(analysis_data), "\n")
## Analysis sample size: 7500
cat("Number of variables:", ncol(analysis_data), "\n")
## Number of variables: 15

The original dataset has 15000 observations. The analysis uses 7500 observations from the same saved half-sample used in the presentation.

3. Data preparation

# Make sure the main categorical variables are treated as categories.
analysis_data$Category <- as.factor(analysis_data$Category)
status <- tolower(trimws(as.character(analysis_data$Cruelty_Free)))
analysis_data$Cruelty_Free <- factor(
  status,
  levels = c("false", "true"),
  labels = c("FALSE", "TRUE")
)

# Confirm missing values in the variables used in the analysis.
analysis_vars <- c("Category", "Price_USD", "Rating",
                   "Number_of_Reviews", "Cruelty_Free")

colSums(is.na(analysis_data[analysis_vars]))
##          Category         Price_USD            Rating Number_of_Reviews 
##                 0                 0                 0                 0 
##      Cruelty_Free 
##                 0
# Keep complete cases for the hypothesis tests and plots.
analysis_data <- analysis_data[complete.cases(analysis_data[analysis_vars]), ]

4. Descriptive statistics

analysis_data %>%
  summarise(
    sample_size = n(),
    mean_price = mean(Price_USD),
    median_price = median(Price_USD),
    mean_rating = mean(Rating),
    median_rating = median(Rating),
    mean_reviews = mean(Number_of_Reviews),
    median_reviews = median(Number_of_Reviews)
  )
##   sample_size mean_price median_price mean_rating median_rating mean_reviews
## 1        7500   80.58049       80.605     2.99064             3     5031.205
##   median_reviews
## 1         5027.5

EDA 1: Product category barplot

category_counts <- table(analysis_data$Category)

barplot(
  sort(category_counts, decreasing = TRUE),
  main = "Number of Products by Category",
  xlab = "Product Category",
  ylab = "Number of Products",
  col = "#C9788B",
  las = 2,
  cex.names = 0.75
)

EDA 1 interpretation

The barplot compares how many products from the half-sample belong to each category. The most common category represents the largest portion of the product dataset, while shorter bars show categories with fewer products. This helps identify whether the sample is concentrated in a particular part of the beauty market.

EDA 2: Price and rating scatterplot

ggplot(analysis_data, aes(x = Price_USD,
                          y = Rating,
                          color = Cruelty_Free)) +
  geom_point(alpha = 0.35, size = 1.4) +
  geom_smooth(method = "lm", se = FALSE, color = "#3A2638") +
  scale_color_manual(values = c("FALSE" = "#C9788B", "TRUE" = "#7B9A8B")) +
  labs(
    title = "Product Price and Rating",
    subtitle = "Random half-sample of beauty products",
    x = "Price (USD)",
    y = "Rating",
    color = "Cruelty-Free"
  ) +
  theme_minimal() +
  theme(plot.title = element_text(face = "bold"))
## `geom_smooth()` using formula = 'y ~ x'

EDA 2 interpretation

The scatterplot shows whether ratings appear to increase or decrease as price changes. The fitted line summarizes the overall linear pattern, while the colors allow a visual comparison between cruelty-free and non-cruelty-free products. A weak or widely scattered pattern would suggest that price alone does not explain product ratings.

5. Hypothesis tests

H1: Reviews and ratings

# H1: Products with more reviews will have higher average ratings.
h1_test <- cor.test(
  analysis_data$Number_of_Reviews,
  analysis_data$Rating,
  method = "pearson"
)

h1_test
## 
##  Pearson's product-moment correlation
## 
## data:  analysis_data$Number_of_Reviews and analysis_data$Rating
## t = 1.3004, df = 7498, p-value = 0.1935
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.007619433  0.037635120
## sample estimates:
##        cor 
## 0.01501553

H2: Cruelty-free status and ratings

# Compare the average rating of cruelty-free and non-cruelty-free products.
analysis_data %>%
  group_by(Cruelty_Free) %>%
  summarise(
    n = n(),
    mean_rating = mean(Rating),
    median_rating = median(Rating),
    sd_rating = sd(Rating)
  )
## # A tibble: 2 × 5
##   Cruelty_Free     n mean_rating median_rating sd_rating
##   <fct>        <int>       <dbl>         <dbl>     <dbl>
## 1 FALSE         3803        2.97           2.9      1.16
## 2 TRUE          3697        3.01           3        1.16
# H2: Cruelty-free products will have higher average ratings.
h2_test <- t.test(Rating ~ Cruelty_Free, data = analysis_data)
h2_test
## 
##  Welch Two Sample t-test
## 
## data:  Rating by Cruelty_Free
## t = -1.2084, df = 7492.2, p-value = 0.2269
## alternative hypothesis: true difference in means between group FALSE and group TRUE is not equal to 0
## 95 percent confidence interval:
##  -0.08505170  0.02018122
## sample estimates:
## mean in group FALSE  mean in group TRUE 
##            2.974652            3.007087

Average ratings by cruelty-free status

rating_summary <- analysis_data %>%
  group_by(Cruelty_Free) %>%
  summarise(average = mean(Rating), .groups = "drop") %>%
  mutate(status = factor(
    if_else(Cruelty_Free == "TRUE", "Marked cruelty-free", "Not marked cruelty-free"),
    levels = c("Marked cruelty-free", "Not marked cruelty-free")
  ))

ggplot(rating_summary, aes(x = status, y = average, fill = status)) +
  geom_col(width = 0.58, show.legend = FALSE) +
  geom_text(aes(label = sprintf("%.2f", average)), vjust = -0.45) +
 scale_fill_manual(values = c("#407870", "#407870")) +
  scale_y_continuous(limits = c(0, 5), breaks = 0:5) +
  labs(
    title = "Average ratings by cruelty-free status",
    x = NULL,
    y = "Average rating (out of 5)"
  ) +
  theme_minimal()

H3: Price, category, and ratings

# H3: Price will have a weak relationship with rating, and the relationship
# will be estimated while accounting for product category.
h3_model <- lm(
  Rating ~ Price_USD + Number_of_Reviews + Cruelty_Free + Category,
  data = analysis_data
)

summary(h3_model)
## 
## Call:
## lm(formula = Rating ~ Price_USD + Number_of_Reviews + Cruelty_Free + 
##     Category, data = analysis_data)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.17965 -1.00398 -0.01506  1.03381  2.10113 
## 
## Coefficients:
##                          Estimate Std. Error t value Pr(>|t|)    
## (Intercept)             2.998e+00  7.510e-02  39.921   <2e-16 ***
## Price_USD              -2.421e-04  3.328e-04  -0.727   0.4670    
## Number_of_Reviews       6.044e-06  4.742e-06   1.275   0.2025    
## Cruelty_FreeTRUE        3.185e-02  2.686e-02   1.186   0.2358    
## CategoryBlush          -4.582e-02  9.181e-02  -0.499   0.6178    
## CategoryBronzer        -6.460e-02  9.314e-02  -0.694   0.4879    
## CategoryCC Cream        7.276e-02  9.420e-02   0.772   0.4399    
## CategoryCleanser       -8.500e-02  9.404e-02  -0.904   0.3661    
## CategoryConcealer      -5.106e-02  9.230e-02  -0.553   0.5802    
## CategoryContour         1.492e-01  9.396e-02   1.587   0.1124    
## CategoryExfoliator      1.317e-03  9.309e-02   0.014   0.9887    
## CategoryEye Shadow     -1.251e-01  9.524e-02  -1.313   0.1892    
## CategoryEyeliner       -1.359e-01  9.117e-02  -1.490   0.1362    
## CategoryFace Mask      -1.832e-02  9.232e-02  -0.198   0.8427    
## CategoryFace Oil       -1.530e-02  9.090e-02  -0.168   0.8663    
## CategoryFoundation     -9.113e-02  9.253e-02  -0.985   0.3247    
## CategoryHighlighter     3.990e-02  9.072e-02   0.440   0.6601    
## CategoryLip Gloss      -7.327e-02  9.526e-02  -0.769   0.4418    
## CategoryLip Liner      -1.662e-01  9.307e-02  -1.785   0.0743 .  
## CategoryLipstick       -4.603e-02  9.299e-02  -0.495   0.6206    
## CategoryMakeup Remover  2.475e-02  9.403e-02   0.263   0.7924    
## CategoryMascara        -7.270e-02  9.038e-02  -0.804   0.4212    
## CategoryMoisturizer     1.002e-02  9.047e-02   0.111   0.9118    
## CategoryPowder         -5.917e-02  9.464e-02  -0.625   0.5319    
## CategoryPrimer         -8.814e-03  9.254e-02  -0.095   0.9241    
## CategorySerum          -9.060e-02  8.946e-02  -1.013   0.3112    
## CategorySetting Spray   3.625e-02  9.172e-02   0.395   0.6927    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.162 on 7473 degrees of freedom
## Multiple R-squared:  0.003946,   Adjusted R-squared:  0.000481 
## F-statistic: 1.139 on 26 and 7473 DF,  p-value: 0.2846

6. Optional model visualization

analysis_data$predicted_rating <- predict(h3_model)

ggplot(analysis_data, aes(x = predicted_rating, y = Rating)) +
  geom_point(alpha = 0.35, color = "#7B3F75") +
  geom_abline(slope = 1, intercept = 0,
              color = "#D6A85F", linewidth = 1) +
  labs(
    title = "Observed Ratings Compared with Model Predictions",
    x = "Predicted Rating",
    y = "Observed Rating"
  ) +
  theme_minimal()

library(ggplot2)

brand_engagement <- data.frame(
  brand = c("The Ordinary", "Rhode", "Cetaphil",
            "La Roche-Posay", "CeraVe", "Neutrogena"),
  posts = c(100, 98, 100, 100, 100, 99),
  likes_plus_reposts = c(378, 299, 242, 224, 215, 49)
)

brand_engagement$average <- with(
  brand_engagement, likes_plus_reposts / posts
)

ggplot(brand_engagement, aes(x = average, y = reorder(brand, average))) +
  geom_col(fill = "#407870", width = 0.65) +
  geom_text(aes(label = sprintf("%.2f", average)), hjust = -0.15) +
  scale_x_continuous(limits = c(0, 4.4), breaks = 0:4) +
  labs(
    title = "Average likes and reposts by brand",
    x = "Average likes plus reposts per post",
    y = NULL
  ) +
  theme_minimal(base_size = 12) +
  theme(panel.grid.major.y = element_blank())

7. Conclusion

The saved sample contained 7,500 beauty products. Products marked cruelty-free averaged 3.01 out of 5, and products not marked cruelty-free averaged 2.97 out of 5. The average ratings were close in this sample. The comparison describes the product records in the dataset.