Unexpected results and defensive coding

19 June2018

Defensive coding is an important part of Good Programming Practice (GPP) and has been defined as "an approach to programming intended to anticipate future changes of the data that might influence the coding algorithms. Ideally programs should be written in such a way that they will continue to work correctly in case of new or unexpected data values which did not exist at the time the code was developed" [ref]. This is especially important if we develop the code on a subset of data, so the analyses can be generated as soon as the final data become available.

Last-observation-carried-forward

17 June 2018

Last-observation-carried-forward is no longer a preferred method of imputation. It is considered quite crude and susceptible to bias, especially in e.g. Alzheimer's disease (EMA points to consider on missing data), and more sophisticated methods are favoured such as multiple imputation and mixed modelling when there are repeated measures over time. However, the code once used routinely to carry the last observation forward may be useful in analogous situations. Barbalau has described different ways of coding LOCF [ref]. I prefer to use the retain statement as follows: