From 74604cbecf4cbd80996cb2b5593fd7f23cbe7398 Mon Sep 17 00:00:00 2001 From: "Steven Paul Sanderson II, MPH" Date: Wed, 25 Oct 2023 08:26:03 -0400 Subject: [PATCH] new post --- .../index/execute-results/html.json | 16 + .../index/figure-html/unnamed-chunk-3-1.png | Bin 0 -> 13119 bytes docs/index.html | 484 +++++++------ docs/index.xml | 444 +++++++----- docs/listings.json | 1 + docs/posts/2023-10-25/index.html | 669 ++++++++++++++++++ .../figure-html/unnamed-chunk-3-1.png | Bin 0 -> 13119 bytes docs/search.json | 9 +- docs/sitemap.xml | 6 +- posts/2023-10-25/index.qmd | 82 +++ 10 files changed, 1302 insertions(+), 409 deletions(-) create mode 100644 _freeze/posts/2023-10-25/index/execute-results/html.json create mode 100644 _freeze/posts/2023-10-25/index/figure-html/unnamed-chunk-3-1.png create mode 100644 docs/posts/2023-10-25/index.html create mode 100644 docs/posts/2023-10-25/index_files/figure-html/unnamed-chunk-3-1.png create mode 100644 posts/2023-10-25/index.qmd diff --git a/_freeze/posts/2023-10-25/index/execute-results/html.json b/_freeze/posts/2023-10-25/index/execute-results/html.json new file mode 100644 index 00000000..a51f9f52 --- /dev/null +++ b/_freeze/posts/2023-10-25/index/execute-results/html.json @@ -0,0 +1,16 @@ +{ + "hash": "82416872553d5b88e2beed9b56456679", + "result": { + "markdown": "---\ntitle: \"What's a Bland-Altman Plot? In Base R\"\nauthor: \"Steven P. Sanderson II, MPH\"\ndate: \"2023-10-25\"\ncategories: [rtip, viz]\n---\n\n\n# Introduction\n\nBefore we dive into the code, let's briefly understand what a Bland-Altman plot is. It's a graphical method to visualize the agreement between two measurement techniques, often used in fields like medicine or any domain with comparative measurements. The plot displays the differences between two measurements (Y-axis) against their means (X-axis).\n\n# Step 1: Data Preparation\n\nStart by loading your data into R. In our example, we'll create some synthetic data for illustration purposes. You'd replace this with your real data.\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Creating example data\nmethod_A <- c(10, 12, 15, 18, 22, 25)\nmethod_B <- c(9.5, 11, 14, 18, 22, 24.5)\n\n# Calculate the differences and means\ndiff_values <- method_A - method_B\nmean_values <- (method_A + method_B) / 2\n\ndf <- data.frame(method_A, method_B, mean_values, diff_values)\n```\n:::\n\n\n# Step 2: Calculate Average Difference and CI\n\nNow that we have our data prepared, let's create the Bland-Altman plot.\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmean_diff <- mean(df$diff_values)\nmean_diff\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 0.5\n```\n:::\n\n```{.r .cell-code}\nlower <- mean_diff - 1.96 * sd(df$diff_values)\nupper <- mean_diff + 1.96 * sd(df$diff_values)\n\nlower\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] -0.3765386\n```\n:::\n\n```{.r .cell-code}\nupper\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n[1] 1.376539\n```\n:::\n:::\n\n\n# Step 3: Creating the Bland-Altman Plot\n\nWe are going to do this in base R.\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Create a scatter plot\nplot(df$mean_values, df$diff_values, \n xlab = \"Mean of Methods A and B\",\n ylab = \"Difference (Method A - Method B)\",\n main = \"Bland-Altman Plot\",\n ylim = c(lower + (lower * .1), upper * 1.1))\n\n# Add a horizontal line at the mean difference\nabline(h = mean(diff_values), col = \"red\", lty = 2)\n\n# Add Confidence Intervals\nabline(h = upper, col = \"blue\", lty = 2)\nabline(h = lower, col = \"blue\", lty = 2)\n```\n\n::: {.cell-output-display}\n![](index_files/figure-html/unnamed-chunk-3-1.png){width=672}\n:::\n:::\n\n\nThis code will generate a simple Bland-Altman plot, and here's what each part does:\n\n- `plot()`: Creates the scatter plot with means on the X-axis and differences on the Y-axis.\n- `abline(h = mean(diff_values), col = \"red\", lty = 2)`: Adds a red dashed line at the mean difference.\n- `abline(h = upper, col = \"green\", lty = 2)`: Adds blue dashed lines representing the 95% limits of agreement.\n\n# Step 4: Interpretation\n\nNow that you've generated your Bland-Altman plot, let's interpret it:\n\n- The red line represents the mean difference between the two methods.\n- The blue dashed lines show the 95% limits of agreement, which help you assess the spread of the differences.\n\nIf most data points fall within the blue lines, it indicates good agreement between the two methods. If data points are scattered widely outside the lines, there may be a systematic bias or inconsistency between the methods.\n\n# Step 5: Exploration\n\nI encourage you to try this out with your own data. Replace the example data with your measurements and see what insights your Bland-Altman plot reveals.\n\nIn conclusion, creating a Bland-Altman plot in R is a valuable technique to visualize agreement or bias between two measurement methods. It's an essential tool for quality control and validation in various fields. I hope this step-by-step guide helps you get started. Happy plotting!", + "supporting": [ + "index_files" + ], + "filters": [ + "rmarkdown/pagebreak.lua" + ], + "includes": {}, + "engineDependencies": {}, + "preserve": {}, + "postProcess": true + } +} \ No newline at end of file diff --git a/_freeze/posts/2023-10-25/index/figure-html/unnamed-chunk-3-1.png b/_freeze/posts/2023-10-25/index/figure-html/unnamed-chunk-3-1.png new file mode 100644 index 0000000000000000000000000000000000000000..4c161d59eb2e058a333d90947d10f4ca9aafb09e GIT binary patch literal 13119 zcmdsecT`i`)-NHHqX?)ds0es0fKp;XkWdniA}9)o6zNu)6oJqZAmMNo6)B4J7Nv`T z3WAh?%0UhwB!GzY0}+zYLJ1{-ByVl>w(-4hjQjq1Z@h1hO?I-^+H1`@*DSv|*XDt_ zsgd~RJ(~pt1jNr7pRo`S5Jn3Kz~BD@2X`9Z9hd@_8S@L4hTtk7fD{mL5fI=DAdvz{ z7Xf6vfQyTO3;3)A4bVO4a6!6&GadXS$!RG*Y#svw^jW+NE)CC;zF7e>3bO9YI zD_ttVCqEu35bpv`WISkw+QCs7UkT2Ec+fg95I?}LbP=d@K~~0t)1~r9Gt>nf15mF4 z@X4>_^9SOQ1Mw~cmEepY*l2^E2940c2VDmEd_G{N(gk$o4^;BO-HqqKZR4Zkd4Szb zcZ_ZQ1q9@xpg&mL`1~yafqeq!&KOt*XUq(F-RQoOM!Z&g@0GpC=D^_8Ov`Su3omM~ zRsMG3^0jB(@70T3etXa6qg>S*&Q~T}iHnQ9K3=1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_8! z3i;!ckvQD$*R;v&27%XzzU ztLuEV`i-Yia@_Xx51s?wGeN|3_1bkgIwlpLspcPYiRvux6)oMM6P}f0I8Bn}HuXjK zCIcvnuJN8^K?ohDkJPf+t7wtpKli^@BTP*6!z3+Fs(1x%?# zzo>iHHSr>XH3T$6&TJ*xRi^>fVQ+<;^R1}}(bRKu6uO1we^39TwXx%O>?!UuF~OSA zH*K&IbwGI@X`afKrq4uc!d!jT2vs z|5n#-aiG9igk)>(!o4El#wc8#PDcDfzt`q;;*opJXP^@I4qn7xUl;e_7c{)ojxApu z6*Ifv@O`ON-Gki}lf6KTO!PVR?IN(c@BaEFUxE?XZLi<7T%*UCxrhd-OS-XBK2Mja zZw87|f0U>aeWWL7xw)|~i`9B6zk9*YI+o?IgzZ)JU^J9?#g zX|vD99QCc{FY>b&=lNlHOQciz8#CmPdR+jMmdp=+dPfYCbIYen7`ZTi)$w5RdB>si zb(|&dI$*cfrEYE|Zt-v(OHr;b{B*v+KN;gZgnH_G0ZgalSA>jhl@?sLHFNjDr zbX;xvUNs_tHF3ryi6TnQ%ue>!f`%#i^r3@9%XWQQRL+jQrXGGsSvx20=i~)n?6^U0 zd)!B#is?4NnhE7lhQ_l=Q=Ua?aYCr7obkwCOQotF?a}t-`vQ{)7AMy-;`YopDB?QH zt>ws~4yKx4q}iu%m|JKq1<{($HwZC$6BVR{a}3Q%jE?_dV$T6)v?#JnoiWy1`=+o* zMyqyop9R41R^?>&s#wE7d8&?!Yu}E7p$t4uPa7R}sxL2d@8iR>;63ET?np(vzb{(r z%5q)6?WF3u!g+=PvxAK4FqJ$a@s@0M_=x16x-UZy*?F3&b7!o|f^JaNpJ4<@Steve On Data +
Categories
All (222)
abline (1)
apply (1)
arrow (1)
attributes (1)
augment (1)
autoarima (1)
automl (1)
batchfile (1)
benchmark (5)
bootstrap (4)
box (1)
brvm (1)
cci30 (1)
cms (1)
code (88)
correlation (1)
crypto (1)
cumulative (2)
data (2)
datatable (5)
datetime (4)
distributions (1)
dplyr (3)
duckdb (1)
excel (6)
files (1)
ggplot2 (2)
healthcare (1)
healthyr (8)
healthyrai (18)
healthyrdata (2)
healthyrts (18)
healthyverse (1)
histograms (2)
kmeans (2)
knn (1)
lapply (5)
linear (1)
linearequations (1)
linkedin (1)
list (3)
lists (5)
mapping (2)
markets (1)
metadata (1)
mixturemodels (1)
modelr (1)
news (1)
openxlsx (2)
parsnip (1)
plotly (1)
plots (1)
preprocessor (1)
purrr (10)
randomwalk (2)
readr (1)
readxl (2)
recipes (3)
regex (1)
regression (1)
rtip (210)
rvest (1)
sample (1)
sapply (1)
shell (1)
shiny (16)
simulation (1)
skew (1)
sql (1)
subset (1)
thanks (1)
tidyaml (11)
tidydensity (21)
tidymodels (9)
tidyquant (1)
tidyr (1)
timeseries (24)
transforms (1)
vba (2)
viz (45)
weeklytip (13)
which (1)
workflowsets (1)
writexl (2)
xgboost (2)
xlsx (2)
@@ -209,7 +209,45 @@
Categories
-
+
+
+

+
+ + +
+
@@ -247,7 +285,7 @@

-
+
@@ -288,7 +326,7 @@

-
+
@@ -326,7 +364,7 @@

-
+
@@ -364,7 +402,7 @@

-
+
@@ -405,7 +443,7 @@

-
+
@@ -446,7 +484,7 @@

-
+
@@ -487,7 +525,7 @@

-
+
@@ -525,7 +563,7 @@

-
+
@@ -563,7 +601,7 @@

-
+
@@ -601,7 +639,7 @@

-
+
@@ -639,7 +677,7 @@

-
+
@@ -677,7 +715,7 @@

-
+
@@ -715,7 +753,7 @@

-
+
@@ -753,7 +791,7 @@

-
+
@@ -791,7 +829,7 @@

-
+
@@ -829,7 +867,7 @@

-
+
@@ -867,7 +905,7 @@

-
+
@@ -905,7 +943,7 @@

-
+
@@ -943,7 +981,7 @@

-
+
@@ -984,7 +1022,7 @@

-
+
@@ -1022,7 +1060,7 @@

-
+
@@ -1060,7 +1098,7 @@

-
+
@@ -1098,7 +1136,7 @@

-
+
@@ -1136,9 +1174,9 @@

-
+
-
+
@@ -1212,7 +1250,7 @@

-
+
@@ -1250,7 +1288,7 @@

-
+
@@ -1288,7 +1326,7 @@

-
+
@@ -1326,7 +1364,7 @@

-
+
@@ -1364,7 +1402,7 @@

-
+
@@ -1402,7 +1440,7 @@

-
+
@@ -1440,7 +1478,7 @@

-
+
@@ -1478,7 +1516,7 @@

-
+
@@ -1516,7 +1554,7 @@

-
+
@@ -1554,7 +1592,7 @@

-
+
@@ -1592,7 +1630,7 @@

-
+
@@ -1633,7 +1671,7 @@

-
+
@@ -1671,7 +1709,7 @@

-
+
@@ -1709,7 +1747,7 @@

-
+
@@ -1747,7 +1785,7 @@

-
+
@@ -1785,7 +1823,7 @@

-
+
@@ -1823,7 +1861,7 @@

-
+
@@ -1861,7 +1899,7 @@

-
+
@@ -1899,7 +1937,7 @@

-
+
@@ -1937,7 +1975,7 @@

-
+
@@ -1972,7 +2010,7 @@

-
+
@@ -2010,7 +2048,7 @@

-
+
@@ -2048,7 +2086,7 @@

-
+
@@ -2083,7 +2121,7 @@

-
+
@@ -2118,7 +2156,7 @@

-
+
@@ -2153,7 +2191,7 @@

-
+
@@ -2188,7 +2226,7 @@

-
+
@@ -2223,7 +2261,7 @@

-
+
@@ -2258,7 +2296,7 @@

-
+
@@ -2293,7 +2331,7 @@

-
+
@@ -2328,7 +2366,7 @@

-
+
@@ -2363,7 +2401,7 @@

-
+
@@ -2398,7 +2436,7 @@

-
+
@@ -2433,7 +2471,7 @@

-
+
@@ -2468,7 +2506,7 @@

-
+
@@ -2506,7 +2544,7 @@

-
+
@@ -2541,7 +2579,7 @@

-
+
@@ -2576,7 +2614,7 @@

-
+
@@ -2611,7 +2649,7 @@

-
+
@@ -2646,7 +2684,7 @@

-
+
@@ -2681,7 +2719,7 @@

-
+
@@ -2722,7 +2760,7 @@

-
+
@@ -2766,7 +2804,7 @@

-
+
@@ -2804,7 +2842,7 @@

-
+
@@ -2839,7 +2877,7 @@

-
+
@@ -2874,7 +2912,7 @@

-
+
@@ -2909,7 +2947,7 @@

-
+
@@ -2944,7 +2982,7 @@

-
+
@@ -2979,7 +3017,7 @@

-
+
@@ -3017,7 +3055,7 @@

-
+
@@ -3055,7 +3093,7 @@

-
+
@@ -3090,7 +3128,7 @@

-
+
@@ -3131,7 +3169,7 @@

-
+
@@ -3175,7 +3213,7 @@

-
+
@@ -3210,7 +3248,7 @@

-
+
@@ -3245,7 +3283,7 @@

-
+
@@ -3280,7 +3318,7 @@

-
+
@@ -3315,7 +3353,7 @@

-
+
@@ -3356,7 +3394,7 @@

-
+
@@ -3397,7 +3435,7 @@

-
+
@@ -3432,7 +3470,7 @@

-
+
@@ -3467,7 +3505,7 @@

-
+
@@ -3505,7 +3543,7 @@

-
+
@@ -3540,7 +3578,7 @@

-
+
@@ -3575,7 +3613,7 @@

-
+
@@ -3613,7 +3651,7 @@

-
+
@@ -3648,7 +3686,7 @@

-
+
@@ -3695,7 +3733,7 @@

-
+
@@ -3742,7 +3780,7 @@

-
+
@@ -3786,7 +3824,7 @@

-
+
@@ -3821,7 +3859,7 @@

-
+
@@ -3859,7 +3897,7 @@

-
+
@@ -3897,7 +3935,7 @@

-
+
@@ -3935,7 +3973,7 @@

-
+
@@ -3973,7 +4011,7 @@

-
+
@@ -4011,7 +4049,7 @@

-
+
@@ -4049,7 +4087,7 @@

-
+
@@ -4087,7 +4125,7 @@

-
+
@@ -4128,7 +4166,7 @@

-
+
@@ -4169,7 +4207,7 @@

-
+
@@ -4207,7 +4245,7 @@

-
+
@@ -4248,7 +4286,7 @@

-
+
@@ -4289,7 +4327,7 @@

-
+
@@ -4333,7 +4371,7 @@

-
+
@@ -4374,7 +4412,7 @@

-
+
@@ -4418,7 +4456,7 @@

-
+
@@ -4462,7 +4500,7 @@

-
+
@@ -4506,7 +4544,7 @@

-
+
@@ -4550,7 +4588,7 @@

-
+
@@ -4594,7 +4632,7 @@

-
+
@@ -4635,7 +4673,7 @@

-
+
@@ -4676,7 +4714,7 @@

-
+
@@ -4717,7 +4755,7 @@

-
+
@@ -4758,7 +4796,7 @@

-
+
@@ -4796,7 +4834,7 @@

-
+
@@ -4840,7 +4878,7 @@

-
+
@@ -4881,7 +4919,7 @@

-
+
@@ -4928,7 +4966,7 @@

-
+
@@ -4972,7 +5010,7 @@

-
+
@@ -5019,7 +5057,7 @@

-
+
@@ -5060,7 +5098,7 @@

-
+
@@ -5110,7 +5148,7 @@

-
+
@@ -5148,7 +5186,7 @@

-
+
@@ -5186,7 +5224,7 @@

-
+
@@ -5224,7 +5262,7 @@

-
+
@@ -5262,7 +5300,7 @@

-
+
@@ -5297,7 +5335,7 @@

-
+
@@ -5338,7 +5376,7 @@

-
+
@@ -5382,7 +5420,7 @@

-
+
@@ -5423,7 +5461,7 @@

-
+
@@ -5464,7 +5502,7 @@

-
+
@@ -5505,7 +5543,7 @@

-
+
@@ -5546,7 +5584,7 @@

-
+
@@ -5590,7 +5628,7 @@

-
+
@@ -5634,7 +5672,7 @@

-
+
@@ -5675,7 +5713,7 @@

-
+
@@ -5719,7 +5757,7 @@

-
+
@@ -5763,7 +5801,7 @@

-
+
@@ -5807,7 +5845,7 @@

-
+
@@ -5854,7 +5892,7 @@

-
+
@@ -5895,7 +5933,7 @@

-
+
@@ -5939,7 +5977,7 @@

-
+
@@ -5980,7 +6018,7 @@

-
+
@@ -6024,7 +6062,7 @@

-
+
@@ -6065,7 +6103,7 @@

-
+
@@ -6106,7 +6144,7 @@

-
+
@@ -6144,7 +6182,7 @@

-
+
@@ -6185,7 +6223,7 @@

-
+
@@ -6226,7 +6264,7 @@

-
+
@@ -6273,7 +6311,7 @@

-
+
@@ -6317,7 +6355,7 @@

-
+
@@ -6361,7 +6399,7 @@

-
+
@@ -6405,7 +6443,7 @@

-
+
@@ -6449,7 +6487,7 @@

-
+
@@ -6493,7 +6531,7 @@

-
+
@@ -6537,7 +6575,7 @@

-
+
@@ -6581,7 +6619,7 @@

-
+
@@ -6625,7 +6663,7 @@

-
+
@@ -6672,7 +6710,7 @@

-
+
@@ -6713,7 +6751,7 @@

-
+
@@ -6757,7 +6795,7 @@

-
+
@@ -6801,7 +6839,7 @@

-
+
@@ -6845,7 +6883,7 @@

-
+
@@ -6889,7 +6927,7 @@

-
+
@@ -6933,7 +6971,7 @@

-
+
@@ -6977,7 +7015,7 @@

-
+
@@ -7018,7 +7056,7 @@

-
+
@@ -7062,7 +7100,7 @@

-
+
@@ -7103,7 +7141,7 @@

-
+
@@ -7144,7 +7182,7 @@

-
+
@@ -7188,7 +7226,7 @@

-
+
@@ -7232,7 +7270,7 @@

-
+
@@ -7276,7 +7314,7 @@

-
+
@@ -7317,7 +7355,7 @@

-
+
@@ -7364,7 +7402,7 @@

-
+
@@ -7405,7 +7443,7 @@

-
+
@@ -7446,7 +7484,7 @@

-
+
@@ -7490,7 +7528,7 @@

-
+
@@ -7534,7 +7572,7 @@

-
+
@@ -7578,7 +7616,7 @@

-
+
@@ -7622,7 +7660,7 @@

-
+
@@ -7663,7 +7701,7 @@

-
+
@@ -7707,7 +7745,7 @@

-
+
@@ -7751,7 +7789,7 @@

-
+
@@ -7795,7 +7833,7 @@

-
+
@@ -7839,7 +7877,7 @@

-
+
@@ -7883,7 +7921,7 @@

-
+
@@ -7927,7 +7965,7 @@

-
+
@@ -7971,7 +8009,7 @@

-
+
@@ -8012,7 +8050,7 @@

-
+
@@ -8056,7 +8094,7 @@

-
+
@@ -8100,7 +8138,7 @@

-
+
@@ -8141,7 +8179,7 @@

-
+
@@ -8185,7 +8223,7 @@

-
+
@@ -8229,7 +8267,7 @@

-
+
@@ -8270,7 +8308,7 @@

-
+
@@ -8311,7 +8349,7 @@

-
+
@@ -8355,7 +8393,7 @@

-
+
@@ -8396,7 +8434,7 @@

-
+
@@ -8440,7 +8478,7 @@

-
+
@@ -8484,7 +8522,7 @@

-
+
@@ -8528,7 +8566,7 @@

-
+
@@ -8569,7 +8607,7 @@

-
+
@@ -8613,7 +8651,7 @@

-
+
@@ -8654,7 +8692,7 @@

-
+
@@ -8695,7 +8733,7 @@

-
+
@@ -8739,7 +8777,7 @@

-
+
@@ -8777,7 +8815,7 @@

-
+
@@ -8821,7 +8859,7 @@

-
+
@@ -8862,7 +8900,7 @@

-
+
@@ -8909,7 +8947,7 @@

-
+
@@ -8950,7 +8988,7 @@

-
+
@@ -8991,7 +9029,7 @@

-
+
@@ -9032,7 +9070,7 @@

-
+
@@ -9073,7 +9111,7 @@

-
+
diff --git a/docs/index.xml b/docs/index.xml index 79bfea19..71d92118 100644 --- a/docs/index.xml +++ b/docs/index.xml @@ -10,7 +10,266 @@ quarto-1.3.433 -Tue, 24 Oct 2023 04:00:00 GMT +Wed, 25 Oct 2023 04:00:00 GMT + + What’s a Bland-Altman Plot? In Base R + Steven P. Sanderson II, MPH + https://www.spsanderson.com/steveondata/posts/2023-10-25/index.html + +

Introduction

+

Before we dive into the code, let’s briefly understand what a Bland-Altman plot is. It’s a graphical method to visualize the agreement between two measurement techniques, often used in fields like medicine or any domain with comparative measurements. The plot displays the differences between two measurements (Y-axis) against their means (X-axis).

+ +
+

Step 1: Data Preparation

+

Start by loading your data into R. In our example, we’ll create some synthetic data for illustration purposes. You’d replace this with your real data.

+
+
# Creating example data
+method_A <- c(10, 12, 15, 18, 22, 25)
+method_B <- c(9.5, 11, 14, 18, 22, 24.5)
+
+# Calculate the differences and means
+diff_values <- method_A - method_B
+mean_values <- (method_A + method_B) / 2
+
+df <- data.frame(method_A, method_B, mean_values, diff_values)
+
+
+
+

Step 2: Calculate Average Difference and CI

+

Now that we have our data prepared, let’s create the Bland-Altman plot.

+
+
mean_diff <- mean(df$diff_values)
+mean_diff
+
+
[1] 0.5
+
+
lower <- mean_diff - 1.96 * sd(df$diff_values)
+upper <- mean_diff + 1.96 * sd(df$diff_values)
+
+lower
+
+
[1] -0.3765386
+
+
upper
+
+
[1] 1.376539
+
+
+
+
+

Step 3: Creating the Bland-Altman Plot

+

We are going to do this in base R.

+
+
# Create a scatter plot
+plot(df$mean_values, df$diff_values, 
+     xlab = "Mean of Methods A and B",
+     ylab = "Difference (Method A - Method B)",
+     main = "Bland-Altman Plot",
+     ylim = c(lower + (lower * .1), upper * 1.1))
+
+# Add a horizontal line at the mean difference
+abline(h = mean(diff_values), col = "red", lty = 2)
+
+# Add Confidence Intervals
+abline(h = upper, col = "blue", lty = 2)
+abline(h = lower, col = "blue", lty = 2)
+
+

+
+
+

This code will generate a simple Bland-Altman plot, and here’s what each part does:

+
    +
  • plot(): Creates the scatter plot with means on the X-axis and differences on the Y-axis.
  • +
  • abline(h = mean(diff_values), col = "red", lty = 2): Adds a red dashed line at the mean difference.
  • +
  • abline(h = upper, col = "green", lty = 2): Adds blue dashed lines representing the 95% limits of agreement.
  • +
+
+
+

Step 4: Interpretation

+

Now that you’ve generated your Bland-Altman plot, let’s interpret it:

+
    +
  • The red line represents the mean difference between the two methods.
  • +
  • The blue dashed lines show the 95% limits of agreement, which help you assess the spread of the differences.
  • +
+

If most data points fall within the blue lines, it indicates good agreement between the two methods. If data points are scattered widely outside the lines, there may be a systematic bias or inconsistency between the methods.

+
+
+

Step 5: Exploration

+

I encourage you to try this out with your own data. Replace the example data with your measurements and see what insights your Bland-Altman plot reveals.

+

In conclusion, creating a Bland-Altman plot in R is a valuable technique to visualize agreement or bias between two measurement methods. It’s an essential tool for quality control and validation in various fields. I hope this step-by-step guide helps you get started. Happy plotting!

+ + +
+ + ]]>
+ rtip + viz + https://www.spsanderson.com/steveondata/posts/2023-10-25/index.html + Wed, 25 Oct 2023 04:00:00 GMT +
Creating a Scree Plot in Base R Steven P. Sanderson II, MPH @@ -4840,188 +5099,5 @@ font-style: inherit;">"purple")
https://www.spsanderson.com/steveondata/posts/2023-09-27/index.html Wed, 27 Sep 2023 04:00:00 GMT - - Mastering Data Visualization with ggplot2: A Guide to Using facet_grid() - Steven P. Sanderson II, MPH - https://www.spsanderson.com/steveondata/posts/2023-09-26/index.html - -

Introduction

-

Data visualization is a crucial tool in the data scientist’s toolkit. It allows us to explore and communicate complex patterns and insights effectively. In the world of R programming, one of the most powerful and versatile packages for data visualization is ggplot2. Among its many features, ggplot2 offers the facet_grid() function, which enables you to create multiple plots arranged in a grid, making it easier to visualize different groups of data simultaneously.

-

In this blog post, we’ll dive into the fascinating world of facet_grid() using a practical example. We’ll generate some synthetic data, split it into multiple groups, and then use facet_grid() to create a visually appealing grid of plots.

- -
-

Generating Synthetic Data

-

Let’s start by generating some synthetic data using the TidyDensity package in R. We’ll create three groups of data, each with 100 observations, and a mean of -2, 0, and 2, respectively, all with a standard deviation of 1. We’ll also perform this simulation five times to create a diverse dataset.

-
-
library(TidyDensity)
-
-data <- tidy_multi_single_dist(
-  .tidy_dist = "tidy_normal", 
-  .param_list = list(
-    .n = 100, 
-    .mean = c(-2, 0, 2), 
-    .sd = 1, 
-    .num_sims = 5
-    )
-  )
-
-

Now that we have our data, it’s time to visualize it using facet_grid().

-
-
-

Using facet_grid() to Visualize Multiple Groups

-

The facet_grid() function in ggplot2 is a versatile tool for creating a grid of plots based on one or more categorical variables. It allows you to create small multiples, which are a series of similar plots, each showing a subset of your data.

-

In our synthetic data, we have three groups (mean of -2, 0, and 2), and we want to visualize each group’s distribution. Here’s how you can do it:

-
-
# Create a ggplot object
-# Load ggplot2
-library(ggplot2)
-
-# Create a ggplot object
-p <- ggplot(data, aes(x = y, color = sim_number, group = sim_number)) +
-  geom_density(alpha = 0.5) +
-  facet_wrap(. ~ dist_name)
-
-# Customize the plot
-p + labs(title = "Density Plots of Three Different Means",
-         x = "Value",
-         y = "Density") +
-  theme_minimal() +
-  theme(legend.position = "none")
-
-

-
-
-

In this code:

-
    -
  1. We load the ggplot2 package, which is essential for creating our plots.

  2. -
  3. We create a ggplot object p where we specify the aesthetics (x-axis, fill color) and the geometry (density plot). We use facet_grid(. ~ simulation) to split the data into separate facets based on the simulation variable. This means that each facet will represent one of the five simulations.

  4. -
  5. We add labels and customize the plot’s appearance using the labs() and theme_minimal() functions.

  6. -
  7. Finally, we display the plot by evaluating p.

  8. -
-

The resulting plot will show a grid of density plots, with each facet representing one simulation. Within each facet, you’ll see the density distribution of the data, colored by the group mean.

-
-
-

Conclusion

-

In this blog post, we explored the power of ggplot2’s facet_grid() function for visualizing multiple groups of data. By generating synthetic data and using ggplot2, we created an informative grid of density plots, allowing us to compare and contrast the distributions of different groups.

-

The ability to create small multiples with facet_grid() is invaluable for gaining insights from complex datasets. Whether you’re working with synthetic data or real-world data, mastering ggplot2’s facet_grid() function will enhance your data visualization skills and help you communicate your findings more effectively.

-

So, go ahead and experiment with your data. Create your own grid of plots using facet_grid() and unlock new ways to visualize and understand your data. Happy plotting!

- - -
- - ]]>
- rtip - viz - ggplot2 - https://www.spsanderson.com/steveondata/posts/2023-09-26/index.html - Tue, 26 Sep 2023 04:00:00 GMT -
diff --git a/docs/listings.json b/docs/listings.json index d64f5487..025c80b7 100644 --- a/docs/listings.json +++ b/docs/listings.json @@ -2,6 +2,7 @@ { "listing": "/index.html", "items": [ + "/posts/2023-10-25/index.html", "/posts/2023-10-24/index.html", "/posts/2023-10-23/index.html", "/posts/2023-10-20/index.html", diff --git a/docs/posts/2023-10-25/index.html b/docs/posts/2023-10-25/index.html new file mode 100644 index 00000000..b54738fd --- /dev/null +++ b/docs/posts/2023-10-25/index.html @@ -0,0 +1,669 @@ + + + + + + + + + + + +Steve’s Data Tips and Tricks - What’s a Bland-Altman Plot? In Base R + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ +
+
+
+

What’s a Bland-Altman Plot? In Base R

+
+
rtip
+
viz
+
+
+
+ + +
+ +
+
Author
+
+

Steven P. Sanderson II, MPH

+
+
+ +
+
Published
+
+

October 25, 2023

+
+
+ + +
+ + +
+ + + + +
+ + + + +
+

Introduction

+

Before we dive into the code, let’s briefly understand what a Bland-Altman plot is. It’s a graphical method to visualize the agreement between two measurement techniques, often used in fields like medicine or any domain with comparative measurements. The plot displays the differences between two measurements (Y-axis) against their means (X-axis).

+
+
+

Step 1: Data Preparation

+

Start by loading your data into R. In our example, we’ll create some synthetic data for illustration purposes. You’d replace this with your real data.

+
+
# Creating example data
+method_A <- c(10, 12, 15, 18, 22, 25)
+method_B <- c(9.5, 11, 14, 18, 22, 24.5)
+
+# Calculate the differences and means
+diff_values <- method_A - method_B
+mean_values <- (method_A + method_B) / 2
+
+df <- data.frame(method_A, method_B, mean_values, diff_values)
+
+
+
+

Step 2: Calculate Average Difference and CI

+

Now that we have our data prepared, let’s create the Bland-Altman plot.

+
+
mean_diff <- mean(df$diff_values)
+mean_diff
+
+
[1] 0.5
+
+
lower <- mean_diff - 1.96 * sd(df$diff_values)
+upper <- mean_diff + 1.96 * sd(df$diff_values)
+
+lower
+
+
[1] -0.3765386
+
+
upper
+
+
[1] 1.376539
+
+
+
+
+

Step 3: Creating the Bland-Altman Plot

+

We are going to do this in base R.

+
+
# Create a scatter plot
+plot(df$mean_values, df$diff_values, 
+     xlab = "Mean of Methods A and B",
+     ylab = "Difference (Method A - Method B)",
+     main = "Bland-Altman Plot",
+     ylim = c(lower + (lower * .1), upper * 1.1))
+
+# Add a horizontal line at the mean difference
+abline(h = mean(diff_values), col = "red", lty = 2)
+
+# Add Confidence Intervals
+abline(h = upper, col = "blue", lty = 2)
+abline(h = lower, col = "blue", lty = 2)
+
+

+
+
+

This code will generate a simple Bland-Altman plot, and here’s what each part does:

+
    +
  • plot(): Creates the scatter plot with means on the X-axis and differences on the Y-axis.
  • +
  • abline(h = mean(diff_values), col = "red", lty = 2): Adds a red dashed line at the mean difference.
  • +
  • abline(h = upper, col = "green", lty = 2): Adds blue dashed lines representing the 95% limits of agreement.
  • +
+
+
+

Step 4: Interpretation

+

Now that you’ve generated your Bland-Altman plot, let’s interpret it:

+
    +
  • The red line represents the mean difference between the two methods.
  • +
  • The blue dashed lines show the 95% limits of agreement, which help you assess the spread of the differences.
  • +
+

If most data points fall within the blue lines, it indicates good agreement between the two methods. If data points are scattered widely outside the lines, there may be a systematic bias or inconsistency between the methods.

+
+
+

Step 5: Exploration

+

I encourage you to try this out with your own data. Replace the example data with your measurements and see what insights your Bland-Altman plot reveals.

+

In conclusion, creating a Bland-Altman plot in R is a valuable technique to visualize agreement or bias between two measurement methods. It’s an essential tool for quality control and validation in various fields. I hope this step-by-step guide helps you get started. Happy plotting!

+ + +
+ +
+ +
+ + + + \ No newline at end of file diff --git a/docs/posts/2023-10-25/index_files/figure-html/unnamed-chunk-3-1.png b/docs/posts/2023-10-25/index_files/figure-html/unnamed-chunk-3-1.png new file mode 100644 index 0000000000000000000000000000000000000000..4c161d59eb2e058a333d90947d10f4ca9aafb09e GIT binary patch literal 13119 zcmdsecT`i`)-NHHqX?)ds0es0fKp;XkWdniA}9)o6zNu)6oJqZAmMNo6)B4J7Nv`T z3WAh?%0UhwB!GzY0}+zYLJ1{-ByVl>w(-4hjQjq1Z@h1hO?I-^+H1`@*DSv|*XDt_ zsgd~RJ(~pt1jNr7pRo`S5Jn3Kz~BD@2X`9Z9hd@_8S@L4hTtk7fD{mL5fI=DAdvz{ z7Xf6vfQyTO3;3)A4bVO4a6!6&GadXS$!RG*Y#svw^jW+NE)CC;zF7e>3bO9YI zD_ttVCqEu35bpv`WISkw+QCs7UkT2Ec+fg95I?}LbP=d@K~~0t)1~r9Gt>nf15mF4 z@X4>_^9SOQ1Mw~cmEepY*l2^E2940c2VDmEd_G{N(gk$o4^;BO-HqqKZR4Zkd4Szb zcZ_ZQ1q9@xpg&mL`1~yafqeq!&KOt*XUq(F-RQoOM!Z&g@0GpC=D^_8Ov`Su3omM~ zRsMG3^0jB(@70T3etXa6qg>S*&Q~T}iHnQ9K3=1bxshRZYMpKS7xuber=wJa^h4SAe*eHA(k2ys<48x zyAZy!vm_hmR=n@hW;fpMuI;e#%_cClhx48sn;21yQ|W+n(rgA|iAo)AEXjH=@&cw- z5)osKj&(IQ5qhffQlvsl>^CY*FH@$tB7VVwEFn$K*H(dLdTsZ4CAgq_+HOD5;hH15 zpxq5gY?NthadMixhA_(dDuj8nE^dv^`Z3HSI5O^!s$P=ee3}IPW+&g@U7vWadQ46{StbDpwQN4#c<-G+16 zf0@p|n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