Both fits are the same additive two-way analysis of variance model: a common intercept, five country effects represented by four contrasts, and eight item effects represented by seven contrasts. The three missing cells are omitted, leaving observations and model rank , hence residual degrees of freedom. The residual sum of squares is in either ordering, giving
These are sequential sums of squares, so each row measures the improvement when that factor is added after the preceding factors. The country-first sum describes its unadjusted contribution before accounting for item; its displayed and are not the country-adjusted-for-item test. When country is added after item, its extra sum is , giving
Thus the additive normal linear model gives strong evidence of country differences after accounting for the different products. Conversely, item added after country has extra sum , so
The printed zero for this probability is numerical formatting, not a probability literally equal to zero. Product differences are much larger than residual variation, as expected from their different scales.
The explanation for the order dependence is that missing cells can destroy factor orthogonality in two-way ANOVA. A complete equally replicated crossed design would make centered country and item indicator columns orthogonal. Here the missing observations change the item mix across countries and the country mix across items, so the two factor subspaces are not orthogonal. The two sequential partitions still have the same total explained sum: to the displayed precision. For inference about either factor conditional on the other, compare the full model with the reduced model that omits that factor, rather than interpreting its first-entry sum as adjusted evidence.
The omnibus country test does not identify the particular country contrasts. As an extension, fitting the supplied price table gives the item-adjusted UK-minus-US contrast about pounds, with standard error and an ordinary Gaussian-model confidence interval approximately pounds. This is a derived model contrast, with Student t-distribution reference on degrees of freedom; simultaneous exploration of many country pairs requires control for multiple hypothesis testing.
Check residuals against fitted values, product and country, together with a normal Q-Q plot and influential observations. The homoscedasticity assumption on absolute prices may be doubtful because expensive products can have larger absolute variation. A model for logarithmic prices gives multiplicative country effects and can make the scale assumption more plausible. Country-by-item interaction terms would allow discounts to differ by product, but there is at most one observed value per cell: an unrestricted interaction saturates the observed means and leaves no pure-error degrees of freedom, so it cannot be tested against independent measurement noise from these data alone. Additional products or genuine cell replication would support that extension. The selected products and non-random missing entries also limit claims about a whole country's consumer prices; the conditional inference is for the stated additive model and observed price collection.
Write the binary incidence matrix of a set system as to avoid confusing it with a sample size. Then
counts the number of blocks containing treatment , and for , counts blocks containing both treatments. The displayed structure therefore makes every treatment replication equal to and every pair concurrence equal to .
Assume the usual nonempty block design, with and . If , any block containing one treatment contains every other treatment: otherwise that treatment's replication would exceed its concurrence with the omitted one. Every block is consequently complete, so and . With random allocation within blocks this is a randomized complete block design. If , the design is a balanced incomplete block design. Counting partners of a fixed treatment in its blocks gives
For , gives , hence . Moreover has eigenvalue on the -dimensional zero-sum subspace and eigenvalue on the constant direction. Thus , while . This proves , the Fisher's inequality for block designs. The case allows singleton blocks; their lack of connectedness prevents general treatment comparison after block adjustment, but does not invalidate the rank inequality.
First ignore the day information and use a one-way normal linear model with five group means and independent errors of common variance. There are observations. The analysis of variance has treatment, residual and corrected-total statistical degrees of freedom , respectively. The mean squares in ANOVA give
Under equal treatment means this has the F-distribution with degrees. It exceeds the given upper critical value , so the unblocked analysis rejects equality at .
The actual day allocation omits a different treatment on each of the five days. Hence it is a balanced incomplete block design with
Every pair occurs on exactly the three days omitting neither member. In the additive two-way analysis of variance, use an intercept, four independent treatment contrasts and four day contrasts. The design is connected, so the model rank is and its residual has statistical degrees of freedom. Day effects and treatment effects are not orthogonal, because a different treatment is absent each day; the unadjusted treatment sum of squares cannot be used for the adjusted test.
Enter days first and then treatments. The supplied sequential sums of squares give
The day, treatment-after-day, residual and corrected-total statistical degrees of freedom are . Under the additive normal linear model and the null of equal treatment effects, the adjusted numerator and residual squared lengths are independent chi-squared quantities, so the ratio has the F-distribution with degrees. It is below even the given critical value . After accounting for days there is no significant treatment difference at either or . This inference assumes independent homoscedastic normal errors and an additive day effect; with one observation per observed treatment–day cell, unrestricted interactions cannot also be fitted.
The commands read the 52 cell values into a vector and build the matching two-factor layout. In expand.grid(country, goods) the first factor varies fastest, so the four countries are listed successively within each goods category. This matches row-by-row reading of the displayed table. Converting Goods to a factor is essential: its labels identify 13 categories and are not a quantitative trend. Country supplies the other categorical factor. The summaries suppress coefficient correlations, not coefficient standard errors.
The first fit is the additive two-factor normal linear model
There are free coefficients and residual statistical degrees of freedom. This is two-way analysis of variance without an interaction term. For this complete balanced layout, ordinary least squares gives
These formulas follow from the row- and column-sum normal equations: fitted row and column totals equal their observed totals. The balanced-design coefficient standard errors are for a goods contrast, for a country contrast, and for the reference-cell intercept. These yield the common contrast standard errors and the different intercept standard error in each summary. In particular the intercept is the fitted Software–UK value, not the grand mean or the observed Software–UK entry.
Thus the first intercept predicts million euros for Software in the UK. The Books coefficient adds million euros to the fitted value in any country, relative to Software; every other goods coefficient has this same arithmetic-difference interpretation. The country coefficients subtract , and million euros from the UK prediction for France, Germany and the rest of Europe respectively, regardless of goods. The model therefore assumes common absolute country differences across goods categories. For Software–France its prediction is
which is impossible for positive spending and indicates a limitation of this additive original-scale specification.
The residual standard error is million euros, obtained from ; direct calculation gives . Each coefficient's printed statistic is , with a reference distribution under this normal linear model. The two-sided p-values compare each goods category with Software, or each other country with the UK, after adjustment for the other factor. For example France and the rest of Europe differ significantly from the UK at 5%, but Germany does not. The raw-scale significant goods differences are Books, Clothing, Electronic Goods, Groceries and Leisure Travel; these are individual reference-level comparisons, not an overall test of the goods factor.
The coefficient of determination is . The omnibus F-test compares all 15 nonintercept coefficients with zero:
with reference and . This says at least one factor contrast is nonzero under the assumed error model. There is one observation per cell, so an unrestricted goods-country interaction would saturate the model, leaving zero residual degrees of freedom. Without replication or a specified interaction structure, the residual variation cannot be separated into interaction and independent error.
The second fit applies a logarithmic transformation and fits the same factor design to . The Gaussian log-response model is
Its intercept exponentiates to a fitted Software–UK conditional median of million euros. Goods coefficients now give multiplicative ratios to Software, and country coefficients give multiplicative ratios to the UK. The estimated country ratios are
For example the Books ratio is and the Sports Equipment ratio is , consistently across countries. The model assumes common relative, rather than common absolute, country effects. It also guarantees positive retransformed fitted values. Under normal log errors, the original-scale conditional mean is , whereas is the conditional median and geometric mean. Correcting the retransformation bias here multiplies the naive predictions by approximately .
The log-scale residual standard error is , with the same 36 residual degrees of freedom, corresponding to a typical multiplicative error multiplier . France and the rest remain significant reference-country contrasts; Germany remains nonsignificant at 5%. The log-scale significant reference-goods contrasts are Books, Music, Videos/DVDs, Clothing, Sports Equipment, Electronic Goods, Groceries and Leisure Travel. Event Tickets, Toys, Video Games and Housewares do not individually differ significantly from Software at that level. These p-values remain subject to the usual multiple testing qualification.
The log-scale is computed using variation in the logarithms, so it cannot by itself establish better fit on the original response scale. The change is plausible because spending varies widely in magnitude and relative discrepancies are more meaningful than constant absolute discrepancies, but it should be assessed with regression diagnostics, especially a residual-versus-fitted plot and a normal Q-Q plot. The minimum residual near merits inspection; the command summaries alone do not verify independent normal errors. Moreover these responses are forecasts, so the inferential p-values have a literal sampling interpretation only if an appropriate stochastic model for their uncertainty is justified.
The log-scale analysis of variance adds Goods and then Country. In this balanced design their effect spaces are orthogonal after removing the intercept, so the sequential sums of squares equal the corresponding adjusted factor sums and are unchanged by reversing the two factors:
The residual sum of squares is , giving . Thus
Their tiny upper-tail p-values show strong overall goods and country effects under the log-error model; a globally significant country factor is compatible with the nonsignificant individual Germany contrast. The omnibus fit statistic is on degrees of freedom, whose p-value is approximately . The printed zero reflects numerical formatting, not an exactly zero probability.
If two cell entries were missing, retain their correct factor labels and mark those responses unavailable, rather than shifting the remaining scan values into different cells. Fit the additive models to the 50 observed cells, assuming the missingness mechanism permits those observations to be analyzed without selection bias. All factor levels remain represented, and the row-column incidence graph remains connected: any two goods rows still share an observed country, since only two edges of the complete layout have been removed, and every country still has many observed goods. By identifiability of an incomplete two-factor additive design, the design therefore still has rank . Hence
The coefficients and their covariance must be recomputed by the observed-cell ordinary least squares equations. The balanced row-mean-plus-column-mean formulas and common within-factor standard errors no longer apply. Goods and Country effects are generally no longer orthogonal, so sequential ANOVA sums can depend on order; factor tests adjusted for the other factor should use nested model comparisons. Missing cells do not restore replication or make an unrestricted interaction test possible: that larger model still fits every observed cell exactly. If missingness depends on the unavailable spending values, additional modelling of that mechanism would be needed.
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 , rather than . 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:
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 responses and independent mean coefficients. Thus the residual degrees of freedom are . 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 are the residual sums of squares from the intercept-only, country-only, item-only and additive fits, the first order allocates to country and to item. The second order allocates to item and to country. Both allocations sum to the same total explained sum of squares, and both end with the same residual sum of squares . 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 . In particular, the adjusted country partial F-test has
with an reference F-distribution and p-value approximately . The adjusted item partial F-test gives on 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 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 , and the fitted US boots price is .
The coefficient standard errors come from , where and is the design matrix. Dividing each estimate by its standard error gives the displayed Student t-test statistic, with 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 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 measures unexplained prices in pounds. With total corrected sum of squares , the coefficient of determination and adjusted coefficient of determination are
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: on 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 , while the full layout nominally has 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. The final fit has zero residuals, 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 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.
The data are read row by row into a vector of 84 prices. The first factor cycles through the six goods within each row; the second repeats each of the fourteen resort levels for six entries. Thus the linear regression fits one observation per resort-good cell, after taking natural logarithms. With treatment coding, its underlying statistical model is
for resorts and goods . This is an additive two-way analysis of variance on log prices, equivalently a multiplicative resort/goods model on the price scale, with no interaction. There are fitted parameters and .
In a balanced complete table, the fitted log price is the resort row mean plus the goods column mean minus the grand mean. Thus every resort coefficient is its row mean minus the Algarve row mean, and every goods coefficient is its column mean minus the meal column mean. The intercept is the fitted mean log price for a meal in Algarve, not necessarily the observed log price in that cell. Exponentiating coefficients gives price multipliers: the beer coefficient corresponds to approximately times the meal scale, and car hire to times that scale. Likewise the Sorrento resort effect gives a common factor relative to Algarve, if the no-interaction model is valid.
The standard errors are computed from with . Balance gives goods-contrast standard error and resort-contrast standard error . Each reported t statistic is its estimated coefficient divided by its standard error. Under the Gaussian model and the corresponding zero-coefficient null, it has a Student t-distribution with 65 degrees of freedom; the reported probabilities are two-sided tail probabilities. All goods contrasts are strongly significant, largely reflecting unlike goods and units of purchase. Among the resort contrasts, Costa del Sol, Majorca, Florida, Sorrento, Sicily and Madeira have unadjusted probabilities below . This is six separate comparisons with Algarve, not a simultaneous ranking guarantee or an omnibus test of all resorts. Multiple comparisons and model adequacy must be considered before declaring a universal cheapest resort.
The residual standard error measures variation on the log scale; is a typical multiplicative one-standard-deviation factor. Under the lognormal distribution, estimates the conditional median/geometric mean price, while the arithmetic mean has the additional factor . The reported means 96.2 percent of the observed log-price sum of squares around its overall mean is explained. It does not mean resorts alone explain that fraction, nor that 96.2 percent of variation on the original price scale is explained.
With only one observation per cell, unrestricted goods-by-resort interactions cannot be estimated separately from residual error. The model assumes comparable quoted items, approximately common log-error variance, independent errors and common resort multipliers across goods. Residuals can reveal failures, such as a particular resort having unusually costly taxis but ordinary prices for other goods. The intercept's test against zero concerns a fitted baseline geometric price of one pound; it is not an assessment of the overall model's validity.
A two-way analysis of variance with the full interaction and one observation in each observed factor cell has one independently varying fitted cell mean per observation. A cell-indicator design matrix has full row matrix rank, even when some combinations are missing, so the model is a saturated statistical model. Its residual sum of squares is zero and its residual degrees of freedom are zero. Missing combinations make some coefficients nonidentifiable; they do not restore a pure-error estimate. Standard errors and an ordinary residual-based F-test for interactions therefore cannot be recovered merely by fitting this larger model.