ajdamico / convey

variance of distribution measures estimation of survey data
GNU General Public License v3.0
17 stars 7 forks source link

svyatk na.rm=T std err fails on linearized designs and also missings create error rather than NA for na.rm=F #370

Closed ajdamico closed 1 year ago

ajdamico commented 1 year ago
library(convey)
library(survey)
library(laeken)
data(eusilc) ; names( eusilc ) <- tolower( names( eusilc ) )

# linearized design

eusilc <- subset( eusilc , py010n > 0 )
eusilc[1,'py010n'] <- NA

des_eusilc <- svydesign( ids = ~rb030 , strata = ~db040 ,  weights = ~rb050 , data = eusilc )
des_eusilc <- convey_prep( des_eusilc )

# replicate-weighted design
des_eusilc_rep <- as.svrepdesign( des_eusilc , type = "bootstrap" )
des_eusilc_rep <- convey_prep( des_eusilc_rep )

# incorrectly throws error instead of returning NA
svyatk(~py010n, des_eusilc)
# incorrectly throws error instead of returning NA
svyatk(~py010n, des_eusilc_rep)

# incorrectly NA in standard error
svyatk(~py010n, des_eusilc,na.rm=T)
# correctly returns a value
svyatk(~py010n, des_eusilc_rep,na.rm=T)