0.1 Load the libraries

1 Identify each of the following elements of this experiment, if applicable:

# Refer to the in-depth explanation in the word/pdf report

# Experiment - The experiment involves a two-level factorial design with three factors, \n i.e popcorn brand, microwave power level, and cooking time on the percentage of edible popcorn kernels made in a microwave oven. Two popcorn \n types from Black Jewel company are used in lieu of different brands. The power levels selected were 5 and 10. Cooking time levels were \n 5 mins and 7.5 mins. The experiment ultimately involves maximization of the proportion of popped popcorns versus un-popped or burnt popcorns. \n This optimized maximum is determined through the combination of the three factors. 

# Experimental unit - Experimental unit in this example is each set of 50 kernels that are experimented upon.

# Independent variable/factor - Cooking time, Microwave Power, and Brand of Popcorn.

# Background variable/lurking variable - i) Positioning in the microwave \n ii) Reuse of glasses that were used to heat the popcorn \n iii) Variance in oil and butter on the popcorn kernels \n iv) Human error. Experiments were carried out in a randomized fashion to 

# Dependent variable/response - Proportion of popped popcorns (% of 50 kernels that popped)

# Effect(s) - To understand the interaction of the independent variables (time, power, and popcorn brand) \n upon the the dependent variable (popping proportion of popcorns)

# Replicates - A total of 3 replicates, or 24 runs were performed in a randomized order. \n Wheeler estimate equates of 2 replicates, however a 3rd set of runs was carried out. 

2 Determine how many replicates will be required to detect a maximum difference in marginal (main effect) means of 0.25.

2.1 Levels - To keep experiments simple, we will choose 2 levels per factor

2.2 Replicates - for a three factored experiment with two levels i.e 2^3 = 8, we determined a minumum of 2 replicates

3 Determine the number of levels of the factors you would like to study, and create a randomized list of the experiments for a factorial design.

3.1 Experiment Grid

3.2 Randomization / Csv output to be filled in with experiment response

4 Perform the experiments and collect the data.

4.1 Post-Experiment - Data Read-In

5 Analyze the data, interpret the results, and determine the optimum combination of factor levels from among those you tested.

5.1 Optimum combination, Modeling and Analysis/Interpretation

## 
## Call:
## lm.default(formula = pct_pop ~ time * power * brand, data = popcorn)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.18667 -0.02167  0.00000  0.03000  0.13333 
## 
## Coefficients:
##                                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                   5.333e-02  4.485e-02   1.189  0.25168    
## time7.5                       4.000e-02  6.342e-02   0.631  0.53714    
## power10                       3.733e-01  6.342e-02   5.887  2.3e-05 ***
## brandregular                  2.667e-02  6.342e-02   0.420  0.67973    
## time7.5:power10               3.267e-01  8.969e-02   3.642  0.00219 ** 
## time7.5:brandregular          9.624e-17  8.969e-02   0.000  1.00000    
## power10:brandregular          1.867e-01  8.969e-02   2.081  0.05383 .  
## time7.5:power10:brandregular -1.800e-01  1.268e-01  -1.419  0.17506    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.07767 on 16 degrees of freedom
## Multiple R-squared:  0.9607, Adjusted R-squared:  0.9435 
## F-statistic: 55.88 on 7 and 16 DF,  p-value: 4.623e-10
##                  (Intercept)                      time7.5 
##                 5.333333e-02                 4.000000e-02 
##                      power10                 brandregular 
##                 3.733333e-01                 2.666667e-02 
##              time7.5:power10         time7.5:brandregular 
##                 3.266667e-01                 9.623937e-17 
##         power10:brandregular time7.5:power10:brandregular 
##                 1.866667e-01                -1.800000e-01

6 Visualization of Optimum combinations of factors

7 ANOVA Summary

## Call:
##    aov.default(formula = pct_pop ~ time * power * brand, data = popcorn)
## 
## Terms:
##                      time     power     brand time:power time:brand
## Sum of Squares  0.1504167 2.0533500 0.0337500  0.0840167  0.0121500
## Deg. of Freedom         1         1         1          1          1
##                 power:brand time:power:brand Residuals
## Sum of Squares    0.0140167        0.0121500 0.0965333
## Deg. of Freedom           1                1        16
## 
## Residual standard error: 0.07767453
## Estimated effects may be unbalanced
##                  Df Sum Sq Mean Sq F value   Pr(>F)    
## time              1 0.1504  0.1504  24.931 0.000133 ***
## power             1 2.0533  2.0533 340.334 3.31e-12 ***
## brand             1 0.0337  0.0337   5.594 0.030992 *  
## time:power        1 0.0840  0.0840  13.925 0.001817 ** 
## time:brand        1 0.0121  0.0121   2.014 0.175061    
## power:brand       1 0.0140  0.0140   2.323 0.146978    
## time:power:brand  1 0.0121  0.0121   2.014 0.175061    
## Residuals        16 0.0965  0.0060                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

8 Marginal Means (pct_pop) - Compare with shift in marginal means (0.25)

##  time lsmean     SE df lower.CL upper.CL
##  5     0.300 0.0224 16    0.252    0.348
##  7.5   0.458 0.0224 16    0.411    0.506
## 
## Results are averaged over the levels of: power, brand 
## Confidence level used: 0.95
##  power lsmean     SE df lower.CL upper.CL
##  5     0.0867 0.0224 16   0.0391    0.134
##  10    0.6717 0.0224 16   0.6241    0.719
## 
## Results are averaged over the levels of: time, brand 
## Confidence level used: 0.95
##  brand   lsmean     SE df lower.CL upper.CL
##  buttery  0.342 0.0224 16    0.294    0.389
##  regular  0.417 0.0224 16    0.369    0.464
## 
## Results are averaged over the levels of: time, power 
## Confidence level used: 0.95

8.1 Visualization - Basics Exploratory Data Analysis

9 How many experiments would it have taken to get the same power for detecting main effects using a vary one-factor-at-a-time plan? Would you detect the same optimum using the vary one factor-at-a-time plan?

## [1] 48