4

I want to know how you generate estimates of standard error without using survey design for the given examples.

library(survey)

data(api)

dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)

example 1

(total_enroll_mean=svymean(~enroll,by=~stype,design= dstrat, na.rm=TRUE))

        mean     SE
 enroll 595.28 18.509

example 2

(total_enroll_total=svytotal(~enroll,by=~stype,design= dstrat, na.rm=TRUE))

       total     SE
enroll 3687178 114642

example 3

(stype_enroll_mean=svyby(~enroll,by=~stype,design= dstrat, na.rm=TRUE,svymean))

stype  enroll       se
E      416.78    16.41740

H      1320.70   91.70781

M      832.48    54.52157

example 4

(stype_enroll_total=svyby(~enroll,by=~stype,design= dstrat, na.rm=TRUE,svytotal)

stype     enroll       se
E        1842584.3     72581.33

H         997128.5     69239.40

M         847464.7     55502.96

So basically I want to generate the standard errors for all 4 examples manually in R instead of using the survey package or srvyr package or any other survey related package. The standard errors that are generated manually for svymean and svytotal should match the standard errors generated by using the survey package in all examples given above.

Sid Sath
  • 41
  • 4
  • 1
    hi, you can type `debug(survey::svymean)` to look at each calculation, step by step, that occurs when you type `svymean(...)` – Anthony Damico Aug 21 '18 at 23:41
  • 1
    Hi, thanks for response. But I want the mathematical formula used by the survey package to calculate the standard error, so that I can create my own function using Base R functions to calculate the estimate of standard error. – Sid Sath Aug 22 '18 at 03:42

1 Answers1

0

I would recommend looking at the source code on github where you can see how the functions are defined and what exactly is done to calculate the standard errors from the survey designs you mentioned.

https://github.com/cran/survey/blob/master/R/survey.R

  • 2
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 09 '21 at 13:02