IQSS / Zelig

A statistical framework that serves as a common interface to a large range of models

Home Page:http://zeligproject.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Zelig-normal-survey incorrectly passes the weights to both svydesign and svyglm

chiungming opened this issue · comments

For some reason Zelig passes the weights to both svydesign and svyglm. Is there a way to prevent Zelig from passing the weights to svyglm?

data(api)

zelig(meals ~ yr.rnd, model = "normal.survey", id = ~dnum, weights = ~api00, data = apiclus1) 

## Warning: Not all features are available in Zelig Survey.
## Consider using surveyglm and setx directly.
## For details see: <http://docs.zeligproject.org/articles/to_zelig.html>.

## How to cite this model in Zelig:
##   Nicholas Carnes. 2019.
##   normal-survey: Normal Regression for Continuous Dependent Variables with Survey Weights
##   in Christine Choirat, Christopher Gandrud, James Honaker, Kosuke Imai, Gary King, and Olivia Lau,
##   "Zelig: Everyone's Statistical Software," http://zeligproject.org/

## Model: 
## 
## Call:
## z5$zelig(formula = meals ~ yr.rnd, data = apiclus1, ids = ~dnum, 
##     weights = ~api00)
## 
## Survey design:
## survey::svydesign(data = data, ids = ids, probs = probs, strata = strata, 
##     fpc = fpc, nest = nest, check.strata = check.strata, weights = localWeights)
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)
## (Intercept)   41.949      4.854   8.642 9.51e-07
## yr.rndYes     38.622      4.411   8.755 8.22e-07
## 
## (Dispersion parameter for gaussian family taken to be 381405.3)
## 
## Number of Fisher Scoring iterations: 2
## 
## Next step: Use 'setx' method

api_design <- svydesign(id = ~dnum, weights = ~api00, data = apiclus1)

svyglm(meals ~ yr.rnd, api_design, family = gaussian("identity"), weights = api00) %>% 
summary()

## 
## Call:
## svyglm(formula = meals ~ yr.rnd, design = api_design, family = gaussian("identity"), 
##     weights = api00)
## 
## Survey design:
## svydesign(id = ~dnum, weights = ~api00, data = apiclus1)
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   41.949      4.854   8.642 9.51e-07 ***
## yr.rndYes     38.622      4.411   8.755 8.22e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for gaussian family taken to be 381405.3)
## 
## Number of Fisher Scoring iterations: 2

svyglm(meals ~ yr.rnd, api_design, family = gaussian("identity")) %>% summary()

## 
## Call:
## svyglm(formula = meals ~ yr.rnd, design = api_design, family = gaussian("identity"))
## 
## Survey design:
## svydesign(id = ~dnum, weights = ~api00, data = apiclus1)
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   45.267      5.262   8.603 1.00e-06 ***
## yr.rndYes     36.649      4.577   8.007 2.21e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for gaussian family taken to be 621.4498)
## 
## Number of Fisher Scoring iterations: 2