Survey package/svyby source code help

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Survey package/svyby source code help

R help mailing list-2
Good day,

I was looking for some help with understanding a particular portion of the svyby source code.
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))).
Alternatively I invite explanation of how the SE values are created in the rval object on line 74.

the data entering svyby is from a svydesign.default object.

I am especially confused by the syntax in 57 - 59, which is not the primary question, but would appreciate any input.

I am new to R and this mailing list and do apologize for committing faux-pas.

Thanks in advance.
        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Survey package/svyby source code help

Ivan Krylov
On Tue, 11 Feb 2020 02:33:45 +0000
AndertechLLC--- via R-help <[hidden email]> 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 variable
named 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

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Survey package/svyby source code help

R help mailing list-2

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 <[hidden email]> wrote:

> On Tue, 11 Feb 2020 02:33:45 +0000
> AndertechLLC--- via R-help [hidden email] 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

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Survey package/svyby source code help

Ivan Krylov
On Tue, 11 Feb 2020 15:23:14 +0000
[hidden email] 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

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.