Load packages

library(ggplot2)
library(dplyr)
library(tidyr)
library(visreg)
library(car)

Data management

# Reshape the data for visualization
data_long <- pack_data %>%
  pivot_longer(cols = starts_with("Weight"), names_to = "Day", values_to = "Weight") %>%
  mutate(Day = case_when(
    Day == "Weight.Day.0.g" ~ "0",
    Day == "Weight.Day.3.g" ~ "3",
    Day == "Weight.Day.6.g" ~ "6",
    TRUE ~ Day
  ))
# Print the reshaped data to verify
head(data_long)

Visualization ———————————————-

pH Levels by Packaging and Number of Perforations

p1 <- ggplot(pack_data, aes(x = factor(Number.of.perforations), y = pH, 
                            fill = Package)) +
  geom_bar(stat = "identity", position = "dodge", width = 0.5) +
  labs(title = "pH Levels by Packaging and Number of Perforations", 
       x = "Number of Perforations", y = "pH") +
  mytheme
print(p1)

Total Soluble Solids by Packaging and Number of Perforations

p2 <- ggplot(pack_data, aes(x = factor(Number.of.perforations), y = TSS, 
                            fill = Package)) +
  geom_bar(stat = "identity", position = "dodge", width = 0.5) +
  labs(title = "Total Soluble Solids by Packaging and Number of Perforations", 
       x = "Number of Perforations", y = "TSS") +
  mytheme
print(p2)

Total Titratable Acidity by Packaging and Number of Perforations

p3 <- ggplot(pack_data, aes(x = factor(Number.of.perforations), y = TTA, 
                            fill = Package)) +
  geom_bar(stat = "identity", position = "dodge", width = 0.5) +
  labs(title = "Total Titratable Acidity by Packaging and Number of Perforations", 
       x = "Number of Perforations", y = "TTA")  +
  mytheme
print(p3)

Vitamin C by Packaging and Number of Perforations

p4 <- ggplot(pack_data, aes(x = factor(Number.of.perforations), y = Vitamin.C, 
                            fill = Package)) +
  geom_bar(stat = "identity", position = "dodge", width = 0.5) +
  labs(title = "Vitamin C by Packaging and Number of Perforations", 
       x = "Number of Perforations", y = "Vitamin C") +
  mytheme
print(p4)

Weight Loss Over Time

# Faceted plot for weight loss over time based on number of perforations
p5 <- ggplot(data_long, aes(x = Day, y = Weight, 
                            group = interaction(Package, Number.of.perforations), 
                            color = Package)) +
  geom_line(aes(linetype = factor(Number.of.perforations)), linewidth = 0.9) +
  labs(title = "Weight Loss Over Time", x = "Day", y = "Weight (g)") +
  facet_wrap(~ Number.of.perforations) +
  mytheme
print(p5)

Statistics ———————————————–

Testing multiple correlation analysis

## Testing multiple correlation analysis
library(corrplot)
## corrplot 0.92 loaded
# Creating a vector for the methods
methods <- c("pearson", "spearman", "kendall")
for(method in methods){
  cor_matrix <- cor(pack_data[, c("TSS", "Number.of.perforations", 
                                  "pH", "Vitamin.C", "Days.of.Storage", 
                                  "Weight.Day.0.g", "Weight.Day.3.g", 
                                  "Weight.Day.6.g")], 
                    method = method, use = "everything")
  corrplot(cor_matrix, 
           type = "upper", 
           method = "color", 
           addCoef.col = "black", 
           tl.col = "black", 
           tl.srt = 45, 
           tl.cex = 0.7, 
           mar = c(0, 0, 1, 0), 
           number.cex = 0.8,
           number.font = 2,
           cl.pos = "n", 
           title = paste(method, "correlation"))
}

Effect of Package and Nuumber of Perforations on the Weight ——————————————————————-

options(contrasts = c("contr.sum","contr.poly")) 

# Fit the linear  modelfor Day 0
anova_day0 <- lm(Weight.Day.0.g ~ Package*Number.of.perforations, data = pack_data)
anova_day3 <- lm(Weight.Day.3.g ~ Package*Number.of.perforations, data = pack_data)
anova_day6 <- lm(Weight.Day.6.g ~ Package*Number.of.perforations, data = pack_data)

summary(anova_day0)
## 
## Call:
## lm(formula = Weight.Day.0.g ~ Package * Number.of.perforations, 
##     data = pack_data)
## 
## Residuals:
##        1        2        3        4        5        6        7        8 
##  -0.6667   1.3333  -0.6667   5.0000 -10.0000   5.0000  -1.0000   2.0000 
##        9 
##  -1.0000 
## 
## Coefficients:
##                                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                     120.2222     3.8329  31.366 7.12e-05 ***
## Package1                         -5.2222     5.4206  -0.963    0.406    
## Package2                         -9.5556     5.4206  -1.763    0.176    
## Number.of.perforations            0.3333     1.4845   0.225    0.837    
## Package1:Number.of.perforations   1.1667     2.0994   0.556    0.617    
## Package2:Number.of.perforations  -0.3333     2.0994  -0.159    0.884    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 7.272 on 3 degrees of freedom
## Multiple R-squared:  0.8464, Adjusted R-squared:  0.5904 
## F-statistic: 3.306 on 5 and 3 DF,  p-value: 0.177
summary(anova_day3)
## 
## Call:
## lm(formula = Weight.Day.3.g ~ Package * Number.of.perforations, 
##     data = pack_data)
## 
## Residuals:
##       1       2       3       4       5       6       7       8       9 
##  -1.333   2.667  -1.333   5.667 -11.333   5.667  -1.333   2.667  -1.333 
## 
## Coefficients:
##                                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                      118.333      4.451  26.583 0.000117 ***
## Package1                          -7.000      6.295  -1.112 0.347248    
## Package2                          -9.000      6.295  -1.430 0.248164    
## Number.of.perforations             0.500      1.724   0.290 0.790691    
## Package1:Number.of.perforations    1.500      2.438   0.615 0.581926    
## Package2:Number.of.perforations   -0.500      2.438  -0.205 0.850639    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 8.446 on 3 degrees of freedom
## Multiple R-squared:  0.8193, Adjusted R-squared:  0.518 
## F-statistic:  2.72 on 5 and 3 DF,  p-value: 0.2199
summary(anova_day6)
## 
## Call:
## lm(formula = Weight.Day.6.g ~ Package * Number.of.perforations, 
##     data = pack_data)
## 
## Residuals:
##       1       2       3       4       5       6       7       8       9 
##  -1.000   2.000  -1.000   5.333 -10.667   5.333  -1.333   2.667  -1.333 
## 
## Coefficients:
##                                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                     116.3333     4.1648  27.932 0.000101 ***
## Package1                         -7.0000     5.8899  -1.188 0.320157    
## Package2                         -9.3333     5.8899  -1.585 0.211225    
## Number.of.perforations            0.1667     1.6130   0.103 0.924225    
## Package1:Number.of.perforations   1.8333     2.2812   0.804 0.480363    
## Package2:Number.of.perforations  -0.6667     2.2812  -0.292 0.789142    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 7.902 on 3 degrees of freedom
## Multiple R-squared:  0.8428, Adjusted R-squared:  0.5809 
## F-statistic: 3.218 on 5 and 3 DF,  p-value: 0.1825
Anova(anova_day0, type=3)
Anova(anova_day3, type=3)
Anova(anova_day6, type=3)

Effect of the package and Number of Perforations on the quality of the pepper

## Fit linear models for each response variable
anova_pH <- lm(pH ~ Package * Number.of.perforations, data = pack_data)
anova_vitaminC <- lm(Vitamin.C ~ Package * Number.of.perforations, data = pack_data)
anova_TSS <- lm(TSS ~ Package * Number.of.perforations, data = pack_data)
anova_TTA <- lm(TTA ~ Package * Number.of.perforations, data = pack_data)

## Summarize the models
summary(anova_pH)
## 
## Call:
## lm(formula = pH ~ Package * Number.of.perforations, data = pack_data)
## 
## Residuals:
##        1        2        3        4        5        6        7        8 
## -0.07000  0.14000 -0.07000 -0.10500  0.21000 -0.10500 -0.06667  0.13333 
##        9 
## -0.06667 
## 
## Coefficients:
##                                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                      6.2838889  0.1063784  59.071 1.07e-05 ***
## Package1                         0.1227778  0.1504417   0.816    0.474    
## Package2                        -0.1538889  0.1504417  -1.023    0.382    
## Number.of.perforations          -0.0641667  0.0412002  -1.557    0.217    
## Package1:Number.of.perforations -0.0008333  0.0582658  -0.014    0.989    
## Package2:Number.of.perforations  0.0341667  0.0582658   0.586    0.599    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2018 on 3 degrees of freedom
## Multiple R-squared:  0.6045, Adjusted R-squared:  -0.05465 
## F-statistic: 0.9171 on 5 and 3 DF,  p-value: 0.5664
summary(anova_vitaminC)
## 
## Call:
## lm(formula = Vitamin.C ~ Package * Number.of.perforations, data = pack_data)
## 
## Residuals:
##       1       2       3       4       5       6       7       8       9 
##  4.0067 -8.0135  4.0067 -0.6311  1.2622 -0.6311 -7.7346 15.4692 -7.7346 
## 
## Coefficients:
##                                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                      103.515      6.510  15.902 0.000541 ***
## Package1                         -27.093      9.206  -2.943 0.060366 .  
## Package2                          -6.252      9.206  -0.679 0.545749    
## Number.of.perforations            40.280      2.521  15.977 0.000533 ***
## Package1:Number.of.perforations    7.999      3.565   2.243 0.110613    
## Package2:Number.of.perforations   -5.210      3.565  -1.461 0.240084    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 12.35 on 3 degrees of freedom
## Multiple R-squared:  0.9895, Adjusted R-squared:  0.9721 
## F-statistic:  56.7 on 5 and 3 DF,  p-value: 0.003604
summary(anova_TSS)
## 
## Call:
## lm(formula = TSS ~ Package * Number.of.perforations, data = pack_data)
## 
## Residuals:
##        1        2        3        4        5        6        7        8 
##  0.01167 -0.02333  0.01167  0.19500 -0.39000  0.19500  0.01167 -0.02333 
##        9 
##  0.01167 
## 
## Coefficients:
##                                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                      3.33722    0.14586  22.879 0.000183 ***
## Package1                        -0.34889    0.20628  -1.691 0.189355    
## Package2                        -0.34889    0.20628  -1.691 0.189355    
## Number.of.perforations          -0.28083    0.05649  -4.971 0.015639 *  
## Package1:Number.of.perforations  0.26333    0.07989   3.296 0.045868 *  
## Package2:Number.of.perforations -0.23667    0.07989  -2.962 0.059434 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2768 on 3 degrees of freedom
## Multiple R-squared:  0.9646, Adjusted R-squared:  0.9057 
## F-statistic: 16.37 on 5 and 3 DF,  p-value: 0.02185
summary(anova_TTA)
## 
## Call:
## lm(formula = TTA ~ Package * Number.of.perforations, data = pack_data)
## 
## Residuals:
##          1          2          3          4          5          6          7 
##  1.787e-05 -3.573e-05  1.787e-05 -1.228e-06  2.457e-06 -1.228e-06 -9.268e-06 
##          8          9 
##  1.854e-05 -9.268e-06 
## 
## Coefficients:
##                                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                      2.423e-04  1.503e-05  16.122 0.000519 ***
## Package1                        -9.034e-05  2.126e-05  -4.250 0.023870 *  
## Package2                        -1.697e-05  2.126e-05  -0.799 0.482935    
## Number.of.perforations           1.362e-04  5.821e-06  23.403 0.000171 ***
## Package1:Number.of.perforations  2.406e-05  8.232e-06   2.923 0.061341 .  
## Package2:Number.of.perforations -2.233e-05  8.232e-06  -2.713 0.072987 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.852e-05 on 3 degrees of freedom
## Multiple R-squared:  0.9952, Adjusted R-squared:  0.9871 
## F-statistic: 123.7 on 5 and 3 DF,  p-value: 0.001133
# Perform Type III ANOVA
anova_results_pH <- Anova(anova_pH, type = 3)
anova_results_vitaminC <- Anova(anova_vitaminC, type = 3)
anova_results_TSS <- Anova(anova_TSS, type = 3)

# Print the ANOVA results
print(anova_results_pH)
## Anova Table (Type III tests)
## 
## Response: pH
##                                 Sum Sq Df   F value    Pr(>F)    
## (Intercept)                    142.154  1 3489.3965 1.069e-05 ***
## Package                          0.048  2    0.5851    0.6102    
## Number.of.perforations           0.099  1    2.4256    0.2172    
## Package:Number.of.perforations   0.018  2    0.2238    0.8117    
## Residuals                        0.122  3                        
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
print(anova_results_vitaminC)
## Anova Table (Type III tests)
## 
## Response: Vitamin.C
##                                Sum Sq Df  F value    Pr(>F)    
## (Intercept)                     38575  1 252.8633 0.0005407 ***
## Package                          2262  2   7.4140 0.0690283 .  
## Number.of.perforations          38940  1 255.2544 0.0005332 ***
## Package:Number.of.perforations    791  2   2.5933 0.2218345    
## Residuals                         458  3                       
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
print(anova_results_TSS)
## Anova Table (Type III tests)
## 
## Response: TSS
##                                Sum Sq Df  F value    Pr(>F)    
## (Intercept)                    40.093  1 523.4503 0.0001829 ***
## Package                         0.876  2   5.7211 0.0946743 .  
## Number.of.perforations          1.893  1  24.7122 0.0156385 *  
## Package:Number.of.perforations  1.009  2   6.5836 0.0799338 .  
## Residuals                       0.230  3                       
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Discussion

Effect of Package and Number of Perforations on Weight

The intercept is significant in all models, indicating that the average weight at each time point is statistically significant. The package type and the number of perforations, as well as their interaction, are not statistically significant (p-values > 0.05). This suggests that neither the type of package nor the number of perforations has a significant effect on the weight loss of the bell peppers over time.

Effect of Package and Number of Perforations on pH

The analysis of variance (ANOVA) for pH indicates that the intercept is highly significant (p-value = 1.07e-05), meaning the overall pH levels are significantly different from zero. However, the effects of the package type (p-value = 0.6102), number of perforations (p-value = 0.2172), and their interaction (p-value = 0.8117) are not statistically significant. This suggests that neither the type of package nor the number of perforations, nor their interaction, have a significant effect on the pH levels of the bell peppers during storage.

Effect of Package and Number of Perforations on Vitamin C

The ANOVA results for Vitamin C show a highly significant intercept (p-value = 0.0005407), indicating significant levels of Vitamin C in the samples. The number of perforations has a highly significant effect on Vitamin C content (p-value = 0.0005332), indicating that changes in the number of perforations significantly affect Vitamin C levels. The package type shows a marginal significance (p-value = 0.0690283), suggesting it might have some effect, but this is not definitive. The interaction between package type and number of perforations is not significant (p-value = 0.2218345).

Effect of Package and Number of Perforations on TSS

The ANOVA for TSS indicates a highly significant intercept (p-value = 0.0001829), confirming that the TSS levels are significantly different from zero. The number of perforations has a significant effect on TSS (p-value = 0.0156385), indicating that the number of perforations influences the TSS levels. The package type is marginally significant (p-value = 0.0946743), suggesting it may have some impact, but this is not conclusive. The interaction between package type and number of perforations shows marginal significance (p-value = 0.0799338), implying a possible combined effect, though further investigation is needed.

Effect of Package and Number of Perforations on TTA

For TTA, the ANOVA reveals a highly significant intercept (p-value = 0.000519), indicating significant levels of TTA in the samples. The number of perforations significantly affects TTA (p-value = 0.000171), showing that changes in the number of perforations significantly influence TTA levels. The package type is significant for one package (p-value = 0.023870 for Package1), indicating that this package type affects TTA levels. The interaction between package type and number of perforations is marginally significant (p-value = 0.061341 for Package1 and p-value = 0.072987 for Package2), suggesting a potential combined effect that warrants further study.

Summary

pH: No significant effects from package type, number of perforations, or their interaction. Vitamin C: Significant effect from the number of perforations; marginal significance from package type. TSS: Significant effect from the number of perforations; marginal significance from package type and their interaction. TTA: Significant effects from the number of perforations and one package type; marginal significance from their interaction. These results indicate that the number of perforations is a crucial factor affecting the quality parameters of bell peppers during storage, particularly for Vitamin C, TSS, and TTA. Package type shows some influence, especially in combination with the number of perforations, suggesting that both factors should be carefully considered in packaging design to optimize the quality and shelf-life of bell peppers.