Category: rblogs

  • Creating an n x n autocorrelation matrix

    Creating an n x n autocorrelation matrix

    Between covid-19 news and announcements of imminent Russia-Ukraine wars I needed a bit of a distraction. Sooo, here it is how to create an n x n autocorrelation matrix based on a correlation rho, with a simple 5 x 5 example in R: This produces the following output: [crayon-63e046cc17e33528228366/] How does this work? Starting from […]

  • The beauty of code vectorisation

    The beauty of code vectorisation

    I came across this problem in Twitter: The basic pieces of the problem are: We need to generate pseudorandom numbers with an identical distribution, add them up until they go over 1 and report back how many numbers we needed to achieve that condition. Well, do the above “quite a few times” and take the […]

  • Recreational programming

    Recreational programming

    I think programming, aka coding, is a fun activity. We are solving a problem subject to a set of constraints that can be time, memory, quantity of code, language, etc. Besides being a part of my work, coding is also a good distraction when doing it for the sake of it. In this type of […]

  • Implementing a model as an R package

    Implementing a model as an R package

    In our research group we often have people creating statistical models that end up in publications but, most of the time, the practical implementation of those models is lacking. I mean, we have a bunch of barely functioning code that is very difficult to use in a reliable way in operations of the breeding programs. […]

  • Reading a folder with many small files

    Reading a folder with many small files

    One of the tools we use in our research is NIR (Near-Infrared Spectroscopy), which we apply to thousands of samples to predict their chemical composition. Each NIR spectrum is contained in a CSV text file with two numerical columns: wavelength and reflectance. All files have the same number of rows (1296 in our case), which […]