Download as xlsx, pdf, or txt
Download as xlsx, pdf, or txt
You are on page 1of 17

TreatmentFactor A Factor B Data

1 -1 -1 10.34 This data is from exercise 1.4, in this spreadsheet we will wa


1 -1 -1 10.44 First, we'll use the built in ANOVA analysis function of Excel
1 -1 -1 10.29
2 1 -1 10.32
2 1 -1 10.29
2 1 -1 10.25
3 -1 1 10.11
3 -1 1 10.135
3 -1 1 10.095
4 1 1 10.234
4 1 1 10.245
4 1 1 10.223

To use built in Excel data analysis ("ANOVA: two-factor with replication") arrange the data like this:
Factor B
-1 1
Factor A -1 10.34 10.11 To perform two factor ANOVA, follow these steps
10.44 10.135 Click "data analysis" under the Data ribbon, and select "ANOVA: two-fa
10.29 10.095 *Note: if you don't see the Data Analysis button, you will need to load
1 10.32 10.234 For input range, highlight the cells outlined in green to the left
10.29 10.245 For number of rows per sample, put the number of replicates (in this ca
10.25 10.223 Choose an output range where Excel will provide the results of the ana

Excel will then produce the results of the ANOVA analysis (everything in the blue box was generated by Excel):
Anova: Two-Factor With Replication

SUMMARY -1 1 Total
-1
Count 3 3 6
Sum 31.07 30.34 61.41
Average 10.35667 10.11333 10.235
Variance 0.005833 0.000408 0.02026

1
Count 3 3 6
Sum 30.86 30.702 61.562
Average 10.28667 10.234 10.26033
Variance 0.001233 0.000121 0.001374

Total
Count 6 6
Sum 61.93 61.042
Average 10.32167 10.17367
Variance 0.004297 0.00458

ANOVA
Source of VariationSS df MS F P-value F crit
Sample 0.001925 1 0.001925 1.013867 0.343459 5.317655 Here "sample" refers to the
Columns 0.065712 1 0.065712 34.60348 0.000369 5.317655 "Columns" refers to the fact
Interaction 0.027265 1 0.027265 14.35773 0.005318 5.317655
Within 0.015192 8 0.001899

Total 0.110095 11
n this spreadsheet we will walk through performing ANOVA on this data three ways.
VA analysis function of Excel

he data like this:

on, and select "ANOVA: two-factor with replication"


button, you will need to load the analysis ToolPak add in. Go to file -> options -> add-ins, select "Analysis ToolPak" and click "Go". Chec
ed in green to the left
number of replicates (in this case, 3)
provide the results of the analysis (I used output range B28 in this example)

x was generated by Excel):


Here "sample" refers to the factor corresponding to the rows (Factor A, in this case)
"Columns" refers to the factor corresponding to the columns (Factor B, in this case)
ToolPak" and click "Go". Check the analysis ToolPak box and click "OK"
TreatmentFactor A Factor B Data
1 -1 -1 10.34 We can also calculate the two-factor ANOVA "manually" (e.
1 -1 -1 10.44 This is useful because it can be more easily extended to mor
1 -1 -1 10.29
2 1 -1 10.32
2 1 -1 10.29 We can put our ANOVA table here:
2 1 -1 10.25 Source SS DOF
3 -1 1 10.11 Factor A 0.001925 1
3 -1 1 10.135 Factor B 0.065712 1
3 -1 1 10.095 Interaction 0.027265 1
4 1 1 10.234 Within 0.015192 8
4 1 1 10.245
4 1 1 10.223 Total 0.110095 11
To start, we'll only have the degrees of freedom c
Grand mean: 10.24767
Next, we need to fill in the SS column
We can calculate these using the equations on slid
ences from grand mean (for total variance): 0.092333
0.192333 To calculate SS for factor A:
0.042333 average when A is low: 10.235 difference
0.072333 average when A is high: 10.26033
0.042333
0.002333 To calculate SS for factor B:
-0.137667 average when B is low: 10.32167 difference
-0.112667 average when B is high: 10.17367
-0.152667
-0.013667 To calculate SS for interaction "AB":
-0.002667 average of treatment 1: 10.35667 differences
-0.024667 average of treatment 2: 10.28667
average of treatment 3: 10.11333
average of treatment 4: 10.234

To calculate SS for within variance (i.e., SSerror):


Differences for treatment 1: -0.016667
0.083333
-0.066667
Differences for treatment 2: 0.033333
0.003333
-0.036667
Differences for treatment 3: -0.003333
0.021667
-0.018333
Differences for treatment 4: 0
0.011
-0.011
To calculate total variance:
SSTotal: 0.110095 (calculated as sum of square

Note: you don't actually need to calculate each SS

We can calculate MS values as the corresponding


We can then calculate the F ratio as the correspon
Finally, we can calculate the p-values using the F d
factor ANOVA "manually" (e.g., not using built in functionality)
more easily extended to more than two factors, which can't be done with ToolPak

OVA table here:


MS F P-value
0.001925 1.013867 0.343459
0.065712 34.60348 0.000369
0.027265 14.35773 0.005318
0.001899

ave the degrees of freedom column filled in. You should be able to complete the DOF column just from the experimental design

in the SS column
ese using the equations on slides 62 and 63 from week 1

-0.012667 SSA: 0.001925 (calculated as levels*replicates*sum of square error between A means and grand mean)
0.012667

0.074 SSB: 0.065712 (calculated as levels*replicates*sum of square error between B means and grand mean)
-0.074

nteraction "AB":
0.047667 SSAB: 0.027265 (calculated as replicates*sum of squares of interaction differences: y - y_i - y_j +grand mean)
-0.047667
-0.047667
0.047667

within variance (i.e., SSerror):


SSerror: 0.015192 (calculated as sum of squares of differences from each data point and treatment mean)
(calculated as sum of squares of each data point difference from grand mean)

ually need to calculate each SS term. Since all the rows should sum to the total value, you can calculate all SS terms but one and use this

S values as the corresponding SS value divided by the degrees of freedom


te the F ratio as the corresponding MS value divided by the MS value of the "within" row
late the p-values using the F distribution
e experimental design

means and grand mean)

means and grand mean)

es: y - y_i - y_j +grand mean)

tment mean)
SS terms but one and use this simple sum rule to calculate the last SS term.
TreatmentFactor A Factor B Data
1 -1 -1 10.34 Lastly, if you prefer to use Matlab, we can use the function a
1 -1 -1 10.44 In this approach, the majority of our effort will be spent arra
1 -1 -1 10.29
2 1 -1 10.32 First, our output data should be put into a vector. We can do
2 1 -1 10.29 y = [10.34 10.44 10.29 10.32 10.29 10.25 10.11 10.135 10.095
2 1 -1 10.25 Note that in practice it is usually easier to cut and paste the
3 -1 1 10.11
3 -1 1 10.135 next we need to define the factors and levels associated wit
3 -1 1 10.095 The levels associated with factor A (or "group 1" in Matlab c
4 1 1 10.234 g1 = [-1 -1 -1 1 1 1 -1 -1 -1 1 1 1]
4 1 1 10.245 The levels associated with factor B (or "group 2" in Matlab c
4 1 1 10.223 g2 = [-1 -1 -1 -1 -1 -1 1 1 1 1 1 1]
Basically, the "group" vectors should be set up so that if you

Finally, we run the following line to have Matlab perform AN


anovan(y,{g1,g2})
This will output the following ANOVA table:

You'll notice that this table is a little different from our previ
We can rerun the function again with a slightly different fun
anovan(y,{g1,g2},'interaction')
To get the following table:
Which matches our ANOVA analysis from both Excel method

To extend this to more than two factors, you just need to de


anovan(y,{g1,g2,g3,g4})
lab, we can use the function anovan to perform MANOVA
of our effort will be spent arranging the data in the correct format

e put into a vector. We can do this with the following command:


.29 10.25 10.11 10.135 10.095 10.234 10.245 10.223]'
ly easier to cut and paste the column from a spreadsheet program than to type the data out as a row vector and transpose it

tors and levels associated with this data.


or A (or "group 1" in Matlab convention) can be defined with this line:

or B (or "group 2" in Matlab convention) can be defined with this line:

hould be set up so that if you look at the i-th entry, it should have the level associated with the i-th entry in the output data vector

ne to have Matlab perform ANOVA analysis:

ANOVA table:

little different from our previous tables. This is because by default, "anovan" doesn't consider interaction effects.
n with a slightly different function call:
alysis from both Excel methods.

wo factors, you just need to define more groups. So for example, the function call for a four factor MANOVA might look like this:
or and transpose it

in the output data vector


A might look like this:

You might also like