ntiles.wtd: Weighted tiles

Description Usage Arguments Details Value Examples

Description

Breaks input vector into n groups. Returns the (optional weighted) tile of an individual observation in vector x.

Usage

1

Arguments

x

a numeric vector for which the quantiles are computed. Missing values are left as missing.

n

the number of desired sub groups to break vector x into.

weights

an optional vector of weights of x to be used in the computation of the tiles. Should be NULL or a numeric vector.

Details

Breaks vector x into n sub groups. The main difference with other tile functions (for instance ntile from dplyr) is that those functions break up vector x in exact equal size sub groups. Observations with the same value can end up in different tiles. In this function, observations with the same value always end up in the same tile, therefore sub groups may have different sizes. Especially when the weights argument is used. For a weighted tile function with the same group size, see for instance weighted_ntile from the grattan package.

When using a short-length vector (compared to the number of tiles) or with high variance weights, output may be different than anticipated.

Value

A vector of integers corresponding to the quantiles of vector x.

Examples

1
2
3
4
5
6
7
8
#Break up the income variable in the Mexican Income data set into 10 groups (tiles)
data(mex_inc_2008)

#unweighted tiles:
q <- ntiles.wtd(x=mex_inc_2008$income, n=10)

#weighted tiles:
qw <- ntiles.wtd(x=mex_inc_2008$income, n=10, weights=mex_inc_2008$factor)

ReneSchulenberg/dineq documentation built on May 14, 2019, 12:43 p.m.