Learn R Programming

survey (version 1.0)

svyglm: Survey-weighted generalised linear models.

Description

Fit a generalised linear model to data from a complex survey design, with inverse-probability weighting and with standard errors corrected for cluster sampling.

Usage

svyglm(formula, design, ...)
## S3 method for class 'svyglm':
summary(object, correlation = FALSE,  ...)

Arguments

formula
Model formula
design
survey.design object. Must contain all variables in the formula
...
Other arguments passed to glm or summary.glm
object
A svyglm object
correlation
Include the correlation matrix of parameters?

Value

  • An object of class svyglm.

Details

Standard errors for cluster-sampled designs are computed using a linearisation estimate (equivalent to the Huber/White sandwich formula in GEEs). Most of these computations are done in svyCprod.

See Also

svydesign, glm, svyCprod, svy.varcoef

Examples

Run this code
## Independent sampling
  df<-data.frame(x=rnorm(1000),z=rep(0:4,200))
  df$y<-with(df, 3+3*x*z)
  df$p<-with(df, exp(x)/(1+exp(x)))
  mpop<-lm(y~x+z, data=df) 
  xi<-rbinom(1000,1,df$p)
  sdf<-df[xi==1,]

  dxi<-svydesign(~0,~p,data=sdf)
  m<-svyglm(y~x+z,data=sdf,family="gaussian",design=dxi)
  m1<-lm(y~x+z, data=sdf)

  summary(m1) ##wrong
  summary(m)  ##right
  summary(mpop) ##whole population

  ##cluster sampling
  df$id<-rep(1:250,each=4)
  df$clustp<-by(df,list(df$id),function(d) min(exp(d$x*d$z)/(1+exp(d$x*d$z))))[df$id]
  mpop<-lm(y~x+z, data=df) 

  xi<-rbinom(250,1,df$clustp[4*(1:250)])
  sdf<-df[xi[df$id]==1,]

  dxi<-svydesign(~id,~clustp,data=sdf)
  m<-svyglm(y~x+z,data=sdf,family="gaussian",design=dxi)
  m1<-lm(y~x+z,data=sdf)
 
  summary(m1) ##wrong
  summary(m)  ##right
  summary(mpop) ##whole population

Run the code above in your browser using DataLab