library(survey)
library(laeken)
data(eusilc) ; names( eusilc ) <- tolower( names( eusilc ) )
# linearized design
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 )
# filter positive incomes
des_eusilc <- subset( des_eusilc , eqincome > 0 )
des_eusilc_rep <- subset( des_eusilc_rep , eqincome > 0 )
# poverty threshold fixed
svywatts(~eqincome, des_eusilc , abs_thresh=10000)
# poverty threshold equal to arpt
svywatts(~eqincome, des_eusilc , type_thresh= "relq", thresh = TRUE)
# poverty threshold equal to 0.6 times the mean
svywatts(~eqincome, des_eusilc , type_thresh= "relm" , thresh = TRUE)
# using svrep.design:
# poverty threshold fixed
svywatts(~eqincome, des_eusilc_rep , abs_thresh=10000)
# poverty threshold equal to arpt
svywatts(~eqincome, des_eusilc_rep , type_thresh= "relq", thresh = TRUE)
# poverty threshold equal to 0.6 times the mean
svywatts(~eqincome, des_eusilc_rep , type_thresh= "relm" , thresh = TRUE)
if (FALSE) {
# database-backed design
library(RSQLite)
library(DBI)
dbfile <- tempfile()
conn <- dbConnect( RSQLite::SQLite() , dbfile )
dbWriteTable( conn , 'eusilc' , eusilc )
dbd_eusilc <-
svydesign(
ids = ~rb030 ,
strata = ~db040 ,
weights = ~rb050 ,
data="eusilc",
dbname=dbfile,
dbtype="SQLite"
)
dbd_eusilc <- convey_prep( dbd_eusilc )
# filter positive incomes
dbd_eusilc <- subset( dbd_eusilc , eqincome > 0 )
# poverty threshold fixed
svywatts(~eqincome, dbd_eusilc , abs_thresh=10000)
# poverty threshold equal to arpt
svywatts(~eqincome, dbd_eusilc , type_thresh= "relq", thresh = TRUE)
# poverty threshold equal to 0.6 times the mean
svywatts(~eqincome, dbd_eusilc , type_thresh= "relm" , thresh = TRUE)
dbRemoveTable( conn , 'eusilc' )
dbDisconnect( conn , shutdown = TRUE )
}
Run the code above in your browser using DataLab