Solution (source code)

= Solution

`scan` reads the numerical prices, including the three missing-value markers, into a vector. The data must be read row by row for the subsequent factor construction to match them. The <sample size> available for analysis is therefore $37$, rather than $40$. The numerical summary describes the observed prices: the <sample median> is £43.54 and the <sample mean> is £46.94. The upper tail, particularly the boots, raises the <sample mean> above the <sample median>. These summaries mix very different products and are not adjusted country comparisons.

The two character scans create labels. `gl(8,5,length=40,labels=item)` makes a <regression factor> with each of eight item labels repeated five times. `gl(5,1,length=40,labels=country)` cycles through the five country labels once for each item. For a <regression factor> and numerical response, the two `plot` commands produce grouped <box plots>. The country <box plots> suggest lower US prices, while the item <box plots> show particularly expensive boots and inexpensive cardigans. They are descriptive displays of this small basket, with different item compositions where prices are missing; they cannot separate country effects from item effects.

The first `lm` fits an additive <two-way analysis of variance>:
$$
p_{ij}=a+c_j+d_i+\varepsilon_{ij},\qquad c_{\mathrm{UK}}=0,\quad d_{\mathrm{jeans}}=0.
$$
The constraints are R's usual <treatment coding>. The <normal linear model> used for the printed tests assumes <independent> errors with common <variance> and approximately a <normal distribution>, and no item-by-country <interaction> in the mean. Missing prices are omitted, leaving $37$ responses and $1+4+7=12$ independent mean coefficients. Thus the <residual degrees of freedom> are $37-12=25$. This deletion is defensible for the conditional price model when missingness does not depend on the unobserved error after conditioning on the two factors; the output itself does not establish such a <missing-data mechanism>.

The `anova` tables report <sequential sums of squares>, rather than order-independent adjusted effects. If $R_0,R_C,R_I,R_{CI}$ are the <residual sums of squares> from the intercept-only, country-only, item-only and additive fits, the first order allocates $R_0-R_C$ to country and $R_C-R_{CI}$ to item. The second order allocates $R_0-R_I$ to item and $R_I-R_{CI}$ to country. Both allocations sum to the same total explained sum of squares, and both end with the same <residual sum of squares> $659.4$. The three missing combinations destroy <balanced factorial orthogonality>, so the allocation changes with order. To test country after allowing for items, use the country row in the second table; to test item after allowing for countries, use the item row in the first table. The first-entered rows do not supply those adjusted tests.

Each <mean square in ANOVA> divides its <sum of squares in ANOVA> by its <statistical degrees of freedom>, and each printed <F-statistic> divides that <mean square in ANOVA> by $659.4/25=26.38$. In particular, the adjusted country <partial F-test> has
$$
F=\frac{1616.7/4}{659.4/25}=15.32,
$$
with an $F_{4,25}$ reference <F-distribution> and <p-value> approximately $1.86\times10^{-6}$. The adjusted item <partial F-test> gives $F=91.58$ on $7,25$ <statistical degrees of freedom>. Both factors contribute strongly under the additive <normal linear model>. The larger item <sum of squares in ANOVA> measures the much greater differences between these products, but is not evidence that every pair of items differs significantly.

The intercept $50.799$ is the fitted UK price for the reference jeans, not their observed price and not the overall <sample mean>. Each country <regression coefficient> is its adjusted price difference from the UK, assumed common across items: Sweden is £5.224 lower, France £10.708 lower, Germany £7.676 lower and the US £21.328 lower. Each item <regression coefficient> is its adjusted difference from the reference jeans, assumed common across countries. Thus the fitted UK boots price is $50.799+52.854=103.653$, and the fitted US boots price is $103.653-21.328=82.325$.

The coefficient <standard errors> come from $s^2(X^TX)^{-1}$, where $s^2=659.4/25$ and $X$ is the <design matrix>. Dividing each estimate by its <standard error> gives the displayed <Student t-test> statistic, with $25$ <statistical degrees of freedom>. The stars summarize the corresponding two-sided <p-values>. The individual tests compare each indicated country or item with its reference level, conditional on all other additive terms; they are neither tests of every pairwise comparison nor a simultaneous <confidence interval> procedure. In particular, Sweden's <p-value> $0.0626$ provides weaker evidence than the other country contrasts, and does not establish equality with the UK. The intercept test has little substantive relevance, and interpreting many individual stars also raises <multiple hypothesis testing> issues.

The <residual standard error> $s=5.136$ measures unexplained prices in pounds. With total corrected sum of squares $T$, the <coefficient of determination> and <adjusted coefficient of determination> are
$$
R^2=1-\frac{659.4}{T}=0.9647,\qquad
\overline R^2=1-\frac{659.4/25}{T/36}=0.9492.
$$
Much of this impressive fit is due to the large differences between items. The overall <F-test> compares the additive fit with a constant mean: $F=((T-659.4)/11)/(659.4/25)=62.12$ on $11,25$ <statistical degrees of freedom>. It tests that all eleven non-intercept coefficients vanish, not that the additive model is adequate. <Regression diagnostics> should examine <regression residuals>, changing price variability across items and possible <interaction>. Percentage differences may be more plausible than common pound differences, motivating a <natural logarithm> of price. No random sample of countries or products, and no independent replication of a price within a cell, is supplied; broad claims about all designer goods or the causes of country differences require more than these conditional tests.

Finally, `Item*Country` expands to both main effects and their full <interaction>. A cell-means parameterization has one separate fitted mean for every observed cell. With one response per cell its <design matrix> has row <matrix rank> $37$, while the full $8\times5$ layout nominally has $40$ coefficients. Three coefficient combinations are aliased because their cells are missing. This is <saturation of an unreplicated two-factor regression>: every observed price is fitted exactly and the <residual degrees of freedom> are zero. \b[The final fit has zero residuals, $R^2=1$ and no residual-based estimate of the error variance or ordinary interaction significance test.] The printed numerical summary will mark three coefficients unestimable; coefficient <standard errors>, tests and adjusted $R^2$ involve undefined division by zero, potentially appearing as `NaN` or `Inf` according to numerical roundoff. Perfect interpolation here is a consequence of a <saturated statistical model>, not evidence for a superior predictive model.