1 Creating a data frame:

# Assuming 'dat' is your data frame
Week = c(22,24,25,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44)
Plan = c(1.57,1.49,1.50,1.50, 1.50, 1.50, 1.51, 1.41, 1.33, 1.48, 1.50, 1.37, 1.49, 1.43, 1.46, 1.40, 1.37, 1.40, 1.39, 1.42)
Bottles = c(20,18,16,16, 17, 18, 15, 15, 11, 17, 17, 16, 18, 17, 17, 15, 15, 15, 16, 15)

dat <- data.frame(Week,Plan,Bottles)
print(dat)
##    Week Plan Bottles
## 1    22 1.57      20
## 2    24 1.49      18
## 3    25 1.50      16
## 4    28 1.50      16
## 5    29 1.50      17
## 6    30 1.50      18
## 7    31 1.51      15
## 8    32 1.41      15
## 9    33 1.33      11
## 10   34 1.48      17
## 11   35 1.50      17
## 12   36 1.37      16
## 13   37 1.49      18
## 14   38 1.43      17
## 15   39 1.46      17
## 16   40 1.40      15
## 17   41 1.37      15
## 18   42 1.40      15
## 19   43 1.39      16
## 20   44 1.42      15

2 Using Regression Model:

model <- lm(Bottles ~ Plan, data = dat)

3 Evaluate the Model:

predictions <- predict(model, newdata = dat)
r_squared <- 1 - (sum((predictions - dat$Bottles)^2) / sum((mean(dat$Bottles) - dat$Bottles)^2))
print(paste("R-squared (R2) Score:", r_squared))
## [1] "R-squared (R2) Score: 0.584204470572811"

4 Making Predictions:

new_production_figures <- data.frame(Plan = c(1.65, 1.75, 1.85,1.95))  # Replace with your desired production figures
new_predictions <- predict(model, newdata = new_production_figures)

5 Results:

predictions_table <- data.frame(new_production_figures = new_production_figures$Plan, Predicted_Bottles = new_predictions)

print(predictions_table)
##   new_production_figures Predicted_Bottles
## 1                   1.65          20.66380
## 2                   1.75          22.90692
## 3                   1.85          25.15004
## 4                   1.95          27.39316