tag:blogger.com,1999:blog-1275149608391671670.post2523903449054764715..comments2023-09-28T06:13:40.704-04:00Comments on SAS and R: Example 9.34: Bland-Altman type plotKen Kleinmanhttp://www.blogger.com/profile/09525118721291529157noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-1275149608391671670.post-86875895026076642522018-07-31T13:57:43.399-04:002018-07-31T13:57:43.399-04:00Interesting idea, Anonymous. If I read your code ...Interesting idea, Anonymous. If I read your code correctly, you are forcing the y-axis to stop at 3 times the SD, plus or minus. <br /><br />There is a risk here that you will cut off any larger outliers-- they would not show on your plot, which I don't think was your intent.<br /><br />Instead, I think you had intended to avoid the appearance of the example plot, where roughly agreeing data might appear to be in disagreement.<br /><br />You might fix both problems with some comparison between the max deviation and the 3*sd, I think. But for myself, I'm happy with the standard limits.Ken Kleinmanhttps://www.blogger.com/profile/09525118721291529157noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-23636222766456902232018-06-29T11:40:58.411-04:002018-06-29T11:40:58.411-04:00Many Thanks Ken for the code.
Wouldn't it be...Many Thanks Ken for the code. <br /><br />Wouldn't it be more appropriate thought to expand the limit of the y-axis as follow: <br /><br />baplot = function(x,y){<br /> xstd = (x - mean(x))/sd(x)<br /> ystd = (y - mean(y))/sd(y)<br /> <br /> bamean = (xstd+ystd)/2<br /> badiff = (ystd-xstd)<br /> ylim_val = mean(badiff)+3*sd(badiff)<br /> <br /> plot(badiff~bamean, pch=20, xlab="mean", ylab="difference", ylim = c(-ylim_val,ylim_val))<br /># in the following, the deparse(substitute(varname)) is what retrieves the<br /># name of the argument as data<br /> title(main=paste("Bland-Altman plot of x and y\n",<br /> deparse(substitute(x)), "and", deparse(substitute(y)),<br /> "standardized"), adj=".5")<br /> <br />#construct the reference lines on the fly: no need to save the values in new <br /># variable names<br /> abline(h = c(mean(badiff), mean(badiff)+1.96 * sd(badiff),<br /> mean(badiff)-1.96 * sd(badiff)), lty=2)<br />} <br /><br />baplot(x,y)<br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-49327926058936962652012-06-06T19:53:54.460-04:002012-06-06T19:53:54.460-04:00Thanks, Chris! Quite right.Thanks, Chris! Quite right.Ken Kleinmanhttps://www.blogger.com/profile/09525118721291529157noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-29528349961867078522012-06-06T11:37:24.576-04:002012-06-06T11:37:24.576-04:00On the pedagogical side:
You took the time to de...On the pedagogical side: <br /><br />You took the time to demonstrate the deparse(substitute(varname)) functionality but then used the same variable names (x and y) to call the function. Thus the user might not see the effect. Readers might want to run the following code (after running all the previous R code):<br /><br />dxa <- x<br />bmi <- y<br />baplot(dxa, bmi)Chris Andrewshttps://www.blogger.com/profile/08124050587254722665noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-59535206462651329212012-06-06T08:15:18.358-04:002012-06-06T08:15:18.358-04:00Thanks. The scale() function is vectorized and pr...Thanks. The scale() function is vectorized and probably more efficient than simple code, both of which could make a difference in large data sets or repeated application.Ken Kleinmanhttps://www.blogger.com/profile/09525118721291529157noreply@blogger.comtag:blogger.com,1999:blog-1275149608391671670.post-86455892094543184672012-06-06T03:20:33.181-04:002012-06-06T03:20:33.181-04:00nice! Note you have a specific function to center/...nice! Note you have a specific function to center/standardise variable, scale(). So:<br />(x - mean(x))/sd(x)<br /><br />can be replaces by scale(x)Anonymousnoreply@blogger.com