A@dertechLLC m@iii@g oii proto@m@ii@com
2020-Feb-11 15:23 UTC
[R] Survey package/svyby source code help
Thank you for responding. I am truly grateful. Apologies for omitting evident and pertinent information. I am using 3.36. I will update to 3.37. I did not notice the newer version. I realize I needed to be more specific. The attr(, "var") that I am interested in is displayed with str(results) after the results object is declared. First line of the subject code looks like: results <- (if (multicore) parallel::mcapply else lapply)(uniques, function(i){.... How that line functions without error is beyond me, but minor to my objective. Disclosing my prime goal, I am trying to produce the same values generated by the confint function, which receives the standard error values from this svyby function. I am trying to replicate the standard error calculation in R and use it in a known program called Tableau. If any other information is needed please let me know. My sincerest gratitude. ??????? Original Message ??????? On Tuesday, February 11, 2020 9:42 AM, Ivan Krylov <krylov.r00t at gmail.com> wrote:> On Tue, 11 Feb 2020 02:33:45 +0000 > AndertechLLC--- via R-help r-help at r-project.org wrote: > > > When debugging the code I am not following the generation of values > > in the results object attr(*, "var")" after line 57 completes. These > > values are fed into line 74 (rval <- t(sapply(results, unwrap))). > > Which version of the survey package you have in mind? I took a look at > the latest version available on CRAN (3.37 at the time of this post, > []) and the R/surveyby.R file has somewhat different code on lines 57 > and 74. > In particular, attr(, "var") is assigned much later, from variablenamed covmat.mat, which is also computed later than line 74. > > ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- > > Best regards, > Ivan > > [*] https://cran.r-project.org/src/contrib/survey_3.37.tar.gz
On Tue, 11 Feb 2020 15:23:14 +0000 AndertechLLC at protonmail.com wrote:> The attr(, "var") that I am interested in is displayed with > str(results) after the results object is declared. First line of the > subject code looks like: > > results <- (if (multicore) parallel::mcapply else lapply)(uniques, > function(i){....'if' returns whatever the taken branch returns (it is documented in ?'if', section "Value"). The rest of the statement applies the function FUN (passed as argument to svyby) to the data (passed as `formula` argument), so the "var" attribute you are looking for in fact comes from the FUN invocation and not from svyby itself. Most examples from ?svyby use FUN=svymean, so perhaps this is where you should be going next. Make sure to check out R-Intro [*] to avoid common pitfalls when working with methods in R. -- Best regards, Ivan [*] https://cran.r-project.org/doc/manuals/r-release/R-intro.html#Object-orientation