Introduction To The Methcomp Package: Bendix Carstensen Steno Diabetes Center, Gentofte, Denmark
Introduction To The Methcomp Package: Bendix Carstensen Steno Diabetes Center, Gentofte, Denmark
MethComp package
1 Overview of MethComp 3
1.1 Data structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.1.1 Wide format data . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.2 Function overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.2.1 Graphical functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.2.2 Data manipulating functions . . . . . . . . . . . . . . . . . . . . . . 7
1.2.3 Analysis functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.2.4 Reporting functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2 Worked examples 9
2.1 Fat measurements: Exchangeable replicates . . . . . . . . . . . . . . . . . 9
2.2 Cardiac output: Linked replicates? . . . . . . . . . . . . . . . . . . . . . . 14
2.3 Systolic blood pressure: Linked replicates by two methods . . . . . . . . . 19
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2
Chapter 1
Overview of MethComp
3
4 1.1 Data structures
> summary( ox )
#Replicates
Method 1 2 3 #Items #Obs: 354 Values: min med max
CO 1 4 56 61 177 22.2 78.6 93.5
pulse 1 4 56 61 177 24.0 75.0 94.0
If variables meth, item, repl and y are not availabe in the data frame we may create
them on the fly or give the variable positions as arguments to the Meth function:
> data( fat )
> str( fat )
> str( sc )
> summary( sc )
#Replicates
Method 3 #Items #Obs: 258 Values: min med max
KL 43 43 129 0.39 1.7 4.2
SL 43 43 129 0.51 1.7 4.1
We may even give some of them as names of the columns in the dataframe:
> vi <- Meth( fat, 2,1,"Rep","Vic" )
The following variables from the dataframe
"fat" are used as the Meth variables:
meth: Obs
item: Id
repl: Rep
y: Vic
#Replicates
Method 3 #Items #Obs: 258 Values: min med max
KL 43 43 129 2.0 3.9 6.5
SL 43 43 129 2.3 4.1 6.7
However, more complicated operations on the dataframe is best done on the fly using
the with function (from the base package):
> data( hba1c )
> str( hba1c )
'data.frame': 835 obs. of 6 variables:
$ dev : Factor w/ 3 levels "BR.V2","BR.VC",..: 2 2 2 2 2 2 2 2 1 1 ...
$ type : Factor w/ 2 levels "Cap","Ven": 2 2 2 2 1 1 1 1 2 2 ...
$ item : num 12 12 12 12 12 12 12 12 12 12 ...
$ d.samp: num 1 1 1 1 1 1 1 1 1 1 ...
$ d.ana : num 2 3 4 5 2 3 4 5 2 3 ...
$ y : num 8.7 8.7 8.7 8.7 9.2 9 8.8 8.7 9.4 9.3 ...
> hb1 <- with( hba1c,
+ Meth( meth = interaction(dev,type),
+ item = item,
+ repl = d.ana-d.samp,
+ y = y, print=TRUE ) )
#Replicates
Method 3 4 #Items #Obs: 835 Values: min med max
BR.V2.Cap 0 38 38 152 5.3 8.0 12.6
BR.VC.Cap 19 19 38 133 5.3 8.2 12.1
Tosoh.Cap 0 38 38 152 5.0 7.8 11.8
BR.V2.Ven 19 19 38 133 5.5 8.1 12.0
BR.VC.Ven 19 19 38 133 5.3 8.0 11.6
Tosoh.Ven 20 18 38 132 5.3 8.0 12.1
> str( hb1 )
Classes 'Meth' and 'data.frame': 835 obs. of 4 variables:
$ meth: Factor w/ 6 levels "BR.V2.Cap","BR.VC.Cap",..: 5 5 5 5 2 2 2 2 4 4 ...
$ item: Factor w/ 38 levels "1","2","3","4",..: 12 12 12 12 12 12 12 12 12 12 ...
$ repl: Factor w/ 5 levels "0","1","2","3",..: 2 3 4 5 2 3 4 5 2 3 ...
$ y : num 8.7 8.7 8.7 8.7 9.2 9 8.8 8.7 9.4 9.3 ...
Objects of class Meth (which inherits from data.frame) has methods such as summary,
plot, subset and transform. The functions mostly do not require the data to be in
Meth format — if a dataframe with the right columns is supplied, it is normally
converted internally to Meth format.
6 1.2 Function overview
> head( RM )
The example code from the manual page can be run directly by:
> example( plot.Meth )
The MethComp package. 7
bothlines Adds regression lines of y on x and vice versa to a scatter plot. Optionally,
the Deming regression line can be added too.
plot.Meth Plots all methods against each other in a square matrix, both as a scatter
plot (below diagonal) and as a Bland-Altman plot (above diagonal).
to.wide Transforms a data frame in the long form to the wide form where separate
columns for each method are generated, with one row per (item,repl).
to.long Reverses the result of to.wide. The function can also generate a long form
dataset from a dataset with different methods beside each other.
summary.Meth Tabulates items by method and no. replicates for a Meth object.
Deming Performs Deming regression, i.e. regression with errors in both variables.
BA.est Estimates in the variance components models underlying the concept of limits
of agreement, and returns the bias and the variance components. The model used
assumes constant bias between methods.
8 1.2 Function overview
AltReg Estimates via alternating regressions in the general model. Returns estimates
of mean conversion parameters and variance components.
MCmcmc Estimates via BUGS in the general model with non-constant bias (and in the
future) possibly non-constant standard deviations of the variance components.
Produces a MCmcmc object, which is an mcmc.list object with some extra
attributes. mcmc.list objects are handeled by the coda package, so this is
required when calling MCmcmc.
post.MCmcmc Plots smoothed posterior densities for the estimates. Primarily of interest
for the variance components, but it has aruments to produce the posterior of the
intercepts and the slopes of the conversion lines between methods too.
check.MCmcmc Makes diagnistic plots of the traces of the chains included in the MCmcmc
object.
Chapter 2
Worked examples
> str(vis)
> summary(vis)
9
10 2.1 Fat measurements: Exchangeable replicates
●
●
●●
●
6 ●● ●
●● ●
●
● ● ●
●● ●
●
● ● ● ●
5
● ● ●
● ●● ●
● ● ● ●
● ● ● ● ●
● ●
●
SL
●● ●●●
● ●● ● ●
● ●● ●
●
4
● ●● ●● ●
● ● ● ● ●
● ● ●
● ● ● ●●
● ●
● ●
● ●● ●●●
● ● ● ●
● ●
3
● ●
●● ●●●● ● ●
● ●
●
●
●
●
2
2 3 4 5 6
#Replicates
Method 3 #Items #Obs: 258 Values: min med max
KL 43 43 129 2.0 3.9 6.5
SL 43 43 129 2.3 4.1 6.7
The two methods plotted against each other requires that we use the replicate
number for pairing the measurements; so we just keep the ordering among the replicates
when using to.wide:
> pw <- to.wide( vis )
Note:
Replicate measurements are taken as separate items!
Since replicates are exchangeable witin (method, item) we should get the same sort of
overview of the data after a random permutation of the replicates. Plotting the data
using the original replicate numbers for pairing and then a random permutation is
shown in figure 2.2:
> plot( vis )
The MethComp package. 11
2 3 4 5 6 2 3 4 5 6
2 2
●
●● ●
●
● 1 ●
●
●
● 1
●●● ● ● ●● ● ● ●
● ●● ●● ● ● ● ● ●● ● ● ● ● ● ●
●● ●●● ● ● ● ● ● ● ● ● ●
● ● ● ● ●● ●● ● ● ● ●● ● ●● ● ●
● ● ● ● ● ● ●● ● ● ●● ●
● ● ● ● ● ●●● ●● ● ● ● ●● ● ● ● ● ● ● ●●● ●● ● ●● ●
KL ● ●
●
●●
●● ● ●
● ● ●● ●
● ●
● ●
●
● ●
●●
●
●●
● ●
● ● ●
●● ●●●
● ●●
●
●
●
●
●
●● ●
●
●
● ●
●
●
● 0 KL ● ● ●●
● ●
●
● ● ●
●
●
● ●
●●●●
●
● ●
●●
●● ●●●
●
●
●● ●●
● ●
●
● ●
● ●
●
●
●
●●
●
● 0
● ● ● ●●
●
● ●
−1 −1
−2 −2
● ●
● ●
●● ●
● ●
● ●
6 ●●
●● ●
●
6 ● ●
●● ●
●
● ●
● ● ● ● ● ●
●● ● ● ● ●
● ●
● ●
5 ● ● ●
● ●
● ●● ●
●
● 5 ● ●● ●
●● ● ●
● ●● ● ●
● ● ● ● ● ●●● ●
● ● ● ● ● ● ● ● ● ●
SL SL
● ● ● ●
● ●
●● ●●● ●● ●●
● ●● ● ● ● ● ● ●
● ●● ● ● ●● ●
4 ●
● ●
●● ●●
●
● ●
●
●
4 ●
● ●● ● ●● ●
● ● ● ● ●
● ● ● ● ● ● ●●●
● ● ● ●● ● ● ● ●
● ● ● ●
● ● ● ●
● ●● ●●● ● ● ●●
●
● ● ● ● ● ● ●
3 ●
●● ●●●●
● ●
●
● ● ●
3 ●
●● ● ●●
●●
●
●
● ● ●●
●
● ● ● ●
● ●
● ●
● ●
● ●
2 2
2 3 4 5 6 2 3 4 5 6
Figure 2.2: Plot of two methods of measuring visceral fat, using different pairings of the
replicates; the left panel is using the pairing in the original coding, the right panel is with
a random permutation of replicates.
Note:
Replicate measurements are taken as separate items!
Note:
Replicate measurements are taken as separate items!
These two plots are shown in figure 2.2 where it is pretty clar that the random
permutation of replicates has little effect.
BA.plot produces a Bland-Altman plot and computes the limits of agreement using
the pairing of replicates across methods based on the numbering of replicates. However
we do not want the replicates to be connected, so we must specify this explicitly:
> par( mar=c(3,3,3,3), mgp=c(3,1,0)/1.6 )
> BA.plot( vis, conn.repl=FALSE )
Limits of agreement:
SL - KL 2.5% limit 97.5% limit SD(diff)
0.1550388 -0.5612718 0.8713493 0.3581553
We see that using this approximation we get limits of agreement for KL−SL of
(−0.86, 0.55).
Moreover, there seems to be no indication that the difference between observers or
the variance varies with the level of measurement. This can be a bit more formally
tested using the DA.reg function (again using the existing pairing of replicates):
> DA.reg( vis )
12 2.1 Fat measurements: Exchangeable replicates
1.0
●
● ●
0.87
●● ●
●●● ● ●
● ●● ●● ● ● ●
0.5
●● ●●● ● ●
● ● ● ● ●● ●●
● ● ● ● ●
SL − KL
● ● ● ● ● ●●● ●● ● ● ● ●● ●
0.16
● ● ●● ● ● ●● ●●● ●● ● ●
0.0
● ● ●● ● ●
●● ● ● ●● ● ●● ●
● ● ●● ● ●
● ● ● ● ● ● ●
● ● ● ● ● ● ● ● ●
−0.5
●
−0.56
3 4 5 6
( SL + KL ) / 2
From the last two columns (p-values for tests of constant difference and constant sd.) it
is clear that there are no obvious violations of the assumptions about constant difference
or about constant variation across the range of measurements.
Setting up a proper variance component model we get only slightly different limits of
agreement (note that we must specify the replicates to be exchangeable):
> ( vis.est <- BA.est( vis, linked=FALSE ) )
1.0
●
● ●
0.87
●● ●
●●● ● ●
● ●● ●● ● ● ●
0.5
●● ●●● ● ●
● ● ● ● ●● ●●
● ● ● ● ●
SL − KL
● ● ● ● ● ●●● ●● ● ● ● ●● ●
0.16
● ● ●● ● ● ●● ●●● ●● ● ●
0.0
● ● ●● ● ●
●● ● ● ●● ● ●● ●
● ● ●● ● ●
● ● ● ● ● ● ●
● ● ● ● ● ● ● ● ●
−0.5
−0.56
●
3 4 5 6
( SL + KL ) / 2
Figure 2.4: Bland-Altman-plot of two methods of measuring visceral fat, using different
pairings of the replicates. The blue lines are the LoA based on taking the paired replicates
as items, the red lines are based on the estimates from the proper variance component
model.
KL 0 0.181 0.193
SL 0 0.181 0.173
Moreover we get the coefficient of reproducibility for each of the methods; that is an
upper 95% confidence interval for the absolute difference between two measurements by
the same method on the same
We can visualize the difference between the ad-hoc-computed LoA and the model
based ones by plotting them in the same graph:
> par( mar=c(3,3,1,3), mgp=c(3,1,0)/1.6 )
> BA.plot( vis, conn.repl=FALSE )
Limits of agreement:
SL - KL 2.5% limit 97.5% limit SD(diff)
0.1550388 -0.5612718 0.8713493 0.3581553
As predicted by the theory, the limits based on the ad-hoc paired replicates are roughly
equal to those derived from the proper variance component model — see figure 2.4.
14 2.2 Cardiac output: Linked replicates?
1.0
●
● ●
0.87
● ● ●
0.75
● ● ● ● ● ●
●
●
● ● ● ● ● ● ● ●
● ●
●
0.5
● ● ● ● ● ● ● ●
●
● ● ● ● ● ● ● ● ●
● ● ●
● ● ●
● ● ● ● ● ●
●
● ●● ● ●
● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ● ●
0.16
SL − KL
● ● ● ● ● ● ●●
● ● ● ● ● ● ● ●
●
0.0
● ● ● ●●
● ● ●
● ● ●
● ● ● ●
● ● ●
● ● ● ● ● ● ● ●
●
●
● ● ● ● ● ● ● ●
●
●
● ● ● ● ● ● ●
●
● ● ● ● ● ● ● ● ●
−0.44
−0.5
●
−0.56
●
−1.0
2 3 4 5 6 7
( SL + KL ) / 2
Figure 2.5: Bland-Altman-plot of two methods of measuring visceral fat, based on the
arbitrary pairing of the replicates (black) and on the mean over replicates (grey).
In order to illustrate the effect of basing the limits of agreement on the mean over the
replicates we use the argument mean.repl, and the trick of using par(new=T) to over
plot:
> par( mar=c(3,3,1,3), mgp=c(3,1,0)/1.6 )
> BA.plot(vis,mean.repl=T,limy=c(-1,1),limx=c(2,7),col=gray(0.7),col.lines=gray(0.5), conn.repl=FALS
Limits of agreement:
SL - KL 2.5% limit 97.5% limit SD(diff)
0.1550388 -0.4371295 0.7472070 0.2960841
> par(new=T)
> BA.plot(vis,mean.repl=F,limy=c(-1,1),limx=c(2,7),cex=0.7,conn.repl=FALSE)
Limits of agreement:
SL - KL 2.5% limit 97.5% limit SD(diff)
0.1550388 -0.5612718 0.8713493 0.3581553
It is not clear from the description of the dataset whether replicates are linked across
methods or not, but a quick check can be made graphically by making a Bland-Altman
plot on the data as supplied and on the dat where replicates are randomly permuted,
and then compare them as in figure 2.2.
> par( mfrow=c(1,2), mar=c(3,3,1,3), mgp=c(3,1,0)/1.6 )
> BA.plot( cardiac , limy=c(-3,3) )
Limits of agreement:
RV - IC 2.5% limit 97.5% limit SD(diff)
0.6021667 -1.3199476 2.5242809 0.9610571
> BA.plot( perm.repl(cardiac), limy=c(-3,3) )
Limits of agreement:
RV - IC 2.5% limit 97.5% limit SD(diff)
0.6021667 -1.3471230 2.5514563 0.9746448
A slightly more formal handle can be obtained by fitting models assuming constant
difference between methods. The models are fitted, one with an item(=person) by
replicate effect, and one without:
> BA.est( cardiac, linked=TRUE )
Conversion between methods:
alpha beta sd LoA: lower upper
To: From:
IC IC 0.000 1.000 0.449 -0.898 0.898
RV -0.705 1.000 1.022 -2.748 1.339
RV IC 0.705 1.000 1.022 -1.339 2.748
RV 0.000 1.000 0.374 -0.749 0.749
●
3
3
●
● ● 2.52 ●
2.58
● ● ●
● ● ● ●
2
2
●
● ●
● ● ● ●
● ● ● ●
● ● ● ●
● ●
● ●● ● ●
● ● ● ● ●
1
1
● ● ● ● ●
● ● ●
●●
● ● ● ●●
● ●
●
●
● ●
● ● 0.60 ● ● ● ● ● 0.60
● ● ●
RV − IC
RV − IC
● ● ● ●
●● ● ● ●● ● ●● ● ●
● ● ●
0
0
●
● ● ●
●● ● ● ● ● ● ●
● ● ●
●
● ● ● ●
● ●
● ● ●
●
−1
−1
● ●
●
−1.32 ●
−1.37
●
−2
−2
−3
−3
3 4 5 6 7 3 4 5 6 7
( RV + IC ) / 2 ( RV + IC ) / 2
Figure 2.6: Bland-Altman plots of the cardiac data. The left panel is the orginal data
using replicate numbers to pair mesurements, the right is using a random permutation of
replicates for the pairing. Even if replicates are claimed to be linked, the replicates the
LoA in the right panel are not substantially wider.
We see that there is a some variation between replicates, which we would not expect to
see if replicates were exchangeable. In the model where we (erroneously) assume
replicates to be exchangeable, we see that it is the residual variances that gets inflated.
We can check the assumptions about constant bias and constant variance across the
range of measurements by fitting a straight line to the differences as function of the
averages (using the given linking of replicates). Note that the argument reg.line=3 gives
printed output and graph annotation of the relationship between methods with three
digits after the decimal point:
> BA.card <- BA.plot( cardiac, limy=c(-2,4), reg.line=3 )
Limits of agreement:
RV - IC 2.5% limit 97.5% limit SD(diff)
0.6021667 -1.3199476 2.5242809 0.9610571
The MethComp package. 17
● ●
● ●
2
●
●
● ● ●
● ●
RV − IC
● ●
●
● ●●
● ●
1
●
● ●
●●● ● ●
●
● ● ●
● ●
● ●
●● ● ● ●● ● ●●
0
● ● ●● ● ●
● ●
●
●
●●
−1
● ●
●
3 4 5 6 7
( RV + IC ) / 2
Figure 2.7: Bland-Altman plot of the cardiac data with a fitted regression line.
There is a some indication that the variance is not constant, but seen from the figure
it does not seem alarming, it presumbaly hinges on the 6 points to the far left of the
plot. An informal test of this can be obtained by using the function DA.reg, which
regresses the Differences between methods on the Averages, and additionally regresses the
18 2.2 Cardiac output: Linked replicates?
absolute values of the residuals from this analysis on the averages, so as to give an
indication as to whether the residual standard deviation depends linearly on the mean:
> DA.reg( cardiac )
If we fit a variance component model using BA.est as before, we can explore what effect
it has on the repeatability (the prediction of a method from itself) if we include the
variation between replicates or not:
> BA.est( cardiac, linked=TRUE, IxR.pr=FALSE )
The former is for the situation where we consider the variation between replicate
measurements as a part of the repeatability conditions (even if the replicates are linked),
the latter where we consider the variation between replicates to be irrelevant to the
assessment of repeatability. However there is not much indication of linked estimates,
since the other two variance components are virtually unchanged between the two
analyses, and hence the predictions between methods based on the two approaches will
be the same.
The MethComp package. 19
> str(sbp)
Note:
Replicate measurements are taken as separate items!
The resulting plot is shown in figure 2.8, clearly shows that the two manual
measurements are in much closer agreement than any of them are with the automatic.
plot.Meth pairs replicates according to their numbering and treat them as separate
items, so the plots fail to take the dependence of observations nto account.
We want to restrict our attention to the comparison of the two manual methods, but
using the replicate measurements.
In this context it is important that we recognize whether the replicates are linked
across the two methods or not. In this case they are, i.e. replicates are not exchangeable
within methods and items.
> par( mar=c(3,3,3,3), mgp=c(3,1,0)/1.6 )
> sbp <- subset( sbp, meth %in% c("J","R") )
> str( sbp )
Limits of agreement:
R - J 2.5% limit 97.5% limit SD(diff)
-0.08627451 -4.60761840 4.43506938 2.26067194
20 2.3 Systolic blood pressure: Linked replicates by two methods
Limits of agreement:
R - J 2.5% limit 97.5% limit SD(diff)
-0.08627451 -4.60761840 4.43506938 2.26067194
Since we only have two methods, we cannot identify separate variance components τ1
and τ2 , so we are forced to assume that τ1 = τ2 , hence the use of pdIdent and not
pdDiag in the specification of the matrix effects (i.e. the method by item interactions).
The model above is fitted to the dataset by:
●● ●
●
100 150 200 100 150 ● 200
●
●●
●
●
● ●
●● ●●
50
● ●
●
●● ● ●
● ●●●● ● ●
● ● ● ●●
● ●● ● ●● ●● ●
● ●
●
●● ● ●●● ● ●
●●●
●
● ● ● ●●● ●
● ●●
●
●
●●
● ●
●● ●
●● ●
● ●
● ●● ●● ● ●● ●
●●● ● ●●●●●● ●● ● ●● ● ● ●
● ● ● ●●● ●●●
●● ●
●
●
●●
● ●● ●●●●● ●●● ● ●
● ● ● ●● ●●●●
●●
●●● ●● ● ● ●● ● ● ● ●
● ●●● ● ●●●● ●● ● ●●● ●● ●● ●
●
J ● ●
● ●●
●
●
●●
●●●
● ●●
● ●●●
●
●
●
●
●
●●
●●
●
●●
● ●
●
●●
●●●●●●●
●
●
●● ●●●
●
●●
●●
●●
●
●
●
●●
●
● ●●●●●
●
●
●
●
●●
●●
●●●
●●
●●
●
●
●●
●
●
●
●●
●●
●
●
●
●
●● ●● ●● ●●●
●●
●
● ●
●●● ●
●●●●●
●● ●
●● ●●
●●
●
● ●● ● ●
●
● ● ●
●
●●
●●●●●● ●● ● ● ●●●
●●
●● ●●●
●
● ●●
● ●● ● ● ●●
●
● ●● ●
●
● ●
● ●
●
●
● ●
●
● ● ●
●
● 0
●
●
●
●
−50
●
●
●
●
●●
●
●● ●
●● ●
●●
● ●
200 ●●●
● ●●
●
50
●
●● ●
●● ● ●
●● ● ● ●● ● ●
● ● ● ● ● ● ● ●
●● ●● ●
●● ● ● ●● ●●●●● ● ●● ● ●●
●●●● ● ●● ●● ● ●
● ●
● ●● ●● ●
● ●
●●
●● ●●●● ● ● ●● ●
● ●● ● ●
●● ●●● ●●
●●
●●
● ●
●
●●●●●●
● ●● ●● ●
●●●● ● ● ●● ●
●●●● ●●● ●
● ● ●●●
●●
●●●
●●
●●●●●
●
●● ● ●
●●●●
● ●●●
● ●● ● ● ●
● ● ● ●● ●●● ●
●
●● ● ●●● ● ●● ●
●
R
●●
● ●● ●
● ● ● ●● ● ● ●●●● ● ●● ● ● ●● ● ●● ● ● ● ●● ● ●
150 ●●
●●
●●
●●● ● ●
●
●● ● ●
●● ● ●
● ● 0
●●●●
●●●● ● ● ●● ● ● ●●●
●●
● ● ● ●
●●●
●●●
●●● ● ●
● ● ●
● ● ●●
●● ●
●
●●●●
●●
●●
●●●
●● ● ●●
● ●
●
●●
●●●●
●
●●
●●●●●
●●
●●
●●
100 ●●
●●
●●●●●●●● −50
● ●●
●
●●●
●●
●●●
●●
●● ● ●●
● ● ●● ● ●●
● ●
● ●
● ● ● ● ● ●
● ● ● ●
● ● ● ●
● ● ● ● ● ●
200 ● ●
●●
● ● ●
●●
●
●● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ●
● ● ● ● ● ●
● ● ● ● ● ●
● ● ●●● ●● ● ●● ● ●● ●
● ● ● ● ● ●
●● ● ● ●
● ● ● ● ●● ● ● ● ● ● ●
● ● ● ●●● ● ● ● ● ● ●●● ● ●
● ● ● ●●● ●●●●● ●● ●●
●
S
● ●●●●●● ●●● ● ●
● ●
●
● ● ●● ● ●
150 ●● ●● ●● ● ● ● ●● ● ● ●●
●
●
●●●
●● ● ● ●
●● ●●● ●●●●● ● ●●
● ● ● ●● ●●
● ●● ● ●●
● ● ● ● ●●
●●
●
●●● ●● ●
●
● ●● ●● ●
● ● ●● ●● ● ● ●●● ●● ●
● ●● ● ●● ● ●
●●●●●● ●●●● ●● ●
●●●●
● ●● ●
●●
● ●●
●
●● ●● ● ● ●●●●
●
● ● ●● ●●●●
● ●●● ●● ● ●
● ●●
● ●●
● ●●●● ●●●● ● ●
●●●● ● ●
● ●●●
●
●
●●
●●
●
●
●● ● ● ● ● ●● ●●
● ●
●●● ●●●
●●● ●
●● ●
●●
● ●●
●●● ● ●
●●●●
●●● ●● ●
●
● ●● ● ● ●
●●●●
●● ●● ●●●●●●● ●
●● ● ●● ●●●● ●
●●● ● ● ●
●●●
● ●●●●
● ●● ● ●● ● ● ●● ● ● ● ●
100 ● ●●
●
●● ● ●
●● ●
●
●● ● ●
●●
● ● ● ● ● ●
● ●
Figure 2.8: Graphical overview of the sbp data. The methods J and R are two human
observers, whereas method S is an automatic device.
The MethComp package. 21
●
15
●
10
● ●
5
●
● ● ●● ● ● ●
4.44
●
5
● ●● ● ●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●● ●●● ● ● ●● ●●
0
−0.09
R−J
● ● ● ● ● ●
−4.61
−5
● ● ● ● ● ●
●
−4.61
−5
●
●
−10
● ● ●
−10
−15
● ●
100 150 200
Figure 2.9: Bland-Altman plot of the sbp data. Replicates are linked between methods,
so the single replicates in the data has been used as single measurements when doing the
Bland-Altman plot. Measurements from the same person are joined by thin lines. The
only difference between the two plots is the scaling of the y-axis.
22 2.3 Systolic blood pressure: Linked replicates by two methods
Random effects:
Formula: ~meth - 1 | item
Structure: Multiple of an Identity
methJ methR
StdDev: 0.2483701 0.2483701
Variance function:
Structure: Different standard deviations per stratum
Formula: ~1 | meth
Parameter estimates:
J R
1.000000 1.122211
Number of Observations: 510
Number of Groups:
item repl %in% item
85 255
Now, the output from lme is pretty difficult to read, but the residual standard deviations
are σJ = 1.485870 and σR = 1.485870 × 1.122211 = 1.6674599, whereas τ = 0.2483701
(largely negligible) and ω = 5.932962, by far the largest variance component. Also from
the output we get the difference between methods R and J to be −0.08627451.
An easier way to get the relevant estimates is to use the wrapper BA.est, where the
only necessary specification is the dataset (assuming that columns meth, item, repl and
y are present) and whether replicates are linked across methods:
> BA.est( sbp, linked=TRUE )
Which is identical to the quantities we fished out of the lme output. Actually BA.est fits
exactly the model we fitted, and then extracts the quantities that we are interested in.
The limits of agreement
√ between the two manual observers is then for R−J
−0.0863 ± 1.96 × 2 × 0.2482 + 1.4862 + 1.6672 = (−4.51, 4.34), i.e. on average they
agree, but in order to be sure to enclose 95% of all differences we need an interval
approximately as 0 ± 4.5 mmHg.
The MethComp package. 23
One way of seeing the lack of exchangeability is to make the overview plot using a
random permuation of the replicates. If replicates were truely exchangeable within
methods the plot would look similar when permuting the replicates — and it does not!
For completeness we reload the data to get observations by all three methods
included, and then make overview plots after random permutation of replicates within
(method,item):
> data(sbp)
> sbp <- Meth( sbp )
> str(sbp)
Note:
Replicate measurements are taken as separate items!
The substantial item by replicate interaction (IR) clearly indicates that replicates are
linked between methods.
The resulting estimates from this model gives limits of agreement for R−J based on
the method by item and the residual variances:
√
−0.0863±1.96× 0.33852 + 0.00112 + 1.63012 + 1.54672 = −0.0863±4.4540 = (−4.54, 4.37)
which is in agreement with the limits computed based on the simplistic way of taking
replicates as items — a procedure wich is actually close to correct if replicates are linked.
Alternatively this could be formulated as a 95% prediction interval for R given a
measurement by J, yJ , which would be
The above analysis is based on the correct analysis of the entire dataset, including
the information from the machine measurement S. If we fit the model on the restricted
dataset, we of course get a common method by item interaction term because we then
only have two methods:
> BA.est( subset( sbp, meth!="S" ), linked=TRUE )
●● ●
● ● ●
●
100 150 200 100 150 ● 200 100 150 200 100 150 ● ● 200
● ●
●
●● ●
●
●
●
● ● ●
● ●●●
●● ●●
50 50
● ● ●
● ● ● ●
● ● ●
●● ● ● ●●
● ●
● ●●●● ● ● ●
●
● ●● ●●● ●
● ● ● ●● ● ● ●●● ●● ● ●
● ●● ● ●● ●● ● ● ● ● ●●● ● ● ● ●
●● ● ●●● ● ● ● ● ● ● ●●● ● ● ● ●● ●●
● ● ● ●●● ●
● ●●●
●●●●
● ● ●● ● ● ●● ●● ● ●● ● ● ● ●
● ●●●
● ●●
●
●●●●
●●
●
●●
●
●
●
●●● ● ●●● ●
● ●
● ● ● ●
●●● ● ● ● ●● ●●
●●●●● ●● ● ●● ● ● ● ● ● ●●● ● ● ● ●
● ● ● ●●● ●●
●● ●●
● ● ● ● ● ●● ● ● ●● ● ● ● ● ● ● ●
● ●●●●
●●●●●● ●
●
● ●●
●●●
●●● ●● ● ●
● ●●●
● ●● ●●●●● ●●● ●● ● ● ● ●●●●●● ● ●●● ● ●● ● ● ● ●
● ● ● ●● ●●
●●● ●●
●
●●
●
● ●●●
● ●● ● ● ●●
● ● ●●●●●● ●
●● ●
●
●
●
● ● ●●
●●●●● ●●● ●● ● ●
●● ● ● ● ● ●● ●●●●● ●
● ● ● ●● ●● ●
●
●● ● ● ●● ●● ● ●● ●
J ● ●
● ●●
●
●
●●
● ●●
●
●●●●●●
●
●
●
●
●
●●
●●
●
●
●
●
●
●
●
●● ●●●
●
●
●●●●●●●
●
●●
●●
●●
●
●
●
●●
●
● ●●●●●
●
●
●
●
●●
●●
●●●
●●
●
●
●
●●●
●
●
●
●●
●●
●●
●
●● ●● ●● ●●●
●
●●
● ●●● ●
●
● ●
●●●●●
●● ●
●● ●●
●●
●
● ●● ●
●● ● ●
● ●
●
●
●●
●●●●●● ●● ● ● ●●●
●●
●● ●●●
●
● ●●
● ●● ● ● ●●
● ●● ●
●
● ●
● ●
●
●
●
● ●
●
● ● 0 J ●
● ●
●
●●
● ●
● ●
●
●●
● ●●
●
●● ●
●
●
●
●
●
●
●●
●●
●
●
●
●
●
●
●
●
●
●
●
●
●
●●
●
●●
●
●
●
●
● ●●
●●●
●
●
● ● ●● ●
●
●
●
●
●
●
●
●● ●
●
●●
●●● ●●●
●
●
●
●
●
●
●
●
●●●● ●
●●
●
●● ●
●
●● ●● ● ●
●●
●
●
●●● ● ●●
● ●● ●
● ● ● ● ●● ●
●
●● ●
● ●
●
●●
●
● ●
●
●● ●
● ●
●
● ● ●● ●●●
●
●
●● ●
●
●
●●● ●
●● ●● ● ●●
●● ●● ● ● ● ● ●●
● ●
● ●●
●
●● ●
● ●
●● ●
●
●
●●
●
●
0
● ● ● ● ●● ● ● ● ●
●
●
● ● ●
● ●
● ● ● ●
●
●
●
−50 ●
−50
● ●
● ● ●●
●
●
●
●● ●
●
● ● ●
●● ● ●● ●
●● ● ●
●●
● ● ●● ● ●
200 ●●●
● ●●
●
50 200 ●●● ● ● ● 50
● ● ● ●
●● ●
●● ● ● ● ● ●
● ●
●●● ●● ●
●● ● ● ●● ● ● ● ●
● ● ●
● ● ● ● ● ● ●
●
● ● ●● ● ● ●● ●
●● ●● ● ● ● ● ● ● ●● ●
● ● ● ●●
●● ● ● ●● ●●●●●● ● ●● ●● ● ●● ● ●● ●●● ●● ●● ●● ●
● ●● ●● ●
●●●● ● ●● ●● ● ●●●●●
●●
●● ●
●● ● ● ●● ● ● ● ● ● ● ●● ● ●
● ●● ●
● ● ●
●
●●
● ●●
● ●●● ●
●●●
●● ●●● ●●●●●●
● ●●● ●● ●●● ● ● ● ●● ● ● ● ●● ● ●● ● ●●
● ●●
● ●
● ●
●● ●●● ● ● ● ● ●
● ●●● ● ●● ●●● ● ● ●●
● ● ● ●●● ●
●●●●
●
●
● ●●●
●
●
●
●
●●●●
●
●●
●
●
●●●
●●
●
● ●●●
● ●
●
●
●●●●●
● ●● ● ● ● ●●● ●
● ● ● ●
●
●●
●●
●
●
●●
●●
●●
● ●● ●●● ●
● ●
●
●●
●● ●
●● ● ●
●●● ● ● ●● ●● ●
● ● ●● ●●●● ●● ●●● ● ●● ●
● ●
●●● ●
● ● ●
●●●●●● ● ●
● ●
● ● ● ● ● ● ● ●
●
R R
●● ● ●● ●●●
●● ●●● ● ●
●●●● ● ●● ● ● ●●●● ● ●
● ● ●● ● ●●
● ● ● ● ● ●● ● ● ● ●●● ● ●● ● ● ● ●●● ● ●
150 ●
●●
●● ●
●● ● ●
●
●●
●● ●
●
●
● ● 0 150 ●
●●
●●
●
● ●●
●
● ●
● ● ● ●●●
●
● ●
●●
●● ● ●
● ● ●● 0
●●
●● ● ● ●● ● ● ●● ● ●●●
●●
● ● ● ●●
●●●●
●● ●
●
● ● ●●● ● ● ● ●● ● ●●
●
●●
●●●●
● ● ● ● ● ● ●●● ●● ●● ● ●
●● ● ●
● ● ●
●
● ● ●●●
●● ● ● ●●● ●● ● ● ●● ● ●
● ●
●●●●
●● ●● ●
● ● ●●●
●●● ●●●● ●
●●
●●● ● ●●●
●●●
●●
●● ●
●● ●
●●●● ●
●●●● ●●
●●
●●●●●
●● ● ●●●● ● ●●●●
●●● ● ●
●
●● ●●
●
●●●
●●● ●●
●●●●
●●●● ● ●
●●● ●●
●●●●●●
100 ●●●●
●
●●
●●
●●●● −50 100 ●●
●●
● ●● ●●
●● ●●● ●
●● ●
●●●● −50
● ●●● ● ●● ● ● ●
●●●
● ● ●●●●
●●● ●
●● ●● ● ●
●● ● ●●
● ● ●● ● ●●
● ● ●● ● ●●
● ●● ● ●●
●
● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ●● ●
● ● ● ● ● ● ● ●
● ● ● ● ● ● ● ●
● ● ● ● ● ● ● ● ● ● ● ●
200 ● ●
●●
● ● ●
●●
●
200 ● ●
●●
● ●
●
●
●●
●
●● ● ● ● ●● ● ● ● ● ● ●● ● ● ● ● ● ● ● ●
● ● ● ● ● ●●
● ● ● ● ● ● ●● ●● ● ● ● ● ●● ● ●
● ● ● ● ● ● ● ● ● ● ●●
● ● ●●● ●● ● ●● ● ●● ● ●● ●
● ●
●● ● ● ● ●●
● ●
● ● ● ● ● ● ● ● ● ●●
●● ● ● ● ●●
● ● ● ●●
● ● ● ● ●● ● ● ● ● ● ● ● ● ● ● ● ● ●● ● ●● ●
● ● ●●● ● ● ●●● ● ● ●● ● ● ● ●●●
● ● ●● ● ● ● ● ●● ● ● ● ●● ●● ● ● ● ●● ●
S S
● ●●● ●●● ● ● ●●● ●● ● ●●● ● ●●●●
●
●●●
● ● ● ● ●●●●
● ● ● ●● ● ● ●● ●
●●● ● ● ●● ●●
●●
● ●●
150 ●● ●● ●● ● ● ● ●● ● ● ●●
●● 150 ●
●● ●● ● ● ●●●
●
● ●
●● ● ● ● ● ● ●●
● ●
●●●
●● ● ● ●
●● ●●● ●●●●● ● ● ● ● ● ● ●● ● ●● ● ● ●● ● ●
●
● ● ● ● ● ● ●
●● ●● ● ●● ● ● ●● ● ●●●●● ●●● ●
●
●●
● ● ●
●●● ● ●● ● ●
●
● ● ● ●
●●●●● ●
●● ●
● ●● ●● ●
● ● ●● ●● ● ● ●●● ●● ●
● ●● ● ●● ● ● ● ●●●●● ● ●● ● ● ● ●
●● ● ●●●●●
●
● ●● ●
● ● ● ●
●●●●●● ●
●●
● ●●
●
●● ●
●●●●
●●
●●●
●●
●●
●
●
●● ● ● ●
●●● ● ●
●●● ● ●
● ● ●● ●
●●●●
● ● ●
● ● ● ●●
●
●
● ● ●●
●●
●●
●●●●
● ●●● ●● ● ●●
● ●●●
● ●●●● ●●●● ● ● ●●
●●
●●●●
● ●● ● ● ●
●●●●
●●
●●
●●●●
●● ● ● ●●
● ●●●
● ●
● ● ●● ●
●●●●●●●
● ● ● ● ● ●● ●●
●● ●● ●●● ● ● ●● ●● ●●●●●●●
●
●●
●●
●● ● ● ● ● ● ●●● ●●●
●●● ● ●●●●
●
● ● ●● ● ● ●●●
●● ● ●
●● ●●● ●
●
●● ●
●● ●●● ●
● ●●
●●● ●● ● ●●
● ●●●● ● ●●●
●
●●●●
●●
●●● ●●● ●
● ●● ●●● ● ● ● ●●●●
● ●● ●● ●●● ● ●
●● ● ● ●●●
●
●● ●● ●●●●●●● ●
● ● ●● ●●●●
●●●●●● ● ● ● ● ● ●● ● ● ●●●● ● ● ● ●● ●●● ● ● ●
●●●
● ●●
● ● ● ●●● ●● ● ●●
● ●● ● ●● ● ● ●● ● ● ● ● ● ● ● ●●● ● ● ●● ● ●● ● ●
100 ● ●●
●
●● ● ●
●● ●
●
●● ● ●
●●
100 ● ● ●
●
●● ●● ● ● ●
● ●● ●
●●
●
● ● ● ● ● ● ● ● ● ● ● ●
● ● ● ●
100 150 200 100 150 200 100 150 200 100 150 200
Figure 2.10: Graphical overview of the sbp data; the left panel with the original replicate
numbers used for matching; the other with replicates permuted randomly within methods.
The MethComp package. 25
Based on these estimates we get the limits of agreement for R−J to be:
√
−0.0863 ± 1.96 × 2 × 0.24842 + 1.48592 + 1.66742 = 0.0863 ± 4.4313 = (−4.52, 4.35)
i.e. effectively the same as before, based on all three methods. Again these limits are
those computed by BA.est.
Bibliography
26