Calculating AUDPS using Julia

Julia4PlantPath R4PlantPath Reproducible Research

Calculating AUDPS in R and Julia.

Adam Sparks https://adamhsparks.netlify.app
2022-02-13

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.

r_audps <-
  function(evaluation, dates) {
    n <- length(dates)
    n_1 <- length(dates) - 1
    
    x <- 0
    for (i in seq_len(n_1)) {
      x <- x + evaluation[[i]] * (dates[[i + 1]] - dates[[i]])
    }
    audps <- x + evaluation[[n]] * (dates[[n]] - dates[[n_1]])
    return(audps)
  }

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

Using Julia

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
    n = length(dates)
    n_1 = length(dates) - 1

    # initialise our objects outside the loop
    i = 0
    out = 0
    # the for loop looks roughly the same but here we just use 1:n
    for j in 1:n_1
        i = i + evaluation[j] * (dates[j + 1] - dates[j])
        
        out = i + evaluation[n] * (dates[n] - dates[n_1])
    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)
julia> dates = [14, 21, 28] # days
julia> evaulation = [40, 80, 90]
julia> j_audps(evaulation, dates)
3-element Vector{Int64}:
 14
 21
 28
3-element Vector{Int64}:
 40
 80
 90
1470

The AUDPS values match!

Conclusion

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.

Colophon

This post was constructed using R Version 4.1.2 (R Core Team 2021) and Julia Version 1.7.1 (Bezanson et al. 2017) using JuliaCall Pull Request #174.

Alves, K. dos S., and Del Ponte, E. M. 2021. epifitter: Analysis and Simulation of Plant Disease Progress Curves. Available at: https://CRAN.R-project.org/package=epifitter.
Bezanson, J., Edelman, A., Karpinski, S., and Shah, V. B. 2017. Julia: A fresh approach to numerical computing. SIAM review. 59:65–98.
Mendiburu, F. de. 2021. agricolae: Statistical Procedures for Agricultural Research. Available at: https://CRAN.R-project.org/package=agricolae.
R Core Team. 2021. R: A language and environment for statistical computing. Vienna, Austria: R Foundation for Statistical Computing. Available at: https://www.R-project.org/.
Savary, S., Nelson, A., Willocquet, L., Pangga, I., and Aunario, J. 2012. Modeling and mapping potential epidemics of rice diseases globally. Crop Protection. 34:6–17.
Simko, I., and Piepho, H.-P. 2012. The area under the disease progress stairs: Calculation, advantage, and application. Phytopathology. 102:381–389.
Sparks, A. 2022. Simulation modelling of crop diseases using a healthy-latent-infectious-postinfectious (HLIP) model in Julia. Available at: https://github.com/adamhsparks/Epicrop.jl.
Sparks, A. H., Hijmans, R., Savary, S., Pangga, I., and Aunario, J. 2021. epicrop: Simulation modelling of crop diseases using a susceptible-exposed-infectious-removed (seir) model. Available at: https://github.com/adamhsparks/epicrop.
Sparks, A., Esker, P. D., Bates, M., Dall’Acqua, W., Guo, Z., Segovia, V., et al. 2008. Ecology and epidemiology in R: Disease progress over time. The Plant Health Instructor.

References

Corrections

If you see mistakes or want to suggest changes, please create an issue on the source repository.

Reuse

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 ...".