# [R] Need to calculate within- and between- run CV

Michal Figurski figurski at mail.med.upenn.edu
Mon Oct 6 19:28:50 CEST 2008

Dear R-helpers,

I have a dataset named "qu", organized as follows:

Sample	Run	Replicate	Value
1	1	1		25
1	1	2		40
1	1	3		33
1	1	4		29
1	2	1		37
1	2	2		44
1	2	3		45
1	3	1		25
1	3	2		40
1	4	1		33
1	4	2		29
1	4	3		25
2 ...

Basically, a sample was run on an assay multiple times within a single
day. Each of these results is "Replicate". Then run was repeated several
times in consecutive days - variable "Run". There are 210 such samples.

I need to actually calculate the CV for each sample:
- within run (between replicates) - that's easy to do in Excel
- between run - that's the problem.

I was thinking of using either 'aov' or 'lme' to solve this. However, I
don't know how to interpret the output. For example, a summary output
from "aov(Value~Run+Replicate, subset(qu,Sample==79))' for one sample was:

Df Sum Sq Mean Sq F value Pr(>F)
Run          1  4.000   4.000  0.3214 0.6104
Replicate    1 73.500  73.500  5.9062 0.0933 .
Residuals    3 37.333  12.444
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Do you guys think this is correct approach?
How do I extract these numbers (sum of squares) to store in a separate
dataframe for further calculations?

And how should I interpret the "Residual" in this setting?