This is an analysis of covariance: achievement is the response, aptitude is a quantitative covariate, and teaching method is a categorical explanatory variable. The usual normal linear model assumes independent errors with common variance .
read.table reads the data with a header row; attach makes its columns directly accessible, and the two printed vectors confirm their ordering. rep(1:3, each=7) supplies the three group labels, and factor makes them categorical. The contrast option selects treatment coding for unordered factors, with method A as the first-level reference. The polynomial option would apply to ordered factors and has no role here.The formula using
aptitude * Group includes both main effects and their interaction. Writing for the method indicators, its fitted mean has the formThus A, B and C have separate intercepts and slopes. There are six coefficients and residual statistical degrees of freedom. The analysis of variance table uses sequential sums of squares: adding aptitude to an intercept-only model removes from the residual sum of squares; subsequently adding the two group indicators removes ; adding the two slope interactions removes only . The remaining sum of squares is , giving mean square .Each displayed F-test divides the added term's sum of squares by its statistical degrees of freedom and then by this full-model residual mean square. In particular the interaction test isThere is no evidence that the slopes differ, so the common-slope model is preferable among the fitted models. The small group -value concerns differences after including aptitude, whereas the first aptitude row is sequential and does not adjust for Group. It should not be interpreted as the covariate test after treatment adjustment.
The additive formula gives the parallel-lines modelIt has four coefficients and residual statistical degrees of freedom. Removing the interaction raises the residual sum of squares to , but lowers the residual mean square to . The sequential aptitude and group sums of squares are unchanged. The adjusted group test is now on statistical degrees of freedom, with : after allowing for initial aptitude, the methods are not all equally effective.
summary(..., cor=F) displays the fitted coefficients, their standard errors, the individual statistics, and two-sided -values; it omits the coefficient-correlation matrix. The intercept is the fitted A mean at aptitude zero, which is outside the observed range and is mainly a parametrization device. The common slope predicts about extra achievement units per aptitude unit, holding method fixed. Its adjusted test is on statistical degrees of freedom, with about . The method coefficients are adjusted differences from A, not the B and C intercepts themselves. The three fitted lines areThe B-minus-A estimate is with standard error and ; the C-minus-A estimate is with standard error and . Both comparisons are strongly significant.The B-minus-C comparison needs its own treatment contrast; its significance cannot be read off either comparison with A. Reconstructing the coefficient covariance from the design givesThus there is no detectable difference between B and C. This is consistent with pooling their effects in a further reduced model, but does not establish exact equality.
The residual standard error is . The five-number residual summary shows deviations on both sides of zero, with the largest magnitude about ; it does not by itself verify constant variance or normality. The coefficient of determination means about of the achievement variation about its overall mean is explained. The overall compares all three nonintercept coefficients with zero, on statistical degrees of freedom; its -value is . Printed coefficient -values rounded to
0.0000 are small, not literally zero.At the same initial aptitude, B and C give higher predicted achievement than A, with no convincing difference between B and C. Interpreting this adjusted association as a causal teaching effect additionally relies on the experimental allocation and error assumptions.
For an exponential dispersion family, differentiating the normalization integral with respect to gives an expected score of zero. The score is , hence . Differentiating again, the expected squared score is ; it is also . ThusThe canonical link function sets the linear predictor equal to the natural parameter: . The variance function is , so ; the dispersion parameter is separated from the mean-dependent factor.
The saturated statistical model has a separate mean for each response and fits , with boundary parameters interpreted by limits. At the same fixed dispersion, its log likelihood and the fitted model's log-likelihood define the scaled devianceThe unscaled deviance isKeeping dispersion fixed in this definition is essential; it is not a comparison with a separately estimated zero variance in a Gaussian saturated fit.
For the normal distribution, expanding its density exponent givesConsequentlyHere and the canonical link is the identity, so . The saturated natural parameter is . Substitution into the deviance formula yields
For the cholesterol fits, all formulae include an intercept. Model 1 has age and BMI with three coefficients; models 2 and 3 have one of these covariates with two coefficients; model 4 has only the intercept. Their residual statistical degrees of freedom are respectively . Their reported deviances are residual sums of squares, because these are Gaussian linear models.
The relevant hypothesis is in the full model, against , with age already present. Thus compare model 2 with model 1 using the partial F-test. Its extra sum of squares is , and the common variance is estimated from model 1 by . ThereforeSince , reject at ; the two-sided coefficient-test equivalent has . BMI is associated with cholesterol after adjustment for age, under the linear Gaussian model. The RSS values alone do not identify the sign of its coefficient or the size of the association.
For comparison, the marginal BMI test would compare model 4 with model 3, giving on statistical degrees of freedom, with . This does not answer the adjusted question and makes the BMI evidence appear stronger than the conditional test. Age also contributes after BMI: comparing model 3 with model 1 gives on statistical degrees of freedom, with . Thus retaining both predictors is supported at the stated level.
A raw deviance difference must not simply be compared with the supplied cutoff: Gaussian dispersion is unknown and the differences here are unscaled. If were known, the scaled difference would have a law. Estimating it from the full fit gives the exact finite-sample comparison above, with the appropriate denominator statistical degrees of freedom.
The logit link makes the probability constant within each group: write , with . Let and . Independence gives . Up to terms independent of the parameters, the log likelihood isThe likelihood equations areTogether they also imply . Thus, when all totals satisfy ,The group logits are unconstrained apart from their parametrization, and each binomial log likelihood is strictly concave in its logit, so these equations give the unique finite maximum. A total of or instead gives a boundary probability and an infinite logit; a finite MLE need not exist in that case.
For , keep fixed and let . Since , the central limit theorem gives . The derivative of the logit is , so the delta method gives the baseline logit estimator in a group-factor binomial model lawThe second group does not improve the baseline estimate because it has its own free offset. Equivalently, the Fisher information matrix for isIts first diagonal entry confirms the same asymptotic variance.
factor(day) treats the nine days as categorical rather than imposing a numerical time trend. rep(400,27) supplies the number of trials for every dish, and prop is the observed surviving proportion. The contrast setting uses treatment coding with day 1 as reference; the ordered-factor polynomial option is unused. Supplying these proportions to glm with the binomial family and weights gives precisely the grouped-binomial logistic regression likelihood for the counts. The weights represent trial counts, not additional independent dish observations. The binomial family's default link is the logit link and its dispersion is fixed at .Let be survivors in dish on day . Both fitted models assume independent . Model 1 specifiesso it has one common probability and one fitted coefficient. Its estimated probability is the total surviving count divided by the total trial count, .
Model 2 specifiesIt has nine coefficients and allows a separate probability for each day, while retaining a common probability for the three dishes within that day. The MLEs are the day totals divided by . In day order they areThe intercept is the first day's logit, and each other coefficient is its day's logit minus that reference. These are additive effects on log odds, not additive changes in survival probability.
The analysis of deviance adds the eight day indicators after an intercept-only model. Its residual deviance compares a fitted model with the saturated statistical model assigning one separate probability to each of the dishes. For fitted dish probabilities , the binomial deviance isThe binomial scale is one, so this is also scaled deviance. The reported decrease measures the extra fit provided by day. There are observational units for these residual statistical degrees of freedom, not separately fitted Bernoulli responses.
The null model uses one parameter, the day model uses nine, and there are grouped observations. The four missing entries, in their table order, are thereforeThe test of no day effect is . The nominal binomial likelihood-ratio test statistic is , compared asymptotically with . Its nominal -value is about , so the common-probability model is decisively inadequate relative to the day model. The fitted probabilities in (i) show substantial differences between days, with days 1 and 7 much higher than days 3 and 8.
However, relative improvement does not establish absolute fit. The day model's deviance goodness-of-fit test compares with , giving . The counts are large enough for this approximation to be reasonable. Thus at the day-specific binomial model still shows lack of fit. Among the two printed models it is preferred, but it should not be regarded as a fully satisfactory final model.
The residual scale estimate suggests overdispersion. Directly computing the Pearson statistic from the day means givesThis corroborates extra dish variation rather than the nominal binomial variance. Dish heterogeneity or dependence among cells in a dish can produce such variation. Residual checks and a quasibinomial regression or an explicit model for dish heterogeneity are sensible refinements. Allowing dispersion of this moderate magnitude would enlarge standard errors but would not plausibly remove the very large day effect. Retain day effects, while accounting for the remaining extra-binomial variation.
The experimental unit for comparing the treatments is the pot: its two plants form a pair. Let be cross-fertilised minus self-fertilised height in pot , for . The paired Wilcoxon signed-rank test assumes independent differences with a continuous distribution symmetric about a location . Its null is , with the one-sided formulation , against . Under this location model it asks whether cross-fertilisation produces a positive shift within a pot. The location is a median, and also a mean if it exists; a hypothesis merely about a median without symmetry does not justify the signed-rank null distribution.
Test 1 uses this paired test and its exact distribution. Form the fifteen differences, omit any zero differences, rank their absolute values, and sum the statistical ranks belonging to positive differences. That positive-rank sum is the reported . Tied absolute differences receive average statistical ranks. Under the symmetric zero-location null, conditional on their magnitudes, the signs are independent fair signs. The exact upper-tail probability is obtained from all sign allocations to the observed statistical ranks: with fifteen nonzero differences there are equiprobable allocations. For untied absolute differences the rank weights are ; ties would require the corresponding conditional rank weights. The reported probability of a positive-rank sum at least as large as observed is . No normal approximation is used.
Test 2 makes exactly the same paired comparison and has the same null and alternative hypotheses.
exact=F replaces the exact distribution by a normal approximation with a continuity correction. Under an untied null the positive-rank sum hasMore generally, conditional on the nonzero absolute statistical ranks , its variance is . The upper-tail correction places the boundary half a lattice unit below the observed statistic. Standardizing gives the reported , and its approximate -value is . Thus the slight difference from Test 1 reflects approximation, not a different scientific question.Test 3 omits
paired=T, so it is the unpaired Wilcoxon rank sum test. Its usual distribution-free null is that two independent samples have the same continuous distribution. In a common-shape location model this is a zero location difference, against a positive cross-minus-self shift. More generally “greater” directs the test towards the cross distribution being shifted upwards; it does not turn the test into a general comparison of means or medians for arbitrary unequal shapes.To form its statistic, pool the thirty heights, rank them together with averaged statistical ranks for ties, and add the cross-group statistical ranks to get . Equivalently use . Under independent untied samples,If the pooled ties have sizes and , the variance becomesSubtract the null mean and the upper-tail continuity correction, then divide by this null standard deviation. This procedure gives the reported rank-sum . Its approximate one-sided probability is . This describes how the statistic and probability are obtained without reconstructing the unprinted heights.
For the statistician, use the paired analysis, preferably the exact Test 1 for these fifteen pairs. The independent units are the pots, while the two heights within a pot share growing conditions and cannot be treated as independent samples. Test 2 is a reasonable approximation to the same paired test and agrees closely. Test 3 discards the matching and uses a null variance that assumes independence between the samples, so its smaller -value is not a reason to prefer it. The appropriate paired result gives evidence at , but not at , that cross-fertilised plants have a positive height shift relative to their paired self-fertilised plants, subject to the symmetry assumption for differences.
A Gaussian generalised additive model with the identity link specifiesThe are unknown smooth functions estimated from the data, rather than necessarily straight lines. The model is additive in their effects, so it does not automatically contain interactions between covariates. To identify the intercept separately from the smooths, impose a constraint such as for each . Linear terms can also be included alongside smooth terms. More generally a specified link function can make additive; for the normal identity-link model the mean itself has the displayed form. Smoothness is typically controlled through a basis and a roughness penalty, preventing an unrestricted smooth from interpolating all the noise.
A natural cubic spline interpolant satisfies , is twice continuously differentiable, and is a polynomial of degree at most three on each interval . Its natural boundary conditions areIf defined outside the data interval, it continues linearly on both exterior intervals. Thus function values and the first two derivatives match at the knots, but the third derivative may jump.
For an explicit construction, let and . Set and solveOn , putThis formula interpolates the values and matches second derivatives; the tridiagonal equations enforce first-derivative matching. The homogeneous system has only the zero solution: in a row with maximal nonzero , its diagonal coefficient strictly exceeds the sum of its neighbour coefficients, making cancellation impossible. Thus the natural interpolant exists uniquely.
With the convention that the residual term is a sum rather than an average, the penalised least squares criterion isMinimize over functions whose first derivative is absolutely continuous and whose second derivative is square-integrable, that is, the usual Sobolev space . The cubic smoothing spline is its minimizer, with natural boundary conditions and linear continuation outside the data range. It is a natural cubic spline with possible knots at the observed , but usually does not interpolate the noisy .
To see why the minimizer is a natural spline, for any take the natural cubic spline interpolant through its values and write . Then . Integrating by parts on every knot interval twice gives zero: the terms involving vanish at knots, the terms involving cancel because is continuous there, and the outer terms vanish by the natural boundary conditions. Hencewhile their residual sums of squares agree. Replacing by never increases the criterion. This proves the minimum roughness property of the natural cubic spline interpolant needed here.
For fitted values , write , where is positive semidefinite and has the sampled affine functions as its two-dimensional nullspace. The finite-dimensional minimization becomes . Its strictly positive definite Hessian is , so it has the unique solutionThis is the roughness-matrix formula for a natural cubic smoothing spline. Larger penalizes curvature more strongly. As the fit approaches interpolation; as it approaches the ordinary least-squares affine line.
Let be the influence matrix, so . Its trace is the effective degrees of freedom, accounting for shrinkage of the fitted smooth rather than just counting basis coefficients. The generalised cross-validation score isFor a fixed smoothing parameter, the exact leave-one-out residual of this penalized linear fit is , obtained by removing its observation's contribution to the normal equations. Thus Leave-one-out cross-validation uses the average of their squared values. GCV replaces the individual leverages by their average . This avoids separate refits and gives a criterion balancing the small training residuals of a flexible fit against its larger complexity.
Evaluate the score across positive , or optimize it numerically, and choose minimizing GCV. Then refit or retain the spline at this value. In the full natural smoothing-spline family the trace decreases from towards as smoothing increases. The selected parameter is intended to give good prediction, rather than necessarily to pass through every point.
library(mgcv) loads the fitting package; gam fits a Gaussian generalised additive model with the printed identity link. The smooth specification s(x, bs="cr") uses a penalized cubic regression spline. This is a finite-dimensional smooth basis, rather than a full interpolating spline with a free value at all observations. The fitted model isHere in the centred cubic regression-spline basis, with its curvature penalized through . The intercept is estimated separately. In the displayed fit the smooth test space has rank , consistent with nine smooth coefficients after the centring constraint, while penalization lowers its effective dimension.The intercept estimate is , with standard error , and . Because the smooth is centred over the observations, the intercept is the overall fitted average, not necessarily the fitted response at . Its test compares this average with zero. The significance-code legend maps progressively smaller -values to stars; stars are an annotation, not an effect-size measure.
The smooth has effective degrees of freedom, displaying substantial nonlinearity: a centred purely linear term would use one.
Est.rank=9 reports the rank used for its approximate significance calculation. The -value below is very strong evidence that the mean depends on , against a zero smooth term. It does not mean the fitted curve is the exact generating function, or that lack of fit has been tested. The total effective dimension including the intercept is .The adjusted coefficient of determination of and deviance explained of indicate that nearly all variation about the response mean is explained. For this Gaussian model, deviance explained is . The scale estimate estimates residual variance, corresponding to a residual standard deviation about . The GCV score is the prediction-oriented criterion used for smoothing selection, not a probability. It is consistent with the reported scale and effective dimension: .
In the PDF's plot, the solid curve is the estimated centred smooth , and the dashed curves show pointwise uncertainty around that smooth, rather than prediction intervals for new noisy responses. The label
s(x,8.24) gives its rounded effective degrees of freedom. The rug marks the observed covariate locations. Reading the endpoints givesThe smooth is increasing with an almost flat middle and one inflection, resembling a cubic. A simpler model to investigate is ordinary Gaussian polynomial regressionIt uses four mean coefficients rather than about nine effective ones. The apparent near-odd shape also makes a plausible further reduction, but the linear and quadratic terms should be checked rather than discarded solely from the picture. The figure suggests this alternative; it does not supply coefficients or establish the true simulation model. Articles by others on the same topic
There are currently no matching articles.
