Skip to main content
Statistics LibreTexts

6.2: Battery Life Example

  • Page ID
    33659
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Consider a study of Battery Life, measured in hours, where 4 brands of batteries are evaluated using 4 replications in a completely randomized design (Battery Data):

    Brand A Brand B Brand C Brand D
    110 118 108 117
    113 116 107 112
    108 112 112 115
    115 117 108 119

    A reasonable question to ask in this study would be, should the brand of the battery be considered a fixed effect or a random effect?

    If the researchers were interested in comparing the performance of the specific brands they chose for the study, then we have a fixed effect.

    But if the researchers were actually interested in studying the overall variation in battery life, so that the results would be applicable to all brands of batteries, then they may have chosen (presumably with a random sampling process) a sample of 4 of the many brands available and tested 4 batteries of each of these brands. In this latter case, the battery brand would add a dimension of variability to battery life and can be considered a random effect.

    Now, let us use SAS proc mixed; to compare the results of battery brand as a fixed vs. random effect:

    1. Fixed Effect model:
      Type 3 Analysis of Variance
      Source DF Sum of Squares Mean Square Expected Mean Square Error Term Error DF F Value Pr > F
      Brand 3 141.687500 47.229167 Var(Residual) + Q(Brand) MS(Residual) 12 6.21 0.0086
      Residual 12 91.250000 7.604167 Var(Residual) . . . .
    2. Random Effect model:
      Type 3 Analysis of Variance
      Source DF Sum of Squares Mean Square Expected Mean Square Error Term Error DF F Value Pr > F
      Brand 3 141.687500 47.229167 Var(Residual) + 4 Var(Brand) MS(Residual) 12 6.21 0.0086
      Residual 12 91.250000 7.604167 Var(Residual) . . . .
      Covariance Parameter Estimates
      Cov Parm Estimate
      Brand 9.9063
      Residual 7.6042

    We can verify the estimated variance component (arrow above) for the random treatment effect as: \[s_{\text{among trts}}^{2} = \frac{MS_{trt} - MS_{error}}{n} = \frac{47.229 - 7.604}{4} = 9.9063\]

    With this, we can calculate the ICC as \[ICC = \frac{9.9063}{9.9063 + 7.604} = 0.5657\]

    The key points in comparing these two ANOVAs are 1) the scope of inference and 2) the hypothesis being tested. For a fixed effect, the scope of inference is restricted to only 4 brands chosen for comparison and the Null hypothesis is a statement of equality of means. In contrast, as a random effect, the scope of inference is the larger population of battery brands and the Null hypothesis is a statement that the variance due to battery brand is 0.

    Using R

    R: Single Random Effect
    • Load the battery life data.
    • Obtain the ANOVA for a single random effect.
    Show Detailed Steps

    1. Load the battery life data by using the following commands:

    setwd("~/path-to-folder/")
    battery_data <- read.table("battery_data.txt",header=T)
    attach(battery_data)
    

    2. Obtain the ANOVA for a single random effect by using the following commands:

    library(lmerTest)
    library(lme4)
    battery_anova<-lmer(lifetime ~ (1 | trt),battery_data)
    summary(battery_anova)
    Linear mixed model fit by REML. t-tests use Satterthwaites method ['lmerModLmerTest']
    Formula: lifetime ~ (1 | trt)
       Data: battery_data
    REML criterion at convergence: 81.3
    #Scaled residuals:
    #     Min       1Q   Median       3Q      Max
    #-1.35317 -0.69070  0.07355  0.69665  1.34279
    #Random effects:
    # Groups   Name        Variance Std.Dev.
    # trt      (Intercept) 9.906    3.147   
    # Residual             7.604    2.758   
    #Number of obs: 16, groups:  trt, 4
    #Fixed effects:
    #            Estimate Std. Error      df t value Pr(>|t|)    
    #(Intercept)  112.938      1.718   3.000   65.73 7.76e-06 ***
    #---
    #Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
    #confint(battery_anova)
    #                  2.5 %     97.5 %
    #.sig01        0.6530752   7.166913
    #.sigma        1.9371621   4.374014
    #(Intercept) 109.1585596 116.716437
    

    Note that the command lmer() gives the ANOVA table only for the fixed effects. Therefore, in this example, since there are no fixed effects, we won’t get the ANOVA table. In the "Random effects" section of the output, under the column variance we get the estimates for \(\sigma_{\alpha}^{2}\) and \(\sigma^{2}\), which are equal to 9.906 and 7.604 respectively. In the "Fixed effects" section under the column estimate, we get the estimate of \(mu\), or the overall mean, which is equal to 112.938. With the command confint() we will get confidence intervals for the standard deviations and the overall mean. If you take the square of the lower and upper bounds, you will get a confidence interval for the model variances.

    Alternatively, we can use the command aov() which gives a partial ANOVA table.

    battery_anova1<-aov(lifetime~Error(trt),battery_data)
    summary(battery_anova1)
    #Error: trt
    #          Df Sum Sq Mean Sq F value Pr(>F)
    #Residuals  3  141.7   47.23               
    #Error: Within
    #          Df Sum Sq Mean Sq F value Pr(>F)
    #Residuals 12  91.25   7.604   
    detach(battery_data)
    

    Note that both of these commands in R don't give the \(F\)-values and \(p\)-values for the tests. Therefore, these must be done manually.


    This page titled 6.2: Battery Life Example is shared under a CC BY-NC 4.0 license and was authored, remixed, and/or curated by Penn State's Department of Statistics.

    • Was this article helpful?