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 )
# concave Chakravarty richness measure
# higher g= parameters tend toward headcount ratio, richness threshold fixed
svyrich(~eqincome, des_eusilc, type_measure = "Cha" , g=3, abs_thresh=30000)
# g=1 parameter computes the richness gap index, richness threshold fixed
svyrich(~eqincome, des_eusilc, type_measure = "Cha" , g=1, abs_thresh=30000)
# higher g= parameters tend toward headcount ratio, richness threshold equal to the median
svyrich(~eqincome, des_eusilc, type_measure = "Cha" , g=3, type_thresh= "relq" )
# g=1 parameter computes the richness gap index, richness threshold equal to the median
svyrich(~eqincome, des_eusilc, type_measure = "Cha" , g=1, type_thresh= "relq" )
# higher g= parameters tend toward headcount ratio, richness threshold equal to the mean
svyrich(~eqincome, des_eusilc, type_measure = "Cha" , g=3, type_thresh= "relm" )
# g=1 parameter computes the richness gap index, richness threshold equal to the mean
svyrich(~eqincome, des_eusilc, type_measure = "Cha" , g=1, type_thresh= "relm" )
# using svrep.design:
# higher g= parameters tend toward headcount ratio, richness threshold fixed
svyrich(~eqincome, des_eusilc_rep, type_measure = "Cha" , g=3, abs_thresh=30000 )
# g=1 parameter computes the richness gap index, richness threshold fixed
svyrich(~eqincome, des_eusilc_rep, type_measure = "Cha" , g=1, abs_thresh=30000 )
# higher g= parameters tend toward headcount ratio, richness threshold equal to the median
svyrich(~eqincome, des_eusilc_rep, type_measure = "Cha" , g=3, type_thresh= "relq" )
# g=1 parameter computes the richness gap index, richness threshold equal to the median
svyrich(~eqincome, des_eusilc_rep, type_measure = "Cha" , g=1, type_thresh= "relq" )
# higher g= parameters tend toward headcount ratio, richness threshold equal to the mean
svyrich(~eqincome, des_eusilc_rep, type_measure = "Cha" , g=3, type_thresh= "relm" )
# g=1 parameter computes the richness gap index, richness threshold equal to the mean
svyrich(~eqincome, des_eusilc_rep, type_measure = "Cha" , g=1, type_thresh= "relm" )
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 )
# higher g= parameters tend toward headcount ratio, richness threshold fixed
svyrich(~eqincome, dbd_eusilc, type_measure = "Cha" , g=3, abs_thresh=30000 )
# g=1 parameter computes the richness gap index, richness threshold fixed
svyrich(~eqincome, dbd_eusilc, type_measure = "Cha" , g=1, abs_thresh=30000 )
# higher g= parameters tend toward headcount ratio, richness threshold equal to the median
svyrich(~eqincome, dbd_eusilc, type_measure = "Cha" , g=3, type_thresh= "relq" )
# g=1 parameter computes the richness gap index, richness threshold equal to the median
svyrich(~eqincome, dbd_eusilc, type_measure = "Cha" , g=1, type_thresh= "relq" )
# higher g= parameters tend toward headcount ratio, richness threshold equal to the mean
svyrich(~eqincome, dbd_eusilc, type_measure = "Cha" , g=3, type_thresh= "relm" )
# g=1 parameter computes the richness gap index, richness threshold equal to the mean
svyrich(~eqincome, dbd_eusilc, type_measure = "Cha" , g=1, type_thresh= "relm" )
dbRemoveTable( conn , 'eusilc' )
dbDisconnect( conn , shutdown = TRUE )
}
Run the code above in your browser using DataLab