F73DA2 INTRODUCTORY DATA ANALYSIS ANALYSIS OF VARIANCE
regression: x is a quantitative explanatory variable
type is a qualitative variable (a factor)
Company 1: Company 2: Company 3: Illustration
Explanatory variable qualitative i.e. categorical - a factor Analysis of variance linear models for comparative experiments
► The display is different if “type” is declared as a factor. Using Factor Commands
► We could check for significant differences between two companies using t tests. ► t.test(company1,company2) ► This calculates a 95% Confidence Interval for difference between means
Includes 0 so no significant difference
Instead use an analysis of variance technique
Taking all the results together
We calculate the total variation for the system which is the sum of squares of individual values –
► We can also work out the sum of squares within each company This sums to
► The total sum of squares of the situation must be made up of a contribution from variation WITHIN the companies and variation BETWEEN the companies. ► This means that the variation between the companies equals
► This can all be shown in an analysis of variance table which has the format:
Source of variation Degrees of freedom Sum of squares Mean squares F Between treatments k 1 SS B SS B /(k 1) Residual (within treatments) n k SS RES SS RES /(n k) Total n 1 SS T
Source of variation Degrees of freedom Sum of squares Mean squares F Between treatments k SS B /(k 1) Residual (within treatments) n k SS RES /(n k) Total n
► Using the R package, the command is similar to that for linear regression
Data: y ij is the j th observation using treatment i where the errors ij are i.i.d. N(0,s 2 ) Model : Theory
The response variables Y ij are independent Y ij ~ N(µ + τ i, σ 2 ) Constraint:
Derivation of least-squares estimators
The fitted values are the treatment means
Partitioning the observed total variation SST = SSB + SSRES SSTSSRES SSB
The following results hold The following results hold
Back to the example
Fitted values: Company 1: 320/10 = 32 Company 2: 225/8 = Company 3: 335/9 = Residuals: Company 1: 1j = y 1j - 32 Company 2: 2j = y 2j Company 3: 3j = y 3j
SS T = – /27 = SS B = (320 2 / / /9) – /27 = = SS RES = – =
ANOVA table Source of Degrees of Sum Mean F variation freedom of squares squares Between treatments Residual Total
Testing H 0 : τ i = 0, i = 1,2,3 v H 1 : not H 0 (i.e. τ i 0 for at least one i) Under H 0, F = 3.83 on 2,24 df. P-value = P(F 2,24 > 3.83) = so we can reject H 0 at levels of testing down to 3.6%.
Conclusion Results differ among the three companies (P-value 3.6%)
The fit of the model can be investigated by examining the residuals: the residual for response yij is this is just the difference between the response and its fitted value (the appropriate sample mean).
Plotting the residuals in various ways may reveal ●a pattern (e.g. lack of randomness, suggesting that an additional, uncontrolled factor is present) ●non-normality (a transformation may help) ●heteroscedasticity (error variance differs among treatments – for example it may increase with treatment mean: again a transformation – perhaps log - may be required)
► In this example, samples are small, but one might question the validity of the assumptions of normality (Company 2) and homoscedasticity (equality of variances, Company 2 v Companies 1/3).
► plot(residuals(lm(company~type))~ fitted.values(lm(company~type)),pch=8)
► abline(h=0,lty=2)
► It is also possible to compare with an analysis using “type” as a qualitative explanatory variable ► type=c(rep(1,10),rep(2,8),rep(3,9)) ► No “factor” command
The equation is company = x type Note low R 2
Example A school is trying to grade 300 different scholarship applications. As the job is too much work for one grader, 6 are used.
Example A school is trying to grade 300 different scholarship applications. As the job is too much work for one grader, 6 are used. The scholarship committee would like to ensure that each grader is using the same grading scale, as otherwise the students aren't being treated equally. One approach to checking if the graders are using the same scale is to randomly assign each grader 50 exams and have them grade.
To illustrate, suppose we have just 27 tests and 3 graders (not 300 and 6 to simplify data entry). Furthermore, suppose the grading scale is on the range 1-5 with 5 being the best and the scores are reported as: grader grader grader
The 5% cut off for F distribution with 2,21 df is The null hypothesis cannot be rejected. No difference between markers.
ClassIIIIIIIVVVI Another Example
Source of variation dfSum of squares Mean squares F Between treatments Residual Total
Normality and homoscedasticity (equality of variance) assumptions both seem reasonable
We now wish to Calculate a 95% confidence interval for the underlying common standard deviation , using SSRES/ 2 as a pivotal quantity with a 2 distribution.
It can easily be shown that the class III has the largest value of and that Class II has the smallest value of Consider performing a t test to compare these two classes
There is no contradiction between this and the ANOVA results. It is wrong to pick out the largest and the smallest of a set of treatment means, test for significance, and then draw conclusions about the set. Even if H 0 : " all equal" is true, the sample means would differ and the largest and smallest sample means perhaps differ noticeably.