I am a beginner user of R. I am using a national survey to test what variables influence the participation in complementary pensions (the participation in complementary pension is voluntary in my country).

Since the dependent variable is a dummy (1 if the person participate and 0 otherwise) I want to run a logit or probit regression; moreover I want to run a fixed effect regression since I subset the survey in order to have only the individuals interviewed more than one time.

The data frame is composed by several social and economical variables and it also contain a variable "weight" which is the survey weight (they are weighting coefficients to adjust the results of the sample to the national data).

 family pers sex income pension
1     10    1   F  10000       1
2     20    1   F  20000       1
3     20    2   M  40000       0
4     30    1   M  25000       0
5     30    2   F  50000       0
6     40    1   M  60000       1

pers is the component of the family and pension takes 1 if the person participate to complementary pension (it is a simplification of the original survey, which contains more variables and observation (around 22k observations)).

I know how to use the plm and glm functions for a fixed effect or logit regression; in this case I don't know what to do since I need to take account of the survey weights.

I used the svydesign function to "weight" the data frame:

df1 <- svydesign(ids=~1, data=df, weights=~dfweight)

I used ids=~1 because there isn't a "cluster" variable in the survey (I know that the towns are ramdomly selected and then individuals are ramdomly selected, but there isn't a variable that indicate the stratification).

At this point I am lost: I don't know if it is right to use the survey package and then what function use to run the regression, or there is a way to use the plm or glm functions taking account of the weights.

I tried so hard to search a solution on the website but if you could give me an answer I'd be glad.

  • $\begingroup$ Ideally, id would specify the towns. If you use id=~1 when it's actually cluster sampled the standard errors will tend to be wrong (usually, but not always, underestimated). $\endgroup$ Jun 20, 2020 at 7:13

1 Answer 1


I don't think it's possible to use sample weights with glm. I don't know about plm, but it seems to me that it's mostly about analyzing panel data (repeated cross-sectional surveys with the same cohort).

You can use the svyglm()function of the survey package:

df1 <- svydesign(ids=~1, data=df, weights=~dfweight)
model1 <- svyglm(y ~ x1 + x2, design = df1, data=df, family=quasibinomial)

The quasibinomial is used instead of the bionomial distribution to account for that your dependent variables will be different from 0 and 1 because of the weighting.

  • 1
    $\begingroup$ Actually, the quasibinomial() function is used with svyglm() only to suppress an annoying warning that you get with binomial(). The results are identical. $\endgroup$ Jun 20, 2020 at 7:12
  • $\begingroup$ Ah, I didn't know that. Thanks! $\endgroup$
    – JonB
    Jun 20, 2020 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.