help for wridit and fridit(Roger Newson)

Generate weighted ridits

wridit varname [if] [in] [weight] , generate(newvarname)

[ by(varlist)
handedness(handedness) folded reverse percent float
]

fridit varname [if] [in] , generate(newvarname)

fframe(framename [, weightvar(varname) xvar(varname)] )

[ by(varlist)
handedness(handedness) folded reverse percent float
]

where handedness is

center | left | right

fweights, pweights, aweights, and iweights are allowed for wridit;
see weight.

Description

wridit inputs a variable and generates its weighted ridits.
If no weights are provided, then all weights are assumed equal to 1,
so unweighted ridits are generated.
Zero weights are allowed,
and imply that the ridits calculated for the observations with zero weights
will refer to the distribution of weights in the observations with nonzero weights.
fridit inputs a variable and generates its weighted foreign ridits,
with respect to a distribution identified by the data in a data frame.

Options for wridit and fridit

generate(newvarname) must be specified.
It specifies the name of the generated output variable,
containing the weighted ridits.

by(varlist) specifies a list of by-variables.
If by() is specified,
then the weighted ridits are computed within by-groups.

handedness(handedness) specifies the handedness of the ridits to be generated.
It may be center (the default), left, or right.
If left is specified, then the left-continuous ridit is generated.
If right is specified, then the right-continuous ridit is generated.
If center is specified (or the handedness() option is absent),
then the standard center ridits
(equal in each observation to the mean of the left ridit and the right ridit)
are generated.

folded specifies that the weighted ridits generated will be folded ridits.
A folded ridit, on a proportion scale from -1 to 1,
is defined as 2*R-1,
where R is the corresponding unfolded ridit (on a proportion scale from 0 to 1).

reverse specifies that the weighted ridits will be reverse ridits,
based on reverse cumulative probabilities.

percent specifies that the weighted ridits will be generated on a percentage scale
from 0 to 100,
or from -100 to 100 if folded is specified.
If percent is not specified,
then the weighted ridits will be generated on a proportion scale from 0 to 1,
or from -1 to 1 if folded is specified.

float specifies that the weighted ridits will be generated with storage type float.
If float is not specified, then the weighted ridits will be generated
with storage type double.
The generated variable will then be compressed,
if that can be done without loss of information.

Options for fridit only

fframe(framename [, weightvar(varname xvar(varname)] )
must be specified.
It specifies an existing data frame,
knowwn as the foreign frame,
and specifying a distribution with respect to which the ridits will be generated.
This data frame must contain a variable with the same mode (numeric or string)
as the input variable,
with the name specified by the xvar() option if present
and the same name as the input variable otherwise,
plus variables with the same names and modes as the by() variables
(if a by() option is specified).
It may also contain a weight variable, specified by the weightvar() suboption,
containing weights to specify a frequency distribution for the variable
with the same name as th input variable.
If a weightvar() option is not specified,
then all weights are assumed to be 1.
The generated variable will contain foreign ridits,
which are ridits with respect to the distribution specified
by the variable of the same name in the foreign frame,
and by the weight variable in the foreign frame (if specified).

Methods and formulas

Ridits were introduced by Bross (1958).
Given a variable X,
the unfolded ridit for a value x is equal to the probability that X<x
plus half the probability that X==x.
The folded ridit for x, introduced by Brockett and Levene (1977),
is equal to the probability that X<x
minus the probability that X>x.
These ridits are classed as center ridits.
The unfolded left ridit is the probability that X<x,
and the folded left ridit is the probability that X<x
minus the probability that X>=x.
The unfolded right ridit is the probability that X<=x,
and the folded right ridit is the probability that X<=x
minus the probability that X>x.
Note that the center ridit is the mean of the left ridit and the right ridit,
whether unfolded or folded ridits are generated.
Note, also, that the unfolded right ridit
is also known as the sample cumulative distribution function.

Foreign ridits (computed by fridit)
are defined in the same way as the native ridits generated by wridit,
except that they are defined with respect to the distribution of a variable Y,
possibly in another population,
instead of with respect to the distribution of X.
For instance, the unfolded ridit for a value x is equal to the probability that Y<x
plus half the probability that Y==x.
The distribution of the variable Y is specified in the foreign frame.

Remarks

Nicholas J. Cox introduced an egen function ridit(),
computing unweighted unfolded center ridits,
as part of the egenmore package,
downloadable from SSC.

Examples

. wridit mpg, gene(wrid1)

. wridit mpg [pwei=weight], gene(wrid2) by(foreign)

The following advanced example demonsttrates fridit in the auto data.
We first use the SSC package xcontract
to create a data frame frankie,
with 1 observation per value of mpg present in the US car models,
and data on the frequencies and percents of these values in the US car models.
We then use fridit to computse foreign ridits of mpg for all car models,
with respect to the frequency distribution of mpg in the US car models,
specified by the weight variable _freq in the frame frankie.
These ridits are stored in a variable jenny.
We then use xcontract to list the values of mpg,
and the corresponding ridit value stored in jenny,
in the US and non-US car models.
Note that some of the foreign ridits of mpg values in the non-US car models
have value 1,
corresponding to values of mpg higher than any values inn the US car models.

. sysuse auto, clear

. desc

. xcontract mpg if foreign==0, frame(frankie, replace) list(, abbr(32))

. fridit mpg, ffr(frankie, weightvar(_freq)) gene(jenny)

. xcontract mpg jenny, by(foreign) list(, abbr(32))

References

Brockett, P. L., and Levene, A. 1977.
On a characterization of ridits.
The Annals of Statistics 5(6): 1245-1248.

Bross, I. D. J. 1958.
How to use ridit analysis.
Biometrics 14(1): 18-38.

Author

Roger Newson, King's College London, UK.

Email: roger.newson@kcl.ac.uk

Also see

Manual: [D] egen

On-line: help for egen

help for egenmore, xcontract if installed