<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/statistics-in-glaucoma-part-iii/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://rviews.rstudio.com/2018/12/18/statistics-in-glaucoma-part-iii/"> R Views</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><em>Samuel Berchuck is a Postdoctoral Associate in Duke University’s Department of Statistical Science and Forge-Duke’s Center for Actionable Health Data Science.</em></p>
<p><em>Joshua L. Warren is an Assistant Professor of Biostatistics at Yale University.</em></p>
<div>
<h2>Looking Forward in Glaucoma Progression Research</h2>
<p>The contribution of the <code>womblR</code> package and corresponding statistical methodology is a technique for correctly accounting for the complex spatial structure of the visual field. The purpose of this method is to properly model visual field data, so that an effective diagnostic is derived that discriminates progression status. This is one of many important clinical questions that needs to be addressed in glaucoma research. Others include: quantifying visual field variability to create simulations of healthy and progression patients, combining multiple data modalities to obtain a composite diagnostic, and predicting the timing and spatial location of future vision loss. There is opportunity within the glaucoma literature for the development of quantitative methods that answer important clinical questions, are easy to understand, and are simple to use. To this end, in closing this three-part series, we present a final example of a new method that uses change points to assess future vision loss.</p>
</div>
<div>
<h2>Modeling Changes on the Visual Field Using Spatial Change Points</h2>
<p>To motivate the use of change points, we note that patients diagnosed with glaucoma are often monitored for years with slow changes in visual functionality. It is not until disease progression that notable vision loss occurs, and the deterioration is often swift. This disease course inspires a modeling framework that can identify a point of functional change in the course of follow-up, thus change points are employed. This is an appealing modeling framework, because the concept of disease progression becomes intrinsically parameterized into the model, with the change point representing the point of functional change. In this model, the time of the change point triggers a simultaneous change in both the mean and variance process. Furthermore, to account for the typical trend of a long period of monitoring with little change followed by abrupt vision loss, we force the mean and variance to be constant before the change point. For the mean process, and assuming data from a patient with nine visual field tests, this results in <span>\[\mu_t\left(\mathbf{s}_i\right)=\left\{ \begin{array}{ll}<br>
{\beta}_0\left(\mathbf{s}_i\right) &amp; x_t \leq \theta\left(\mathbf{s}_i\right),\\<br>
{\beta}_0\left(\mathbf{s}_i\right) + {\beta}_1\left(\mathbf{s}_i\right)\left\{x_t-\theta\left(\mathbf{s}_i\right)\right\} &amp; \theta\left(\mathbf{s}_i\right) \leq x_t.\end{array} \right. \quad t = 1,\ldots,9 \quad i = 1,\ldots,52 \]</span> Here, the change point at location <span>\(\mathbf{s}_i\)</span> is given by <span>\(\theta(\mathbf{s}_i)\)</span>, and <span>\(x_t\)</span> is the days from baseline visit for follow-up visit <span>\(t\)</span>. A final important detail is that the change points <span>\(\theta(\mathbf{s}_i)\)</span> are truncated in the observed follow-up range, <span>\((x_1, x_9)\)</span>. In practice, the true change point can occur outside of this region, so we define a latent process, <span>\(\eta(\mathbf{s}_i)\)</span>, that defines the true change point, <span>\(\theta(\mathbf{s}_i) = \max\{\min\{\eta(\mathbf{s}_i), x_9\}, x_1\}\)</span>. Finally, all of the location-specific effects are modeled using a novel multivariate conditional autoregressive (MCAR) prior that incorporates the anatomy detailed in the <code>womblR</code> method. More details can be found in Berchuck et al. 2018.</p>
<p>We once again rely on MCMC methods for inference, and a package similar to <code>womblR</code> was developed that implements the spatially varying change point model, <code>spCP</code>. This package has much of the same functionality as <code>womblR</code>, and we demonstrate its functionality below.</p>
<p>We begin by loading <code>spCP</code>. All of the visual field data (<code>VFSeries</code>), adjacencies (<code>HFAII_Queen</code>), and anatomical angles (<code>GarwayHeath</code>) are included in the <code>spCP</code> package.</p>
<pre><code>###Load package
library(spCP)

###Format data
blind_spot &lt;- c(26, 35) # define blind spot
VFSeries &lt;- VFSeries[order(VFSeries$Location), ] # sort by location
VFSeries &lt;- VFSeries[order(VFSeries$Visit), ] # sort by visit
VFSeries &lt;- VFSeries[!VFSeries$Location %in% blind_spot, ] # remove blind spot locations
Y &lt;- VFSeries$DLS # define observed outcome data
Time &lt;- unique(VFSeries$Time) / 365 # years since baseline visit
MaxTime &lt;- max(Time)

###Neighborhood objects
W &lt;- HFAII_Queen[-blind_spot, -blind_spot] # visual field adjacency matrix
M &lt;- dim(W)[1] # number of locations
DM &lt;- GarwayHeath[-blind_spot] # Garway-Heath angles
Nu &lt;- length(Time) # number of visits

###Obtain bounds for spatial parameter (details are in Berchuck et al. 2018)
pdist &lt;- function(x, y) pmin(abs(x - y), (360 - pmax(x, y) + pmin(x, y))) #Dissimilarity metric distance function (i.e., circumference)
DM_Matrix &lt;- matrix(nrow = M, ncol = M)
for (i in 1:M) {
  for (j in 1:M) {
    DM_Matrix[i, j] &lt;- pdist(DM[i], DM[j])
  }
}
BAlpha &lt;- -log(0.5) / min(DM_Matrix[DM_Matrix > 0])
AAlpha &lt;- 0

###Hyperparameters
Hypers &lt;- list(Alpha = list(AAlpha = AAlpha, BAlpha = BAlpha),
               Sigma = list(Xi = 6, Psi = diag(5)),
               Delta = list(Kappa2 = 1000))

###Starting values
Starting &lt;- list(Sigma = 0.01 * diag(5),
                 Alpha = mean(c(AAlpha, BAlpha)),
                 Delta = c(0, 0, 0, 0, 0))

###Metropolis tuning variances 
Tuning &lt;- list(Lambda0Vec = rep(1, M),
               Lambda1Vec = rep(1, M),
               EtaVec = rep(1, M),
               Alpha = 1)

###MCMC inputs
MCMC &lt;- list(NBurn = 10000, NSims = 250000, NThin = 25, NPilot = 20)</code></pre>
<p>Once the inputs have been properly formatted, the program can be run.</p>
<pre><code>###Run MCMC sampler
reg.spCP &lt;- spCP(Y = Y, DM = DM, W = W, Time = Time, 
                 Starting = Starting, Hypers = Hypers, Tuning = Tuning, MCMC = MCMC,
                 Family = &quot;tobit&quot;, 
                 Weights = &quot;continuous&quot;, 
                 Distance = &quot;circumference&quot;,
                 Rho = 0.99, 
                 ScaleY = 10, 
                 ScaleDM = 100, 
                 Seed = 54)
## Burn-in progress: |*************************************************|
## Sampler progress: 0%.. 10%.. 20%.. 30%.. 40%.. 50%.. 60%.. 70%.. 80%.. 90%.. 100%..  </code></pre>
<p>To visualize the estimated change points, we can use the <code>PlotCP</code> function from <code>spcP</code>. The function requires the model fit object and the original data set, plus the variable names of the raw DLS, time (in years), and spatial locations.</p>
<pre><code>VFSeries$TimeYears &lt;- VFSeries$Time / 365
PlotCP(reg.spCP, 
       VFSeries, 
       dls = &quot;DLS&quot;, 
       time = &quot;TimeYears&quot;, 
       location = &quot;Location&quot;, 
       cp.line = TRUE, 
       cp.ci = TRUE)</code></pre>
<p><img src="https://i0.wp.com/rviews.rstudio.com/post/2018-12-12-statistics-in-glaucoma-part-iii_files/figure-html/unnamed-chunk-4-1.png?w=450&ssl=1" data-recalc-dims="1"></p>
<p>Using the <code>PlotCP</code> function, we present the posterior means of the change points using a blue vertical line, with dashed 95% credible intervals. Furthermore, the mean process and credible interval are plotted using red lines, and the raw DLS values are given by black points. For this example patient, the majority of the change points are at the edges of follow-up. When the DLS is constant over time, the estimated change points are at the end of follow-up, while any trends that are present before follow-up correspond to the change point occurring at the beginning. This information provides clinicians with visual and quantitative confirmation of functional changes across the visual field.</p>
</div>
<div>
<h2>Change Points as a Proxy for Progression</h2>
<p>To formalize the importance of the change points, we look to convert their presence or absence into a clinical decision. We decide to calculate the probability that a change point has been observed at each location across the visual field. To provide a tool that is useful for clinicians, we create a gif that presents the probability of a change point throughout a patient’s follow-up, and are able to predict one and a half years into the future. In Berchuck et al. 2018, it is shown that these change points are highly predictive of progression.</p>
<p>We begin by extracting and calculating the change point probabilities.</p>
<pre><code>###Extract change point posterior samples
eta &lt;- reg.spCP$eta

###Convert change points to probabilties of occuring before time t 
NFrames &lt;- 50 # number of frames in GIF
GIF_Times &lt;- seq(0, MaxTime + 1.5, length.out = NFrames) # obtain GIF 1.5 years after the end of follow-up
GIF_Days &lt;- round(GIF_Times * 365) # convert to days for use later
CP_Probs &lt;- matrix(nrow = M, ncol = NFrames)

###Obtain probabilties at each time point
for (t in 1:NFrames) {
  CP_Probs[, t] &lt;- apply(eta, 2, function(x) mean(x &lt; GIF_Times[t]))
}
colnames(CP_Probs) &lt;- GIF_Times</code></pre>
<p>Now, to create a gif of the probabilities, we use the <code>magick</code> package, and in particular, the functions <code>image_graph</code> and <code>image_animate</code>. Furthermore, we use the <code>PlotSensitivity</code> function from <code>womblR</code> to plot the predicted probabilities on the visual field.</p>
<pre><code>###Load packages
library(magick) # package for creating GIFs
library(womblR) # loaded for PlotSensitivity

###Create GIF
Img &lt;- image_graph(600, 600, res = 96)
for (f in 1:NFrames) {
  p &lt;- womblR::PlotSensitivity(CP_Probs[, f], 
                               legend.lab = expression(paste(&quot;Pr[&quot;, eta, &quot;(s)] &lt; &quot;, t)), 
                               zlim = c(0, 1), 
                               bins = 250,
                               legend.round = 2, 
                               border = FALSE,
                               main = bquote(&quot;Days from baseline: t = &quot; ~ .(GIF_Days[f]) ~ &quot; (&quot; ~ t[max] ~ &quot; = &quot; ~ .(Time[Nu] * 365) ~ &quot;)&quot;))
}
dev.off()</code></pre>
<pre><code>## quartz_off_screen 
##                 2</code></pre>
<p>Now, we animate and print the created gif using the <code>image_animate</code> function, specifying 10 frames per second using the <code>fps</code> option.</p>
<pre><code>Animation &lt;- image_animate(Img, fps = 10)
Animation</code></pre>
<p><img src="https://i2.wp.com/rviews.rstudio.com/post/2018-12-12-statistics-in-glaucoma-part-iii_files/figure-html/unnamed-chunk-7-1.gif?w=456&ssl=1" data-recalc-dims="1"></p>
<p>This gif has many properties that make it clinically useful. The space-time nature of the image allows for clinicians to understand not only the current state of the disease, but also the progression pattern throughout all of follow-up. Furthermore, the gif shows the pattern and future risk of progression over the next one and a half years, presenting clinicians a tool for planning for future risk.</p>
</div>
<div>
<h2>Conclusions and Future Directions</h2>
<p>The hope in developing these <code>R</code> packages is for them to be used clinically, and to inspire other quantitative scientists to do the same. When statistical methods are typically developed for medical research, it is more common for the methodologies to be published without any corresponding software package. This means that no matter how impactful the method may be, it is unlikely to make a clinical impact for many years, due to the complexity in implementing the inferential methods. Clinicians are dependent on quantitative methods for analyzing the massive amounts of data that exist in today’s world, and they are typically reliant on the proprietary software that is built into the imaging machines themselves. This software is useful, but because the methods are often not published, it can be difficult to interpret the results. More open-source software being developed for medical research will lead to greater collaboration and visibility of the important problems being addressed by health researchers. The <code>R</code> environment, including CRAN and RStudio, make it particularly easy to create and share <code>R</code> packages, and the development of <code>Rcpp</code> and its relatives allow for the packages to be computationally fast. Our hope is that the <code>womblR</code> and <code>spCP</code> packages illustrate this concept and excite people to get involved in glaucoma research, or one of many other important health areas.</p>
</div>
<div>
<h2>Reference</h2>
<ol>
<li>Berchuck, S.I., Mwanza, J.C., &amp; Warren, J.L. (2018). <a rel="nofollow" href="https://arxiv.org/pdf/1811.11038.pdf" target="_blank">“A Spatially Varying Change Points Model for Monitoring Glaucoma Progression Using Visual Field Data”</a>.</li>
</ol>
</div>
<p> </p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://rviews.rstudio.com/2018/12/18/statistics-in-glaucoma-part-iii/"> R Views</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/OTP8YcKNgp0" height="1"></a></div>