Calculating AUDPS in R and Julia.
Previously we introduced Julia, a programming language that is similar to R or Python and demonstrated how AUDPC can be calculated using the trapezoidal method in R as shown in the “Disease Progress Over Time” module of the “Epidemiology and Ecology in R”, Sparks et al. (2008). Then we looked at how the function could be optimised in R before writing a Julia function to calculate the same value.
Now we will take a look at a similar calculation, Area Under the Disease Stairs (AUDPS) (Simko and Piepho 2012). AUDPS can give better estimates of the disease progress by giving a weight closer to the optimal first and last observations.
This function is not the fully optimised version like what we showed for AUDPC, using sum()
would help make this faster but possibly at the expense of readability so we’ll stick with using the regular +
and -
here for readability.
Both of the R packages that were previously discussed when showing how to calculate AUDPC, agricolae (Mendiburu 2021) and epifitter (Alves and Del Ponte 2021), provide easy to use functions to calculate AUDPS, audps()
and AUDPS()
, respectively.
The following code uses an example from agricolae’s help showing how to calculate AUDPS in R using our own function, r_audps()
.
> dates <- c(14, 21, 28) # days
> evaluation <- c(40, 80, 90)
> r_audps(evaluation, dates)
[1] 14 21 28
[1] 40 80 90
[1] 1470
Since we’ve already introduced Julia, here we’ll just build an AUDPS function in Julia to illustrate how it can be done.
function j_audps(evaluation, dates)
# find how many observations there are and calculate that minus 1 as well
= length(dates)
n = length(dates) - 1
n_1
# initialise our objects outside the loop
= 0
i = 0
out # the for loop looks roughly the same but here we just use 1:n
for j in 1:n_1
= i + evaluation[j] * (dates[j + 1] - dates[j])
i
= i + evaluation[n] * (dates[n] - dates[n_1])
out end
# return the object, `out` from the for loop
return out
# end the function (no curly brackets!)
end
j_audps (generic function with 1 method)
> dates = [14, 21, 28] # days
julia> evaulation = [40, 80, 90]
julia> j_audps(evaulation, dates) julia
3-element Vector{Int64}:
14
21
28
3-element Vector{Int64}:
40
80
90
1470
The AUDPS values match!
This is just a quick follow-up example of how you can use Julia in plant pathology to show new users how it compares with R with a another commonly used function. If you’re curious to know more, the Julia docs are a great place to start. In particular, the noteworthy differences is a useful bit to refer to if you’re familiar with R.
For a more detailed comparison of complete Julia and R packages that offer an existing plant disease model, EPIRICE (Savary et al. 2012), see Epicrop.jl (Sparks 2022), a port of epicrop (Sparks et al. 2021) to Julia, which has demonstrated faster speeds in benchmarking tests for the same rice disease predictions.
This post was constructed using R Version 4.4.0 (R Core Team 2021) and Julia Version 1.10.2 (Bezanson et al. 2017) using JuliaCall Pull Request #174.
If you see mistakes or want to suggest changes, please create an issue on the source repository.
Text and figures are licensed under Creative Commons Attribution CC BY 4.0. Source code is available at https://github.com/openplantpathology/OpenPlantPathology, unless otherwise noted. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".