Computed theoretical power for N=100 and N=200 scenarios
This commit is contained in:
119
Modules/ado/plus/d/dellist.ado
Normal file
119
Modules/ado/plus/d/dellist.ado
Normal file
@ -0,0 +1,119 @@
|
||||
program def dellist, rclass
|
||||
*! NJC 1.5.0 14 December 2000
|
||||
* NJC 1.4.0 6 Sept 2000
|
||||
* NJC 1.3.0 6 June 2000
|
||||
* NJC 1.2.0 31 Jan 2000
|
||||
* NJC 1.1.0 22 Dec 1999
|
||||
* NJC 1.0.0 22 Sept 1999
|
||||
version 6.0
|
||||
gettoken list 0 : 0, parse(",")
|
||||
if "`list'" == "" | "`list'" == "," {
|
||||
di in r "nothing in list"
|
||||
exit 198
|
||||
}
|
||||
|
||||
local nlist : word count `list'
|
||||
|
||||
syntax , [ Delete(str) Pos(numlist sort int >=-`nlist' <=`nlist') /*
|
||||
*/ Exact All Global(str) Noisily ]
|
||||
|
||||
local nopts = ("`delete'" != "") + ("`pos'" != "")
|
||||
if `nopts' != 1 {
|
||||
di in r "must specify one of delete( ) and pos( )"
|
||||
exit 198
|
||||
}
|
||||
|
||||
if length("`global'") > 8 {
|
||||
di in r "global name must be <=8 characters"
|
||||
exit 198
|
||||
}
|
||||
|
||||
if "`exact'" != "" & "`all'" != "" {
|
||||
di in r "all option not allowed with exact option"
|
||||
exit 198
|
||||
}
|
||||
|
||||
tokenize `list'
|
||||
|
||||
if "`delete'" != "" {
|
||||
local i = 1
|
||||
while `i' <= `nlist' {
|
||||
local len = length("``i''")
|
||||
if `len' > 80 {
|
||||
di in r "cannot handle word length > 80"
|
||||
exit 498
|
||||
}
|
||||
local i = `i' + 1
|
||||
}
|
||||
|
||||
tknz `delete', s(d)
|
||||
local nd : word count `delete'
|
||||
|
||||
if "`exact'" != "" {
|
||||
while "`1'" != "" {
|
||||
local i = 1
|
||||
local OK = 0
|
||||
while `i' <= `nd' & !`OK' {
|
||||
local OK = "`1'" == "`d`i''"
|
||||
local i = `i' + 1
|
||||
}
|
||||
if !`OK' { local newlist "`newlist'`1' " }
|
||||
mac shift
|
||||
}
|
||||
}
|
||||
else {
|
||||
while "`1'" != "" {
|
||||
local i = 1
|
||||
local OK = 0
|
||||
while `i' <= `nd' {
|
||||
local thisOK = /*
|
||||
*/ index("`1'", "`d`i''") > 0
|
||||
local OK = `OK' + `thisOK'
|
||||
local i = `i' + 1
|
||||
}
|
||||
if "`all'" != "" { local OK = `OK' == `nd' }
|
||||
if !`OK' { local newlist "`newlist'`1' " }
|
||||
mac shift
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
local np1 = `nlist' + 1
|
||||
tknz `pos' `np1', s(p)
|
||||
local np : word count `pos'
|
||||
|
||||
* negative indexes to positive
|
||||
local i = 1
|
||||
while `p`i'' < 0 {
|
||||
local p`i' = `nlist' + 1 + `p`i''
|
||||
local i = `i' + 1
|
||||
}
|
||||
|
||||
local i = 1
|
||||
local j = 1
|
||||
while `i' <= `nlist' {
|
||||
if `i' == `p`j'' { local j = `j' + 1 }
|
||||
else local newlist "`newlist'``i'' "
|
||||
local i = `i' + 1
|
||||
}
|
||||
}
|
||||
|
||||
if "`noisily'" != "" { di "`newlist'" }
|
||||
if "`global'" != "" { global `global' "`newlist'" }
|
||||
return local list `newlist'
|
||||
end
|
||||
|
||||
program def tknz, rclass
|
||||
* NJC 1.1.0 2 June 2000
|
||||
version 6.0
|
||||
gettoken list 0 : 0, parse(",")
|
||||
syntax , Stub(str) [ * ]
|
||||
tokenize `"`list'"' , `options'
|
||||
|
||||
local i = 1
|
||||
while "``i''" != "" {
|
||||
c_local `stub'`i' `"``i''"'
|
||||
local i = `i' + 1
|
||||
}
|
||||
end
|
||||
|
2
Modules/ado/plus/d/dellist.hlp
Normal file
2
Modules/ado/plus/d/dellist.hlp
Normal file
@ -0,0 +1,2 @@
|
||||
.h listutil
|
||||
|
108
Modules/ado/plus/d/delta.ado
Normal file
108
Modules/ado/plus/d/delta.ado
Normal file
@ -0,0 +1,108 @@
|
||||
*! Delta version 1.5 - 5 March 2008
|
||||
*! Jean-Benoit Hardouin
|
||||
************************************************************************************************************
|
||||
* DELTA: delta coefficient
|
||||
* Version 1.5: March 5, 2008
|
||||
*
|
||||
* Historic
|
||||
* Version 1 (2007-05-21): Jean-Benoit Hardouin
|
||||
* Version 1.1 (2007-05-22): Jean-Benoit Hardouin /* if in and possibility to use the score*/
|
||||
* Version 1.2 (2007-05-22): Jean-Benoit Hardouin /*bug when a score is missing*/
|
||||
* Version 1.3 (2007-06-16): Jean-Benoit Hardouin /*change in the options*/
|
||||
* Version 1.4 (2007-07-03): Jean-Benoit Hardouin /*correct a bug in the options*/
|
||||
* Version 1.5 (2008-03-05): Jean-Benoit Hardouin /*correct a bug in the ci option*/
|
||||
*
|
||||
* Jean-benoit Hardouin, Faculty of Pharmaceutical Sciences - University of Nantes - France
|
||||
* jean-benoit.hardouin@univ-nantes.fr
|
||||
*
|
||||
* News about this program : http://www.anaqol.org
|
||||
* FreeIRT Project : http://www.freeirt.org
|
||||
*
|
||||
* Copyright 2007-2008 Jean-Benoit Hardouin
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
************************************************************************************************************
|
||||
|
||||
program define delta , rclass
|
||||
version 7.0
|
||||
syntax varlist(min=1 numeric) [if] [in] [,ci(integer 0) noDots MINscore(int 0) MAXscore(int 0)]
|
||||
|
||||
preserve
|
||||
tempfile deltafile
|
||||
qui save `deltafile'
|
||||
if "`if'"!=""|"`in'"!="" {
|
||||
qui keep `if' `in'
|
||||
}
|
||||
|
||||
local nbitems:word count `varlist'
|
||||
tokenize `varlist'
|
||||
|
||||
local scoremin=`minscore'
|
||||
local scoremax=`maxscore'
|
||||
|
||||
|
||||
|
||||
tempvar score
|
||||
if `nbitems'==1&`scoremax'==0 {
|
||||
di in red "If you indicate only the score variable, you must define the {cmd:scoremax} option"
|
||||
error 198
|
||||
}
|
||||
else if `nbitems'==1&`scoremax'!=0 {
|
||||
qui gen `score'=`varlist'
|
||||
}
|
||||
else {
|
||||
qui genscore `varlist',score(`score')
|
||||
}
|
||||
qui drop if `score'==.
|
||||
qui count
|
||||
local nbind=r(N)
|
||||
|
||||
if `scoremax'==0 {
|
||||
qui su `score'
|
||||
local scoremax=r(max)
|
||||
}
|
||||
|
||||
tempname error
|
||||
gen `error'=`score'<`scoremin'|`score'>`scoremax'
|
||||
qui count if `error'==1
|
||||
local err=r(N)
|
||||
if `err'!=0 {
|
||||
di in red "`err' individuals has(have) a score inferior to `scoremin' or superior to `scoremax'"
|
||||
error 198
|
||||
}
|
||||
|
||||
local sumsqscore=0
|
||||
forvalues i=`scoremin'/`scoremax' {
|
||||
qui count if `score'==`i'
|
||||
local score`i'=r(N)
|
||||
local sumsqscore=`sumsqscore'+`score`i''^2
|
||||
}
|
||||
local delta=(1+`scoremax')*(`nbind'^2-`sumsqscore')/(`nbind'^2*`scoremax')
|
||||
|
||||
di in green "Range of the scores : " in ye `scoremin' in gr "/" in ye `scoremax'
|
||||
di in green "Number of used individuals : " in ye `nbind'
|
||||
|
||||
if `ci'!=0 {
|
||||
bootstrap delta=r(delta), reps(`ci') nowarn noheader nolegend `dots': delta `varlist' ,minscore(`scoremin') maxscore(`scoremax')
|
||||
}
|
||||
else {
|
||||
display in green "Delta= " in yellow %8.6f `delta'
|
||||
}
|
||||
return scalar delta=`delta'
|
||||
qui use `deltafile',clear
|
||||
restore,not
|
||||
|
||||
end
|
61
Modules/ado/plus/d/delta.hlp
Normal file
61
Modules/ado/plus/d/delta.hlp
Normal file
@ -0,0 +1,61 @@
|
||||
{smcl}
|
||||
{* 16may2007}{...}
|
||||
{hline}
|
||||
help for {hi:delta}{right:Jean-Benoit Hardouin}
|
||||
{hline}
|
||||
|
||||
{title:Syntax}
|
||||
|
||||
{p 8 14 2}{cmd:delta} {it:varlist} [{cmd:if} {it:exp}] [{cmd:in} {it:range}] [, {cmdab:ci}({it:#}) {cmdab:nod:ots} {cmdab:min:score}({it:#}) {cmdab:max:score}({it:#})]
|
||||
|
||||
{title:Description}
|
||||
|
||||
{p 4 8 2}{cmd:delta} computes the generalized delta index of scale discrimination developed by Hankins (2007) based on the original work of Ferguson (1949). This index measures the scale's ability to distinguish between individuals.
|
||||
A value of 1 indicates that the test has maximal discrimination (all possible scores occur with the same frequency) and a value of 0 means that the test has minimal discrimination (all the respondents have the same score).
|
||||
A value of 0.9 results from a set of scores that is normally distributed. A value of 1 is observed if the scores follow a uniform distribution. Individuals with a missing score are omitted.
|
||||
|
||||
{title:Options}
|
||||
|
||||
{p 4 8 2}If {it:varlist} is composed of only one variable, the {cmd:delta} module considers that this variable is the score of the individuals.
|
||||
|
||||
{p 4 8 2}{cmd:ci}({it:#}) estimates the confidence interval by boostrap. {it:#} is the number of replications to be performed. By default, no confidence interval is calculated.
|
||||
|
||||
{p 4 8 2}{cmd:nodots} avoids displaying a dot for each replication (only with {cmd:ci}).
|
||||
|
||||
{p 4 8 2}{cmd:minscore}({it:#}) defines the minimal value of the score. By default, this value is fixed to 0.
|
||||
|
||||
{p 4 8 2}{cmd:maxscore}({it:#}) defines the maximal value of the score. By default, the maximal observed score is used.
|
||||
|
||||
{title:Output}
|
||||
|
||||
{p 4 8 2}{cmd:r(delta)}: Observed value of the delta index.
|
||||
|
||||
{title:Examples}
|
||||
|
||||
{p 4 8 2}{cmd: . delta itemA*}
|
||||
|
||||
{p 4 8 2}{cmd: . delta itemA*, ci(500) dots}
|
||||
|
||||
{p 4 8 2}{cmd: . delta score, scoremax(8)}
|
||||
|
||||
{title: References}
|
||||
|
||||
{p 4 8 2}Ferguson G. A. (1949) On the theory of test discrimination. {it:Psychometrika}, 14: 61-68.
|
||||
|
||||
{p 4 8 2}Hankins M. (2007) Questionnaire discrimination: (re)- introducting coefficient delta. {it:BMC Medical Research Methodology}, 7: 19.
|
||||
|
||||
{title:Author}
|
||||
|
||||
{p 4 8 2}Jean-Benoit Hardouin, PhD, assistant professor{p_end}
|
||||
{p 4 8 2}Team of Biostatistics, Clinical Research and Subjective Measures in Health Sciences{p_end}
|
||||
{p 4 8 2}University of Nantes - Faculty of Pharmaceutical Sciences{p_end}
|
||||
{p 4 8 2}1, rue Gaston Veil - BP 53508{p_end}
|
||||
{p 4 8 2}44035 Nantes Cedex 1 - FRANCE{p_end}
|
||||
{p 4 8 2}Email:
|
||||
{browse "mailto:jean-benoit.hardouin@univ-nantes.fr":jean-benoit.hardouin@univ-nantes.fr}{p_end}
|
||||
{p 4 8 2}Websites {browse "http://www.anaqol.org":AnaQol}
|
||||
and {browse "http://www.freeirt.org":FreeIRT}
|
||||
|
||||
{title:Also see}
|
||||
|
||||
{p 4 13 2}Online: help for {help alpha} and {help loevH} if installed.{p_end}
|
90
Modules/ado/plus/d/difflist.ado
Normal file
90
Modules/ado/plus/d/difflist.ado
Normal file
@ -0,0 +1,90 @@
|
||||
program def difflist, rclass
|
||||
*! NJC 1.4.0 6 June 2000
|
||||
* NJC 1.3.0 31 Jan 2000
|
||||
* NJC 1.2.0 22 Dec 1999
|
||||
* NJC 1.1.0 21 Dec 1999
|
||||
* NJC 1.0.0 14 Oct 1999
|
||||
version 6.0
|
||||
gettoken lists 0 : 0, parse(",")
|
||||
if "`lists'" == "" | "`lists'" == "," { /* no \ */
|
||||
di in r "incorrect syntax: no separator"
|
||||
exit 198
|
||||
}
|
||||
|
||||
tokenize "`lists'", parse("\")
|
||||
if "`4'" != "" {
|
||||
di in r "incorrect syntax: too much stuff"
|
||||
exit 198
|
||||
}
|
||||
if "`1'" == "\" { /* list1 empty */
|
||||
if "`2'" == "\" {
|
||||
di in r "incorrect syntax: one \ only"
|
||||
exit 198
|
||||
}
|
||||
local list2 "`2'" /* might be empty */
|
||||
}
|
||||
else if "`2'" == "\" {
|
||||
local list1 "`1'"
|
||||
local list2 "`3'" /* might be empty */
|
||||
}
|
||||
else {
|
||||
di in r "incorrect syntax: what to compare?"
|
||||
exit 198
|
||||
}
|
||||
|
||||
syntax [ , Global(str) Noisily ]
|
||||
|
||||
if length("`global'") > 8 {
|
||||
di in r "global name must be <=8 characters"
|
||||
exit 198
|
||||
}
|
||||
|
||||
* remove duplicates from `list1'
|
||||
|
||||
tokenize `list1'
|
||||
local list1 "`1'"
|
||||
mac shift
|
||||
|
||||
while "`1'" != "" {
|
||||
local n1 : word count `list1'
|
||||
local i = 1
|
||||
local putin = 1
|
||||
while `i' <= `n1' {
|
||||
local word : word `i' of `list1'
|
||||
if "`word'" == "`1'" {
|
||||
local putin = 0
|
||||
local i = `n1'
|
||||
}
|
||||
local i = `i' + 1
|
||||
}
|
||||
if `putin' { local list1 "`list1' `1'" }
|
||||
mac shift
|
||||
}
|
||||
|
||||
* what is in `list1' but not `list2'?
|
||||
|
||||
local n1 : word count `list1'
|
||||
tokenize `list1'
|
||||
local n2 : word count `list2'
|
||||
|
||||
local i = 1
|
||||
while `i' <= `n1' {
|
||||
local j = 1
|
||||
local putin = 1
|
||||
while `j' <= `n2' {
|
||||
local word : word `j' of `list2'
|
||||
if "`word'" == "``i''" {
|
||||
local putin = 0
|
||||
local j = `n2'
|
||||
}
|
||||
local j = `j' + 1
|
||||
}
|
||||
if `putin' { local newlist "`newlist' ``i''" }
|
||||
local i = `i' + 1
|
||||
}
|
||||
|
||||
if "`noisily'" != "" { di "`newlist'" }
|
||||
if "`global'" != "" { global `global' "`newlist'" }
|
||||
return local list `newlist'
|
||||
end
|
||||
|
2
Modules/ado/plus/d/difflist.hlp
Normal file
2
Modules/ado/plus/d/difflist.hlp
Normal file
@ -0,0 +1,2 @@
|
||||
.h listutil
|
||||
|
269
Modules/ado/plus/d/discrim2.ado
Normal file
269
Modules/ado/plus/d/discrim2.ado
Normal file
@ -0,0 +1,269 @@
|
||||
*! version 2.0 : Oct1995 : Joseph Hilbe
|
||||
* Dichotomous Discriminate Anaylsis
|
||||
* Based on version 1, written by Hilbe 12-7-91, published: STB-5 (Jan1992)
|
||||
|
||||
program define discrim2
|
||||
version 5.0
|
||||
local varlist "req ex"
|
||||
local options "Detail Graph Anova Predict Keep"
|
||||
local in "opt"
|
||||
local if "opt"
|
||||
parse "`*'"
|
||||
parse "`varlist'",parse(" ")
|
||||
qui summ `1'
|
||||
|
||||
if (_result(6)<0 | _result(6)>1) {
|
||||
noi di in red "Error: Group variable must be 0/1"
|
||||
exit
|
||||
}
|
||||
if "`keep'"=="" {
|
||||
preserve
|
||||
}
|
||||
qui {
|
||||
dropmiss `varlist'
|
||||
tempvar prob0 prob1 dummy D nvar obs obs1 obs0 c0 c1 prop D cntall
|
||||
gen `cntall'=_n
|
||||
local group `1'
|
||||
local y "`1'"
|
||||
mac shift
|
||||
qui count
|
||||
gen `obs' = _result(1)
|
||||
count if `group'==0
|
||||
gen `obs0'= _result(1)
|
||||
count if `group'==1
|
||||
gen `obs1'= _result(1)
|
||||
tempvar c0
|
||||
gen `c0' =`obs1'/`obs'
|
||||
gen `c1' = -(`obs0'/`obs')
|
||||
gen `prob0' = `obs1'/`obs'
|
||||
gen `dummy' = `c0' if `group'==0
|
||||
replace `dummy' = `c1' if `group'==1
|
||||
reg `dummy' `*', noheader
|
||||
global nvar = _result(3)
|
||||
cap drop `dummy' `c0' `c1'
|
||||
global rsquare = _result(7)
|
||||
global mahala=($rsquare/(1-$rsquare))*((`obs'*(`obs'-2))/(`obs0'*`obs1'))
|
||||
gen `prop' = $rsquare/$mahala
|
||||
gen `D' = sqrt($mahala)
|
||||
|
||||
* Calc discriminant scores
|
||||
local i = 1
|
||||
while "``i''"!= "" {
|
||||
tempvar cof`i' dis`i'
|
||||
gen `cof`i'' = _b[``i'']
|
||||
gen `dis`i'' = `cof`i''/`prop'
|
||||
local i = `i'+1
|
||||
}
|
||||
|
||||
* Calc main values */
|
||||
local j = 1
|
||||
local i = 1
|
||||
tempvar konst usdfk dscorep dscore dsFp dfun
|
||||
gen `usdfk'=0
|
||||
gen `konst' = 0
|
||||
gen `dscorep'=0
|
||||
gen `dscore'=0
|
||||
gen `dsFp'=0
|
||||
gen `dfun'=0
|
||||
while "``i''"!="" {
|
||||
tempvar mean`j' mn0`j' mn1`j' mndff`j' usdf`j'
|
||||
summ ``i''
|
||||
gen `mean`j'' = _result(3)
|
||||
summ ``i'' if `group'==0
|
||||
gen `mn0`j'' = _result(3)
|
||||
summ ``i'' if `group'==1
|
||||
gen `mn1`j'' = _result(3)
|
||||
gen `mndff`j'' = `mn0`j'' + `mn1`j''
|
||||
replace `konst' = `dis`i''*`mndff`j''+`konst'
|
||||
gen `usdf`i''=`dis`i''/-`D'
|
||||
replace `usdfk'=`usdf`j'' * `mean`j'' + `usdfk'
|
||||
replace `dscorep'=`usdf`i''*``i''
|
||||
replace `dscore'=`dscore'+`dscorep'
|
||||
replace `dsFp'=`dis`i''*``i''
|
||||
replace `dfun'=`dfun'+`dsFp'
|
||||
local i = `i'+1
|
||||
local j = `j'+1
|
||||
}
|
||||
replace `usdfk'=`usdfk'* -1
|
||||
replace `dscore'=`dscore'+`usdfk'
|
||||
replace `konst'=`konst'*-.5
|
||||
replace `dfun' = `dfun'+`konst'
|
||||
local tsquare = $mahala*((`obs0'*`obs1')/`obs')
|
||||
local F = `tsquare'*(`obs'-$nvar)/(($nvar-1)*(`obs'-2))
|
||||
global cnt0 = -`D'*(`obs1'/`obs')
|
||||
global cnt1 = `D'*(`obs0'/`obs')
|
||||
noi di _n
|
||||
noi di in gr _col(20) "Dichotomous Discriminant Analysis"
|
||||
noi di " "
|
||||
#delimit ;
|
||||
noi di in gr "Observations = " in ye `obs'
|
||||
in gr _col(50) "Obs Group 0 = " in ye %9.0g `obs0';
|
||||
noi di in gr "Indep variables = " in ye $nvar
|
||||
in gr _col(50) "Obs Group 1 = " in ye %9.0g `obs1';
|
||||
noi di " ";
|
||||
noi di in gr "Centroid 0 = " in ye %9.4f $cnt0
|
||||
in gr _col(50) "R-square = " in ye %9.4f $rsquare;
|
||||
noi di in gr "Centroid 1 = " in ye %9.4f $cnt1
|
||||
in gr _col(50) "Mahalanobis = " in ye %9.4f $mahala;
|
||||
noi di in gr "Grand Cntd = " in ye %9.4f
|
||||
((`obs1'*$cnt0)+(`obs0'*$cnt1))/`obs';
|
||||
noi di " ";
|
||||
#delimit cr
|
||||
oneway `dscore' `group'
|
||||
global eigen = _result(2)/_result(4)
|
||||
global ccor = sqrt(_result(2)/(_result(2)+_result(4)))
|
||||
global lambda = _result(4)/(_result(2)+_result(4))
|
||||
global chisq = log($lambda)* -((`obs'-($nvar+2)/2)-1)
|
||||
#delimit ;
|
||||
noi di in gr "Eigenvalue = " in ye %9.4f $eigen
|
||||
in gr _col(50) "Wilk's Lambda = " in ye %7.4f $lambda;
|
||||
noi di in gr "Canon. Corr. = " in ye %9.4f $ccor
|
||||
in gr _col(50) "Chi-square = " in ye %7.4f $chisq;
|
||||
noi di in gr "Eta Squared = " in ye %9.4f $ccor^2
|
||||
in gr _col(50) "Sign Chi2 = " in ye %7.4f chiprob($nvar,$chisq);
|
||||
#delimit cr
|
||||
|
||||
* DISPLAY COEFFICIENTS
|
||||
noi di _n(1)
|
||||
noi di in gr _col(26) "Discrim Function" _col(46) "Unstandardized"
|
||||
noi di in gr _col(11) /*
|
||||
*/ "Variable" _col(28) "Coefficients" _col(48) "Coefficients"
|
||||
noi di in gr _col(11) _dup(49) "-"
|
||||
local i=1
|
||||
while "``i''"!="" {
|
||||
noi di in gr _col(11) "``i''" in ye _col(28) %9.4f `dis`i'' /*
|
||||
*/ _col(51) %9.4f `usdf`i''
|
||||
local i = `i'+1
|
||||
}
|
||||
noi di in gr _col(11) "constant" in ye _col(28) %9.4f `konst' /*
|
||||
*/ _col(51) %9.4f `usdfk'
|
||||
|
||||
tempvar lprob grpred cell
|
||||
gen `lprob' = 1/(1+exp(`dfun'))
|
||||
gen `grpred' = 1 if `lprob'>=0.5
|
||||
replace `grpred' = 0 if `lprob'<0.5
|
||||
gen `cell' = 1
|
||||
summ `cell' if `group'==0 & `lprob'<0.5
|
||||
local aa=_result(2)
|
||||
summ `cell' if `group'==0 & `lprob'>=0.5
|
||||
local bb=_result(2)
|
||||
summ `cell' if `group'==1 & `lprob'<0.5
|
||||
local cc=_result(2)
|
||||
summ `cell' if `group'==1 & `lprob'>=0.5
|
||||
local dd=_result(2)
|
||||
local tot = `aa'+`bb'+`cc'+`dd'
|
||||
|
||||
* CONFUSION MATRIX AND RELATED STATS OPTION
|
||||
if "`predict'" !="" {
|
||||
noi di _n " "
|
||||
noi di in gr _col(25) "----- Predicted -----"
|
||||
noi di in gr _col(13) "Actual | Group 0 Group 1 | Total"
|
||||
noi di in gr _col(13) "---------+" _dup(26) "-" "+--------"
|
||||
noi di in gr _col(13) "Group 0 |" in ye _col(26) %6.0g `aa' /*
|
||||
*/ _col(40) %6.0g `bb' in gr _col(49) "|" in ye _col(52) %6.0g `aa'+`bb'
|
||||
noi di in gr _col(13) "Group 1 |" in ye _col(26) %6.0g `cc' /*
|
||||
*/ _col(40) %6.0g `dd' in gr _col(49) "|" in ye _col(52) %6.0g `cc'+`dd'
|
||||
noi di in gr _col(13) "---------+" _dup(26) "-" "+--------"
|
||||
noi di in gr _col(13) "Total |" in ye _col(26) %6.0g `aa'+`cc' /*
|
||||
*/ _col(40) %6.0g `bb'+`dd' in gr _col(49) "|" in ye _col(52) /*
|
||||
*/ %6.0g `tot'
|
||||
noi di in gr _col(13) "---------+" _dup(26) "-" "+--------"
|
||||
noi di " "
|
||||
noi di in gr _col(21) "Correctly predicted = " in ye /*
|
||||
*/ %6.2f ((`aa'+`dd')/`tot')*100 " %"
|
||||
noi di in gr _col(21) "Model sensitivity = " in ye /*
|
||||
*/ %6.2f (`aa'/(`aa'+`bb'))*100 " %"
|
||||
noi di in gr _col(21) "Model specificity = " in ye /*
|
||||
*/ %6.2f (`dd'/(`cc'+`dd'))*100 " %"
|
||||
noi di in gr _col(21) "False positive = " in ye /*
|
||||
*/ %6.2f (`cc'/(`aa'+`cc'))*100 " %"
|
||||
noi di in gr _col(21) "False negative = " in ye /*
|
||||
*/ %6.2f (`bb'/(`bb'+`dd'))*100 " %"
|
||||
}
|
||||
|
||||
* ANOVA OPTION
|
||||
if "`anova'"!="" {
|
||||
noi di _n(1)
|
||||
noi di in gr _col(18) "Discriminant Scores v Group Variable"
|
||||
noi oneway `dscore' `group'
|
||||
}
|
||||
|
||||
* GRAPH OPTION
|
||||
if "`graph'"!="" {
|
||||
tempvar lnp lnm
|
||||
gen `lnp'=`lprob' if (`lprob'>=0.5 & `group'==1) | /*
|
||||
*/ (`lprob'<0.5 & `group'==0)
|
||||
gen `lnm'=`lprob' if `lnp'==.
|
||||
lab var `lnp' "Classified"
|
||||
lab var `lnm' "Misclassified"
|
||||
lab var `dfun' "Discriminant Index"
|
||||
noi gr `lnp' `lnm' `dfun', s(.p) xlab ylab(.1,.3,.4,.5,.6,.7,.9) /*
|
||||
*/ border yline(.5) ti(" Probability of Classification")
|
||||
cap drop `lnp' `lnm'
|
||||
}
|
||||
|
||||
* INDIVIDUAL CLASSIFICATION STATISTICS OPTION: SAVES WITH SAVE OPTION
|
||||
if "`detail'"!="" {
|
||||
cap drop PRED DscScore DscIndex LnProb1 Group DIFF
|
||||
sort `cntall'
|
||||
noi di _n(2)
|
||||
gen PRED=`grpred'
|
||||
gen DscScore = `dscore'
|
||||
gen DscIndex = `dfun'
|
||||
gen LnProb1 = `lprob'
|
||||
gen Group = `group'
|
||||
compress Group PRED
|
||||
gen str2 DIFF = " *" if `group'!=PRED
|
||||
format DIFF %2s
|
||||
format DscIndex DscScore LnProb1 %9.4f
|
||||
noi di in gr " PRED = Predicted Group DIFF = Misclassification"
|
||||
noi di in gr " LnProb1 = Probability Gr 1 DscScore = Discriminant Score"
|
||||
noi di in gr " DscIndex = Discriminant Index"
|
||||
noi di in gr _dup(63) "-"
|
||||
di " "
|
||||
noi l `y' PRED DIFF LnProb1 DscIndex DscScore, nol
|
||||
}
|
||||
|
||||
global S_E_var $nvar
|
||||
global S_E_obs `obs'
|
||||
global S_E_ob0 `obs0'
|
||||
global S_E_ob1 `obs1'
|
||||
global S_E_cn0 $cnt0
|
||||
global S_E_cn1 $cnt1
|
||||
global S_E_cng ((`obs1'*$cnt0)+(`obs0'*$cnt1))/`obs'
|
||||
global S_E_r2 $rsquare
|
||||
global S_E_mah $mahala
|
||||
global S_E_eig $eigen
|
||||
global S_E_lam $lamda
|
||||
global S_E_cc $ccor
|
||||
global S_E_chi $chisq
|
||||
global S_E_e2 $ccor^2
|
||||
global S_E_cmd "discrim"
|
||||
|
||||
}
|
||||
|
||||
if "`keep'"!="" {
|
||||
noi di _n in bl " Caution: data changed in memory"
|
||||
}
|
||||
if "`keep'"=="" {
|
||||
restore
|
||||
}
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
* DROP MISSING VALUES
|
||||
capture program drop dropmiss
|
||||
program define dropmiss
|
||||
local varlist "req ex"
|
||||
parse "`*'"
|
||||
parse "`varlist'", parse(" ")
|
||||
local i= 1
|
||||
while "``i''"!="" {
|
||||
drop if ``i''==.
|
||||
local i=`i'+1
|
||||
}
|
||||
end
|
||||
|
||||
|
77
Modules/ado/plus/d/discrim2.hlp
Normal file
77
Modules/ado/plus/d/discrim2.hlp
Normal file
@ -0,0 +1,77 @@
|
||||
.-
|
||||
help for ^discrim^ (STB-x)
|
||||
.-
|
||||
|
||||
Dichotomous Discriminant Analysis
|
||||
---------------------------------
|
||||
|
||||
^discrim^ grpvar [varlist] [^, p^redict^ a^nova^ g^raph^ d^etail^ k^eep]
|
||||
|
||||
Description
|
||||
-----------
|
||||
^discrim^ allows the user to perform a discriminant analysis on a Bernoulli
|
||||
distributed response of grouping variable (1/0).
|
||||
|
||||
Output includes table with the following statistics and their global
|
||||
designation for post-estimation use when applicable:
|
||||
|
||||
1. Observations [S_E_obs] 2. Independent vars [S_E_var]
|
||||
3. Obs: group==0 [S_E_ob0] 4. Obs: group==1 [S_E_ob1]
|
||||
5. Centroid 0 [S_E_cn0] 6. Centroid 1 [S_E_cn1]
|
||||
7. Grand centroid [S_E_cng] 8. R-square [S_E_r2]
|
||||
9. Mahalanobis [S_E_mah] 10. Eigenvalue [S_E_eig]
|
||||
11. Canon. Correl [S_E_cc] 12. Eta squared [S_E_e2]
|
||||
13. Wilk's lambda [S_E_lam] 14. Chi-square [S_E_chi]
|
||||
|
||||
Output also includes a table displaying both the Discriminant Function and
|
||||
Unstandardized Coefficients.
|
||||
|
||||
Cases in which a variable has a missing value are dropped from estimation.
|
||||
The ^keep^ command does not restore such cases to active memory.
|
||||
|
||||
Options
|
||||
-------
|
||||
^predict^ provides a confusion matrix of actual vs predicted group cell
|
||||
counts. Also included is a listing of the following percentages:
|
||||
1. Correctly predicted 2. Model sensitivity
|
||||
3. Model specificity 4. False Positive
|
||||
5. False Negative
|
||||
|
||||
^anova^ provides an ANOVA of discriminant scores vs the group variable.
|
||||
Bartlett's test for equal variances in included.
|
||||
|
||||
^graph^ provides a classification graph showing correctly and incorrectly
|
||||
classified cases.
|
||||
|
||||
^detail^ creates and lists the following for each retained case:
|
||||
1. Group : actual group value
|
||||
2. PRED : predicted group value
|
||||
3. DIFF : a star indicating misclassified cases
|
||||
4. LnProb1 : logistic probability of grouyp 1 membership
|
||||
5. DscIndex : discriminant index
|
||||
6. DscScore : discriminant score
|
||||
|
||||
^keep^ allows the user to keep the variables created in the Detail option.
|
||||
The data set in memory is altered, so care must be taken when saving the
|
||||
resultant file to disk.
|
||||
|
||||
Examples
|
||||
--------
|
||||
. ^discrim foreign price mpg length^
|
||||
|
||||
. ^discrim foreign price mpg length, p a gr d^
|
||||
|
||||
. ^discrim foreign price mpg length, detail keep^
|
||||
|
||||
Also see
|
||||
--------
|
||||
STB-5 (Jan1992): smv3 - Hilbe, "Regression based dichotomous discriminant
|
||||
analysis".
|
||||
Selvin, Steve (1995, 1996) "Practical Biostatistical Methods", Chap 6.
|
||||
Explanation and use of the 1st version of the ^discrim^ command.
|
||||
|
||||
Additional help
|
||||
---------------
|
||||
Joseph Hilbe, Dept of Sociology, Arizona State University
|
||||
Email: atjmh@@asuvm.inre.asu.edu
|
||||
|
15
Modules/ado/plus/d/dropvars.ado
Normal file
15
Modules/ado/plus/d/dropvars.ado
Normal file
@ -0,0 +1,15 @@
|
||||
*! 1.0.1 14mar2000 jw/ics
|
||||
program define dropvars
|
||||
version 6
|
||||
|
||||
while "`1'" != "" {
|
||||
capture drop `1'
|
||||
if _rc {
|
||||
local nodropv "`nodropv' `1'"
|
||||
}
|
||||
mac shift
|
||||
}
|
||||
if "`nodropv'" != "" {
|
||||
di in gr "Unable to drop" in ye "`nodropv'"
|
||||
}
|
||||
end
|
35
Modules/ado/plus/d/dropvars.hlp
Normal file
35
Modules/ado/plus/d/dropvars.hlp
Normal file
@ -0,0 +1,35 @@
|
||||
.-
|
||||
help for ^dropvars^ [jw] Mar 14, 2000
|
||||
.-
|
||||
|
||||
Drop variables
|
||||
--------------
|
||||
|
||||
^dropvars^ list
|
||||
|
||||
|
||||
Description
|
||||
-----------
|
||||
|
||||
^dropvars^ drops the variables that match the varlist specifications in list.
|
||||
In contrast with ^drop^, ^dropvars^ allows terms in list that do not match
|
||||
any variables; ^drop^ complain if any variable does not exist, and then
|
||||
drops nothing.
|
||||
|
||||
^dropvars list^ is equivalent to
|
||||
|
||||
^for any list : capture drop X^
|
||||
|
||||
|
||||
Example
|
||||
-------
|
||||
|
||||
. ^dropvars a* b*^
|
||||
drop all variables that start with either a or b.
|
||||
|
||||
|
||||
Also see
|
||||
--------
|
||||
|
||||
Manual: ^[R] drop^
|
||||
On-line: help for @drop@
|
Reference in New Issue
Block a user