2

Can someone help me on this? I would like to make a Bland-Altman plot using R, for 2 columns of my data, the columns are forearm and forearm2 in the data below, but I have no idea how.

>data_2
      Sex Forearm Height Age  Forearm2
1    Male  17    182     55      26
2    Male  18    185    103      28
3    Male  20    171     49      25
4    Male  18    176     58      25
5    Male  21    158     57      23
6  Female  21    155     43      25
7    Male  18    199    114      29
8    Male  19    176     90      25
9    Male  17    191     68      29
10   Male  23    176     52      25
11 Female  19    153     34      24
12 Female  19    160     56      26
13   Male  19    170     47      25
14   Male  22    178     62      25
15 Female  21    174     49      27
16   Male  22    162     40      24
17 Female  23    172     82      27
18 Female  19    185     99      28
19 Female  18    168     66      25
20 Female  17    155     45      24
21   Male  17    182     83      27
22 Female  17    164     42      25
23 Female  18    162     73      26
24   Male  18    185     68      28
25 Female  18    146     50      23
26 Female  23    169     47      25
27 Female  18    160     51      24
28 Female  18    170     69      25
29   Male  24    185     57      27
30   Male  24    167     46      24
31 Female  25    169     47      26
32 Female  24    164     50      25
33 Female  21    155     47     235
34 Female  24    158     37      24
35 Female  23    177     88      27
36 Female  23    155     36      24
37   Male  19    170     47      24
38 Female  21    170     48      26
39 Female  23    160     74      25
40   Male  21    180    100      26
41   Male  19    186     95      27
42   Male  21    181     65      26

I have tried to go about it several times using approaches that I find on the internet(wikipedia) but I don't know where am going wrong. Here is what I have done so far, but I keep getting the error message.

BAplot=function(data_2$forearm,data_2$forearm2){
  (data_2$forearm,data_2$forearm2,
   xlab="Mean size(mm)", 
   ylab="Difference(mm)",
   ylim=c(15,40), pch=42)
  abline(0,0)} 

Error: unexpected '$' in "BAplot=function(data_2$"
leech
  • 8,293
  • 7
  • 62
  • 78
user3136251
  • 567
  • 3
  • 7
  • 9
  • 3
    You have the same question [here](http://stackoverflow.com/q/20837805/1315767), and you haven't neither accepted nor up-voted the provided answer. Also you got nice answers to [this](http://stackoverflow.com/q/20801803/1315767) and [this](http://stackoverflow.com/q/20812129/1315767) and you haven't accepted any yet. – Jilber Urbina Dec 30 '13 at 14:32

1 Answers1

7

If you type Bland-Altman plot using R on google you'll find the 'MethComp' package and looking inside there is a function called BlandAltman which does exactly what you want.

> library(MethComp)
> with(df, BlandAltman(Forearm, Forearm2))
NOTE:
 'AB.plot' and 'BlandAltman' are deprecated,
 and likely to disappear in a not too distant future,
 use 'BA.plot' instead.

Limits of agreement:
Forearm - Forearm2         2.5% limit        97.5% limit           SD(diff) 
         -10.33333          -75.01517           54.34850           32.34092 

Note that BA.plot function already exists, pay attention to the NOTE. It'll produce the following plot:

enter image description here

Jilber Urbina
  • 58,147
  • 10
  • 114
  • 138