In my pursuit of self learning the R programming language, I have mostly mastered the art of reading through CRAN documentation of R libraries as they are published. I have gone through everything from mediocre to very well documented sheets and anything in between. I am sharing one example of a very good function that was well documented in the 'survey' library by Dr. Thomas Lumley that for some reason I could not process and make work with my data initially. No finger pointing or anything like that here. It was merely my brain not readily able to wrap around the idea that the function passed another function in its arguments.
fig1: the svyby function in the 'survey' library by Thomas Lumley filled in with variables for my study |
However, I was unable to break through the library to find the software that I needed. First, I tried to use other functions and add to those snippets to see if I was doing something right, with no such luck. There was weeks of this going on before I finally discovered svyby.
Then when I discovered this code, the tildes threw me off. In many cases, calling the object or part of an object in R by quotations is usually how to satisfy arguments in functions. The use of the tilde is admittedly foreign to my eye as an R programmer. But I do not say that as a criticism as the writer of this package is part of the R core team. Maybe there's something in the 'survey' library that is truer than what we've all been doing in other countries? I'm not sure. It's just a different experience.
However, the use of the term "formula" in the CRAN documentation for slots 1, 2, and 4 threw me off once I realized that svyby is the function that I needed to break down descriptive statistics into subsets of the survey that I was using for my analysis. In some cases, useRs will need a formula to specify subsets in very particular form, as their survey sampling will be complex: this was not the case for me, as I had a very simply sampled survey from which to draw. Therefore, I did not need a formula. I could have substituted a different word in my head altogether for slots 1 and 2 (viz. vector). In terms of slot 4, this was easy enough to figure out when I realized what was needed for slots 1 and 2 in the arguments for svyby.
All of this did not come easy, but instead, it took weeks of problem solving, persistent reading, perspective changing, drilling through technical CRAN documentation and trying variations on code to get to results that worked. I can say that in the time that it took to understand the svyby function I learned more about myself, using functions as arguments, and my data than I thought possible. I am grateful to Dr. Thomas Lumley and the 'survey' package.
Comments
Post a Comment