Skip to main content

Ex. 9 – Two factors and group means

Hypotheses about cell means in a two-way design, with an intercept and interactions, using group_means() and :=.

The research question

In the previous examples, we removed the intercept so that every coefficient was a group mean. With two or more factors, or when you want to keep the usual parameterization with an intercept, the coefficients are differences between groups. Writing hypotheses about group means is then less straightforward. restriktor has two tools for this: group_means() and the := operator.

We use the ToothGrowth dataset that comes with R: the length of odontoblasts (cells responsible for tooth growth) in 60 guinea pigs that received vitamin C at one of three doses (0.5, 1 or 2 mg/day), either as orange juice (OJ) or as ascorbic acid (VC).

We expect that the tooth length increases with the dose, for both supplements:

\[ H_1:\; \mu_{OJ,0.5} \leq \mu_{OJ,1} \leq \mu_{OJ,2} \quad\text{and}\quad \mu_{VC,0.5} \leq \mu_{VC,1} \leq \mu_{VC,2}. \]

Step 1 – fit the two-way model

library(restriktor)

ToothGrowth$dose <- factor(ToothGrowth$dose)
fit.TG <- lm(len ~ supp * dose, data = ToothGrowth)
coef(fit.TG)
 (Intercept)       suppVC        dose1        dose2 suppVC:dose1 suppVC:dose2 
       13.23        -5.25         9.47        12.83        -0.68         5.33 

The intercept is the mean of the OJ group with dose 0.5. All other coefficients are differences relative to that group or interaction terms.

Step 2 – express the group means in the parameters

group_means() shows how each cell mean is built up from the coefficients, and gives syntax that you can copy:

group_means(fit.TG)

restriktor (0.7): group means in terms of the model parameters

Grouping variable(s): supp, dose 

 name  supp dose n  definition                                 
 mu_11 OJ   0.5  10 .Intercept.                                
 mu_12 OJ   1    10 .Intercept. + dose1                        
 mu_13 OJ   2    10 .Intercept. + dose2                        
 mu_21 VC   0.5  10 .Intercept. + suppVC                       
 mu_22 VC   1    10 .Intercept. + suppVC + dose1 + suppVC.dose1
 mu_23 VC   2    10 .Intercept. + suppVC + dose2 + suppVC.dose2

The group-mean names (e.g., 'mu_11') can be used directly in the goric
hypotheses;
the definitions are added automatically. Syntax to copy (if desired):

mu_11 := .Intercept.
mu_12 := .Intercept. + dose1
mu_13 := .Intercept. + dose2
mu_21 := .Intercept. + suppVC
mu_22 := .Intercept. + suppVC + dose1 + suppVC.dose1
mu_23 := .Intercept. + suppVC + dose2 + suppVC.dose2 

The names are mu_ followed by the level number of each factor: mu_12 is the mean of supplement 1 (OJ) with dose 2 (1 mg/day).

Step 3 – test the hypothesis with iht()

We paste the definitions into the constraint syntax with := and add the restrictions on the newly defined parameters:

H1 <- '
  mu_11 := .Intercept.
  mu_12 := .Intercept. + dose1
  mu_13 := .Intercept. + dose2
  mu_21 := .Intercept. + suppVC
  mu_22 := .Intercept. + suppVC + dose1 + suppVC.dose1
  mu_23 := .Intercept. + suppVC + dose2 + suppVC.dose2

  mu_11 < mu_12 < mu_13    # orange juice
  mu_21 < mu_22 < mu_23    # ascorbic acid
'

out <- iht(fit.TG, constraints = H1)
out

Restriktor: restricted hypothesis tests: 


Multiple R-squared remains 0.794 

Constraint matrix:
   (Intercept) suppVC dose1 dose2 suppVC:dose1 suppVC:dose2    op rhs active
1:           0      0     1     0            0            0    >=   0     no
2:           0      0    -1     1            0            0    >=   0     no
3:           0      0     1     0            1            0    >=   0     no
4:           0      0    -1     1           -1            1    >=   0     no


Overview of all available hypothesis tests:

Global test: H0: all parameters are restricted to be equal (==)
         vs. HA: at least one inequality restriction is strictly true (>)
       Test statistic: 207.7859,   p-value: <0.0001

Type A test: H0: all restrictions are equalities (==) 
         vs. HA: at least one inequality restriction is strictly true (>)
       Test statistic: 192.2139,   p-value: <0.0001

Type B test: H0: all restrictions hold in the population
         vs. HA: at least one restriction is violated
       Test statistic: 0.0000,   p-value: 1

Joint Type A and Type B test (Wolak, 1989, Theorem 1):
         joint tail probability under H0: Rb = r (least favorable null)
       Pr[Type B >= 0.0000, Type A >= 192.2139]:   p-value: <0.0001

Type C test: H0: at least one restriction is false or active (==) 
         vs. HA: all restrictions are strictly true (>)
       Test statistic: 2.0689,   p-value: 0.02168

Note: Type C test is based on a t-distribution (one-sided), 
      all other tests are based on a mixture of F-distributions.

Step 4 – interpret the results

  • Type B is not rejected (\(\bar{F}\) = 0.00, p = 1.000): the cell means are ordered as expected.
  • Type A is rejected (\(\bar{F}\) = 192.21, p < .001).
  • Even Type C is rejected (\(t\) = 2.07, p = .022): every single step up in dose is supported, for both supplements.

Conclusion: tooth length increases with the dose of vitamin C, both for orange juice and for ascorbic acid.

The same hypothesis with the GORIC

In goric(), you can use the mu_ names directly, without the := definitions; they are added automatically. This makes it easy to compare several hypotheses. Suppose that a second theory says that orange juice is also better than ascorbic acid at the two lower doses:

H1 <- ' mu_11 < mu_12 < mu_13; mu_21 < mu_22 < mu_23 '
H2 <- ' mu_11 < mu_12 < mu_13; mu_21 < mu_22 < mu_23
        mu_11 > mu_21; mu_12 > mu_22 '

out.goric <- goric(fit.TG, hypotheses = list(H1 = H1, H2 = H2))
out.goric
restriktor (0.7): generalized order-restricted information criterion: 

Results:

Values:
           model          loglik          penalty          goric
1             H1        -159.353            4.667        328.039
2             H2        -159.353            4.248        327.201
3  unconstrained        -159.353            7.000        332.706

Weights:
           model  loglik.weights  penalty.weights  goric.weights
1             H1           0.333            0.382          0.382
2             H2           0.333            0.581          0.581
3  unconstrained           0.333            0.037          0.037
   goric.weights_without_unc
1                      0.397
2                      0.603
3                           

Conclusion:
- The order-restricted hypothesis 'H2' is the best in the set, as it has
  the highest GORIC weight.
- Since 'H2' has a higher GORIC weight than the unconstrained hypothesis,
  it is not considered weak. We can now inspect the relative support for
  'H2' against the other order-restricted hypotheses:
  * 'H2' is 1.520 times more supported than 'H1' (This relative support
    reached its maximum, see Note).

---

Additional information:

- Note: Hypotheses 'H1' and 'H2' have equal log-likelihood values. This
  indicates that they overlap and that the ratio of their GORIC weights
  reached its maximum.

- Since the best hypothesis overlaps with one or more other hypotheses, we
  recommend evaluating the overlap (or best hypothesis) vs. its complement
  (for the best hypothesis, see the post-hoc analysis mentioned below). For
  more information and an example, see the vignette
  'Guidelines_GORIC_output'; to open it, run
  vignette("Guidelines_GORIC_output", package = "restriktor").

- The benchmark() function can be used to label the height of the output,
  for example, the height of the ratio(s) of weights (e.g., to say whether
  that value denotes medium, high, or very large evidence). More details
  can be found in the vignette 'Guidelines_GORIC-benchmarks'; to open it,
  run vignette("Guidelines_GORIC-benchmarks", package = "restriktor").

- The results (including the conclusion) of the post-hoc analysis, in which
  the best hypothesis ('H2') is evaluated against its complement, are
  stored in the goric object. To see them, use:
  out.goric$posthoc

Both hypotheses fit the data equally well (the same log-likelihood): the sample means satisfy all restrictions of \(H_2\). But \(H_2\) is more specific and therefore has a smaller penalty. \(H_2\) is 1.52 times more supported than \(H_1\). Note that \(H_2\) is nested in \(H_1\): it contains all restrictions of \(H_1\) plus two more. Then \(H_2\) can never fit better than \(H_1\), and the ratio of weights can never exceed \(\exp(\text{penalty}_{H_1} - \text{penalty}_{H_2})\), here 1.52. See the GORIC(A) guidelines for how to interpret such overlapping hypotheses.