help for logistic_scores

Logistic scores from grade variables

logistic_scores
varname
[weight]
[if] [in]
,
generate(newvar)
[
symmetric
tabdisp_options
]

fweights and aweights are allowed.

Description

logistic_scores calculates logistic scores in the sense
of Mosteller and Tukey (1977) from a graded ordinal variable.

Remarks

For concreteness consider a graded ordinal variable with
possible values 1, 2, 3, 4, 5. Here the numbering conveys order but
strictly nothing else. In particular, equal spacing is a convention for
convenience and not meant to imply anything else. Graded variables like
these abound in assessment of movies, hotels, courses, teachers, and
much else.

If you have an ordinal variable expressed only as text (e.g.
"strongly disagree", ..., "strongly agree") such a variable should first
be mapped to consecutive integers. See help on label and
encode.

Suppose that we calculate proportions of the data at each grade,
say p_1, p_2, p_3, p_4, p_5.
Given those we can calculate cumulative proportions
P_1 = p_1,
P_2 = P_1 + p_2,
P_3 = P_2 + p_3,
P_4 = P_3 + p_4,
P_5 = P_4 + p_5.
The last is always identically 1, but otherwise we have 4 breakpoints
P_1 to P_4.

More generally, J grades running j = 1,...,J
lead to that many probabilities p_j and that many cumulative
probabilities P_j. Define additionally P_0 := 0.

The idea of logistic scores is to invoke a latent variable that
has a standard logistic distribution with mean zero and quantile
function logit P = ln [P / (1 - P)] = ln P - ln (1
- P). Such a distribution is conveniently simple and tractable. It
has mean 0, skewness 0, and kurtosis 4.2. Incidentally in mean,
skewness and kurtosis the logistic resembles Student's t
distribution with 9 df.

Given that, the distribution is considered divided into slices
by breakpoints on the cumulative probability scale P_1 to
P_J-1 with corresponding breakpoints on the logit scale
defined by logit P. The logistic scores are the centres of gravity
of each slice. The centre of gravity of a slice bounded by lower limit
P_j-1 =: A and upper limit P_j =:
B is [phi(B) - phi(A)] / (B - A) where
phi(x) is x ln x - (1 - x) ln (1 - x), noting
that 0 ln 0 is to be returned as 0.

The derivation of the precise recipe for centres of gravity
is not given by Mosteller and Tukey (1977), perhaps as being too
trivial for mathematical readers and too technical for other readers.
The argument is sketched in an accompanying .pdf document.

Options

generate() is a required option and specifies the name of
a new variable to hold the logistic scores. The forms
generate(float newvar) and
generate(double newvar)
are allowed to specify storage type.

symmetric insists on scores symmetric about a middle
value. For example, with five levels, scores for 1 and 5 are identical,
as are those for 2 and 4; or with six levels, scores for 1 and 6 are
identical, as are those for 2 and 5 and for 3 and 4. Calculation
proceeds by averaging the corresponding probabilities and using each
average twice instead of the original probabilities.

tabdisp_options are options of tabdisp.

Examples

. * repair record

. sysuse auto, clear

. logistic_scores rep78, gen(lgstc)

. logistic_scores rep78, symmetric gen(lgstc_s)

. * another way to do it

. local text : variable label rep78

. contract rep78, nomiss

. logistic_scores rep78 [fw=_freq], gen(lgstc)

. gen cufreq = sum(_freq)

. gen cuprob = cufreq / cufreq[_N]

. gen X = logit(cuprob)

. set obs 1000

. range x -6 6

. gen density = exp(x) / (1 + exp(x))^2

. gen where = -0.007

. foreach y in 0.05 0.1 0.15 0.2 0.25 {

. local ylabel `ylabel' `y' "`y'"

. }

. twoway mspline density x, color(black) lw(thick) bands(200) ///

|| area density x if x < X[1], color(red*0.8) ///

|| area density x if inrange(x, X[1], X[2]), color(red*0.4) ///

|| area density x if inrange(x, X[2], X[3]), color(white) ///

|| area density x if inrange(x, X[3], X[4]), color(blue*0.4) ///

|| area density x if x > X[4], color(blue*0.8) ///

|| scatter where lgstc, ms(T) msize(large) mc(black) ///

mlabel(rep78) mlabpos(6) mlabcolor(black) mlabsize(medium) ///

|| scatteri 0 -6 0 6, recast(line) lcolor(black) ysc(r(-0.025, .)) ///

ytitle(density) yla(0 `ylabel' ) ///

xtitle(logistic scores) xla(-6/6) legend(off) ///

subtitle("`text'", place(left)) ///

note("cumulative probabilities define slices;" "centres of gravity define scores") ///

name(G1, replace)

. * Mosteller and Tukey 1977 p.106

. clear

. set obs 5

. gen MT106 = _n

. label def MT106 1 A 2 B 3 C 4 D 5 E

. label val MT106 MT106

. decode MT106, gen(letters)

. gen freq = real(word("127 497 3243 231 74", MT106))

. logistic_scores MT106 [fw=freq], gen(lgstc_MT)

. gen cufreq = sum(freq)

. gen cuprob = cufreq / cufreq[_N]

. gen X = logit(cuprob)

. set obs 1000

. range x -6 6

. gen density = exp(x) / (1 + exp(x))^2

. gen where = -0.007

. foreach y in 0.05 0.1 0.15 0.2 0.25 {

. local ylabel `ylabel' `y' "`y'"

. }

. twoway mspline density x, color(black) lw(thick) bands(200) ///

|| area density x if x < X[1], color(red*0.8) ///

|| area density x if inrange(x, X[1], X[2]), color(red*0.4) ///

|| area density x if inrange(x, X[2], X[3]), color(white) ///

|| area density x if inrange(x, X[3], X[4]), color(blue*0.4) ///

|| area density x if x > X[4], color(blue*0.8) ///

|| scatter where lgstc_MT, ms(T) msize(large) mc(black) ///

mlabel(letters) mlabpos(6) mlabcolor(black) mlabsize(medium) ///

|| scatteri 0 -6 0 6, recast(line) lcolor(black) ysc(r(-0.025, .)) ///

ytitle(density) yla(0 `ylabel' ) ///

xtitle(logistic scores) xla(-6/6) legend(off) ///

subtitle("Mosteller and Tukey 1977 p.106", place(left)) ///

note("cumulative probabilities define slices;" "centres of gravity define scores") ///

name(G2, replace)

. * Lake District cirques Evans and Cox 1995; Evans 2015

. clear

. set obs 5

. gen grade = _n

. * reverses 1995 order

. label def grade 1 poor 2 marginal 3 definite 4 "well-defined" 5 classic

. label val grade grade

. decode grade, gen(words)

. gen freq = real(word("35 36 44 31 11", grade))

. logistic_scores grade [fw=freq], gen(lgstc_grade)

. gen cufreq = sum(freq)

. gen cuprob = cufreq / cufreq[_N]

. gen X = logit(cuprob)

. set obs 1000

. range x -6 6

. gen density = exp(x) / (1 + exp(x))^2

. gen where = -0.007

. foreach y in 0.05 0.1 0.15 0.2 0.25 {

. local ylabel `ylabel' `y' "`y'"

. }

. twoway mspline density x, color(black) lw(thick) bands(200) ///

|| area density x if x < X[1], color(red*0.8) ///

|| area density x if inrange(x, X[1], X[2]), color(red*0.4) ///

|| area density x if inrange(x, X[2], X[3]), color(white) ///

|| area density x if inrange(x, X[3], X[4]), color(blue*0.4) ///

|| area density x if x > X[4], color(blue*0.8) ///

|| scatter where lgstc_grade, ms(T) msize(large) mc(black) ///

mlabel(words) mlabpos(6) mlabcolor(black) mlabsize(small) ///

|| scatteri 0 -6 0 6, recast(line) lcolor(black) ysc(r(-0.025, .)) ///

ytitle(density) yla(0 `ylabel' ) ///

xtitle(logistic scores) xla(-6/6) legend(off) ///

subtitle("Lake District cirques", place(left)) ///

note("cumulative probabilities define slices;" "centres of gravity define scores") ///

name(G3, replace)

Author

Nicholas J. Cox, Durham University, U.K.

n.j.cox@durham.ac.uk

References

Balakrishnan, N. (ed.) 1992.
Handbook of the Logistic Distribution.
New York: Marcel Dekker.

Evans, I.S. 2015. The Lake District cirque inventory: updated. In
McDougall, D.A. and Evans, D.J.A. (eds)
The Quaternary of the Lake District: Field Guide.
London: Quaternary Research Association, 83-95.

Evans, I.S. and Cox, N.J. 1995.
The form of glacial cirques in the English Lake District, Cumbria.
Zeitschrift für Geomorphologie 39: 175-202.

Mosteller, F. and Tukey, J.W. 1977.
Data Analysis and Regression: A Second Course in Statistics.
Reading, MA: Addison-Wesley. Chapters 5F, 5H, 11F, 11G.

Tukey, J.W. 1961. Data analysis and behavioral science or learning
to bear the quantitative man's burden by shunning badmandments. In
Jones, L.V. (ed) The Collected Works of John W. Tukey.
Volume III: Philosophy and Principles of Data Analysis 1949-1964.
Monterey, CA: Wadsworth, 187-389.