Description Usage Arguments Details Value Note Author(s) References See Also Examples
View source: R/svyzengacurve.R
Estimate the Zenga curve, an inequality graph
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | svyzengacurve(formula, design, ...)
## S3 method for class 'survey.design'
svyzengacurve(
formula,
design,
quantiles = seq(0, 1, 0.1),
empirical = FALSE,
plot = TRUE,
add = FALSE,
curve.col = "red",
ci = TRUE,
alpha = 0.05,
na.rm = FALSE,
...
)
## S3 method for class 'svyrep.design'
svyzengacurve(
formula,
design,
quantiles = seq(0, 1, 0.1),
empirical = FALSE,
plot = TRUE,
add = FALSE,
curve.col = "red",
ci = TRUE,
alpha = 0.05,
na.rm = FALSE,
...
)
## S3 method for class 'DBIsvydesign'
svyzengacurve(formula, design, ...)
|
formula |
a formula specifying the income variable |
design |
a design object of class |
... |
additional arguments passed to |
quantiles |
a sequence of probabilities that defines the quantiles sum to be calculated |
empirical |
Should an empirical Zenga curve be estimated as well? Defaults to |
plot |
Should the Zenga curve be plotted? Defaults to |
add |
Should a new curve be plotted on the current graph? |
curve.col |
a string defining the color of the curve. |
ci |
Should the confidence interval be plotted? Defaults to |
alpha |
a number that especifies de confidence level for the graph. |
na.rm |
Should cases with missing values be dropped? Defaults to |
WARNING: this is an experimental version. Use with caution.
You must run the convey_prep
function on your survey design object immediately after creating it with the svydesign
or svrepdesign
function.
Notice that the 'empirical' curve is observation-based and is based on the Lorenz curve formula actually used to calculate the Gini index. On the other hand, the quantile-based curve is used to estimate the complement of the ratio between the means, SEs and confidence intervals.
This way, as the number of quantiles of the quantile-based function increases, the quantile-based curve approaches the observation-based curve.
Object of class "svyquantile
", which are vectors with a "quantiles
" attribute giving the complement of the ratio between the lower and upper means,
and a "SE
" attribute giving the standard errors of the estimates.
This function is experimental and is subject to changes in later versions.
Guilherme Jacob, Djalma Pessoa and Anthony Damico
Marcella Polisicchio and Francesco Porro (2011). A Comparison Between Lorenz L(P) Curve and Zenga I(P) Curve. Statistica Applicata, v. 21, n. 3-4, 289-301.
Matti Langel (2012). Measuring inequality in finite population sampling. PhD thesis. URL http://doc.rero.ch/record/29204.
Jean-Claude Deville (1999). Variance estimation for complex statistics and estimators: linearization and residual techniques. Survey Methodology, 25, 193-203, URL http://www5.statcan.gc.ca/bsolc/olc-cel/olc-cel?lang=eng&catno=12-001-X19990024882.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | 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 )
svyzengacurve( ~eqincome , des_eusilc, alpha = .01 )
# replicate-weighted design
des_eusilc_rep <- as.svrepdesign( des_eusilc , type = "bootstrap" )
des_eusilc_rep <- convey_prep( des_eusilc_rep )
svyzengacurve( ~eqincome , des_eusilc_rep, alpha = .01 )
## Not run:
# linearized design using a variable with missings
svyzengacurve( ~py010n , des_eusilc, alpha = .01 )
svyzengacurve( ~py010n , des_eusilc, alpha = .01, na.rm = TRUE )
# demonstration of `curve.col=` and `add=` parameters
svyzengacurve( ~eqincome , des_eusilc, alpha = .05 , add = TRUE , curve.col = 'green' )
# replicate-weighted design using a variable with missings
svyzengacurve( ~py010n , des_eusilc_rep, alpha = .01 )
svyzengacurve( ~py010n , des_eusilc_rep, alpha = .01, na.rm = TRUE )
# 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 )
svyzengacurve( ~eqincome , dbd_eusilc, alpha = .01 )
# highlighting the difference between the quantile-based curve and the empirical version:
svyzengacurve( ~eqincome , dbd_eusilc, seq(0,1,.1), empirical = TRUE, curve.col = "green" )
svyzengacurve( ~eqincome , dbd_eusilc, seq(0,1,.1), alpha = .01, add = TRUE )
legend( "bottomleft", c("Quantile-based", "Empirical"), lwd = c(1,1), col = c("red", "green"))
# as the number of quantiles increases, the difference between the curves gets smaller
svyzengacurve( ~eqincome , dbd_eusilc, seq(0,1,.01), empirical = TRUE, curve.col = "green" )
svyzengacurve( ~eqincome , dbd_eusilc, seq(0,1,.01), alpha = .01, add = TRUE )
legend( "bottomleft", c("Quantile-based", "Empirical"), lwd = c(1,1), col = c("red", "green"))
dbRemoveTable( conn , 'eusilc' )
dbDisconnect( conn , shutdown = TRUE )
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.