File restructure #1
This commit is contained in:
@ -1,501 +0,0 @@
|
||||
************************************************************************************************************
|
||||
* hcaccprox: Hierachical Clusters Analysis/CCPROX
|
||||
* Version 1: May 12, 2004
|
||||
* Add-on: Partition version 2 (2004-04-10)
|
||||
*
|
||||
* Use the Detect Stata program (http://freeirt.free.fr)
|
||||
*
|
||||
* Historic :
|
||||
* Version 1 [2004-01-18], Jean-Benoit Hardouin
|
||||
*
|
||||
* Jean-benoit Hardouin, Regional Health Observatory of Orl<72>ans - France
|
||||
* jean-benoit.hardouin@neuf.fr
|
||||
*
|
||||
* News about this program : http://anaqol.free.fr
|
||||
* FreeIRT Project : http://freeirt.free.fr
|
||||
*
|
||||
* Copyright 2004 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 hcaccprox , rclass
|
||||
version 8.0
|
||||
syntax varlist(min=2 numeric) [,PROX(string) METHod(string) PARTition(numlist) MEASures DETails DETect(integer 0)]
|
||||
|
||||
local nbpart:word count `partition'
|
||||
tokenize `partition'
|
||||
forvalues k=1/`nbpart' {
|
||||
local part`k'=``k''
|
||||
}
|
||||
|
||||
local nbitems : word count `varlist'
|
||||
tokenize `varlist'
|
||||
|
||||
tempname proximity whereitems
|
||||
|
||||
matrix define `proximity'=J(`nbitems',`nbitems',0)
|
||||
matrix define `whereitems'=J(`=`nbitems'-1',`nbitems',0)
|
||||
|
||||
if `detect'>`nbitems' {
|
||||
di _col(3) in green "The number of partitions analyzed by the DETECT criterion must be inferior to the number of possible partitions"
|
||||
di _col(3) in green "This number of possible partitions is `=`nbitems'-1', so your detect option is put to this number"
|
||||
local detect=`nbitems'-1
|
||||
di
|
||||
}
|
||||
|
||||
if "`prox'"!="a"&"`prox'"!="ad"&"`prox'"!="cor"&"`prox'"!="ccov"&"`prox'"!="ccor"&"`prox'"!="mh" {
|
||||
if "`prox'"=="" {
|
||||
local prox="ccov"
|
||||
}
|
||||
else {
|
||||
di in red "You must define an existing measure of proximity (a, ad, cor, ccov, ccor, mh)."
|
||||
di in red "Please correct your prox option."
|
||||
exit
|
||||
}
|
||||
}
|
||||
|
||||
if "`method'"!="UPGMA"&"`method'"!="single"&"`method'"!="complete" {
|
||||
if "`method'"=="" {
|
||||
local method="UPGMA"
|
||||
}
|
||||
else {
|
||||
di in red "Tou must define an existing method to define the proximity between two clusters of items:"
|
||||
di in red _col(10) "- UPGMA: Unweighted Pair-Group Method of Average"
|
||||
di in red _col(10) "- single: single linkage"
|
||||
di in red _col(10) "- complete: complete linkage "
|
||||
di in red "Please correct your method option"
|
||||
exit
|
||||
}
|
||||
}
|
||||
|
||||
forvalues i=1/`nbitems' {
|
||||
matrix `whereitems'[1,`i']=`i'
|
||||
if "`details'"!="" {
|
||||
di in green _col(3) "The item " _col(13) in yellow "``i''" in green " correspond to the node " in yellow "`i'"
|
||||
}
|
||||
}
|
||||
|
||||
tempvar score
|
||||
egen `score'=rmean(`varlist')
|
||||
qui replace `score'=`score'*`nbitems'
|
||||
forvalues k=0/`nbitems' {
|
||||
qui count if `score'==`k'
|
||||
local nk`k'=r(N)
|
||||
}
|
||||
|
||||
qui count
|
||||
local N=r(N)
|
||||
|
||||
if "`prox'"=="ccov"|"`prox'"=="mh" {
|
||||
local proxmin=0
|
||||
}
|
||||
|
||||
/*************************Measure of proximities*********************************/
|
||||
|
||||
forvalues i=1/`nbitems' {
|
||||
forvalues j=`=`i'+1'/`nbitems' {
|
||||
/***********************************Proximity A**************************/
|
||||
if "`prox'"=="a" {
|
||||
qui count if ``i''==1&``j''==1
|
||||
local tmp11=r(N)
|
||||
qui count if ``i''==0&``j''==0
|
||||
local tmp00=r(N)
|
||||
|
||||
matrix `proximity'[`i',`j']=sqrt(1-`tmp11'/(`N'-`tmp00'))
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
|
||||
/***********************************Proximity AD*************************/
|
||||
if "`prox'"=="ad" {
|
||||
qui count if ``i''==1&``j''==1
|
||||
local tmp11=r(N)
|
||||
qui count if ``i''==0&``j''==0
|
||||
local tmp00=r(N)
|
||||
|
||||
matrix `proximity'[`i',`j']=sqrt(1-(`tmp11'+`tmp00')/`N')
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
|
||||
/**********************************Proximity COR*************************/
|
||||
if "`prox'"=="cor" {
|
||||
qui count if ``i''==1&``j''==1
|
||||
local tmp11=r(N)
|
||||
qui count if ``i''==0&``j''==0
|
||||
local tmp00=r(N)
|
||||
qui count if ``i''==1&``j''==0
|
||||
local tmp10=r(N)
|
||||
qui count if ``i''==0&``j''==1
|
||||
local tmp01=r(N)
|
||||
|
||||
matrix `proximity'[`i',`j']=sqrt(2*(1-(`tmp11'*`tmp00'-`tmp10'*`tmp01')/(sqrt((`tmp11'+`tmp10')*(`tmp11'+`tmp01')*(`tmp00'+`tmp10')*(`tmp00'+`tmp01')))))
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
|
||||
/***********************************Proximity CCOV**********************/
|
||||
if "`prox'"=="ccov" {
|
||||
local dij=0
|
||||
forvalues k=1/`=`nbitems'-1' {
|
||||
if `nk`k''!=0 {
|
||||
qui corr ``i'' ``j'',cov
|
||||
local covi`i'j`j'k`k'=r(cov_12)
|
||||
local dij=`dij'+`covi`i'j`j'k`k''*`nk`k''
|
||||
}
|
||||
}
|
||||
|
||||
matrix `proximity'[`i',`j']=-`dij'/`N'
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
if `proxmin'<`dij'/`N' {
|
||||
local proxmin=`dij'/`N'
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************Proximity CCOR**********************/
|
||||
|
||||
if "`prox'"=="ccor" {
|
||||
local dij=0
|
||||
forvalues k=1/`=`nbitems'-1' {
|
||||
if `nk`k''!=0 {
|
||||
qui corr ``i'' ``j''
|
||||
local cori`i'j`j'k`k'=r(rho)
|
||||
local dij=`dij'+`cori`i'j`j'k`k''*`nk`k''
|
||||
}
|
||||
}
|
||||
|
||||
matrix `proximity'[`i',`j']=sqrt(2*(1-`dij'/`N'))
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
|
||||
|
||||
/***********************************Proximity MH************************/
|
||||
|
||||
if "`prox'"=="mh" {
|
||||
local numij=0
|
||||
local denom=0
|
||||
forvalues k=1/`=`nbitems'-1' {
|
||||
if `nk`k''!=0 {
|
||||
qui count if ``i''==1&``j''==1
|
||||
local A=r(N)
|
||||
qui count if ``i''==0&``j''==1
|
||||
local B=r(N)
|
||||
qui count if ``i''==1&``j''==0
|
||||
local C=r(N)
|
||||
qui count if ``i''==0&``j''==0
|
||||
local D=r(N)
|
||||
|
||||
if `B'!=0&`C'!=0 {
|
||||
local numij=`numij'+`A'*`D'/`nk`k''
|
||||
local denomij=`denomij'+`B'*`C'/`nk`k''
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
matrix `proximity'[`i',`j']=-log(`numij'/`denomij')
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
if `proxmin'<log(`numij'/`denomij') {
|
||||
local proxmin=-`proximity'[`i',`j']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if "`prox'"=="ccov"|"`prox'"=="mh" {
|
||||
forvalues i=1/`nbitems' {
|
||||
forvalues j=`=`i'+1'/`nbitems' {
|
||||
matrix `proximity'[`i',`j']=`proximity'[`i',`j']+`proxmin'
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**********************END OD THE COMPUTING OF THE PROXIMITIES**************************************/
|
||||
if "`measures'"!="" {
|
||||
di
|
||||
matrix rowname `proximity'=`varlist'
|
||||
matrix colname `proximity'=`varlist'
|
||||
di in green _col(3) "Measures of proximity between the items"
|
||||
matrix list `proximity', noheader
|
||||
di
|
||||
}
|
||||
|
||||
/**********************STEP 0**********************************************************************/
|
||||
|
||||
tempname currentprox nodes conclinesnodes mempart
|
||||
|
||||
matrix `currentprox'=`proximity'
|
||||
matrix define `nodes'=J(`=`nbitems'+4',`=2*`nbitems'-1',0)
|
||||
matrix define `conclinesnodes'=J(1,`nbitems',0)
|
||||
matrix define `mempart'=J(`=`nbitems'+2',`=`nbitems'-1',0)
|
||||
forvalues i=1/`nbitems' {
|
||||
matrix `nodes'[1,`i']=1
|
||||
matrix `nodes'[2,`i']=1
|
||||
matrix `nodes'[5,`i']=`i'
|
||||
matrix `conclinesnodes'[1,`i']=`i'
|
||||
}
|
||||
|
||||
|
||||
/*********************************CLUSTERING PROCEDURE*************************************/
|
||||
|
||||
forvalues k=1/`=`nbitems'-1' {
|
||||
local nbclusters=`nbitems'-`k'+1
|
||||
local distmin=`currentprox'[1,2]
|
||||
local cl1=1
|
||||
local cl2=2
|
||||
|
||||
forvalues i=1/`nbclusters' {
|
||||
forvalues j=`=`i'+1'/`nbclusters' {
|
||||
if `distmin'>`currentprox'[`i',`j'] {
|
||||
local distmin=`currentprox'[`i',`j']
|
||||
local cl1=`i'
|
||||
local cl2=`j'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
local linescl1=`conclinesnodes'[1,`cl1']
|
||||
local nbitemscl1=`nodes'[1,`linescl1']
|
||||
matrix `nodes'[2,`linescl1']=0
|
||||
local linescl2=`conclinesnodes'[1,`cl2']
|
||||
local nbitemscl2=`nodes'[1,`linescl2']
|
||||
matrix `nodes'[2,`linescl2']=0
|
||||
matrix `nodes'[1,`=`nbitems'+`k'']=`nbitemscl1'+`nbitemscl2'
|
||||
matrix `nodes'[2,`=`nbitems'+`k'']=1
|
||||
matrix `nodes'[3,`=`nbitems'+`k'']=`linescl1'
|
||||
matrix `nodes'[4,`=`nbitems'+`k'']=`linescl2'
|
||||
if "`details'"!="" {
|
||||
di in green _col(3) "The nodes" _col(13) in yellow "`linescl1'" _col(17) in green "and" _col(21) in yellow "`linescl2'" _col(25) in green "are been aggregated to form the node " in yellow "`=`nbitems'+`k''"
|
||||
}
|
||||
|
||||
forvalues i=5/`=`nbitemscl1'+4' {
|
||||
local item=`nodes'[`i',`linescl1']
|
||||
matrix `nodes'[`i',`=`nbitems'+`k'']=`item'
|
||||
matrix `whereitems'[`k',`item']=`=`nbitems'+`k''
|
||||
}
|
||||
forvalues i=5/`=`nbitemscl2'+4' {
|
||||
local item=`nodes'[`i',`linescl2']
|
||||
matrix `nodes'[`=`i'+`nbitemscl1'',`=`nbitems'+`k'']=`item'
|
||||
matrix `whereitems'[`k',`item']=`=`nbitems'+`k''
|
||||
}
|
||||
|
||||
local tmp=1
|
||||
forvalues i=1/`=`nbitems'+`k'' {
|
||||
if `nodes'[2,`i']==1 {
|
||||
matrix `mempart'[`tmp',`k']=`i'
|
||||
local tmp=`tmp'+1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if `detect'>=`=`nbitems'-`k'' {
|
||||
local partdetect
|
||||
local compteur=1
|
||||
local scaledetect
|
||||
forvalues i=1/`=`nbitems'-`k'' {
|
||||
local scaledetect`i'
|
||||
}
|
||||
forvalues i=1/`=`nbitems'+`k'' {
|
||||
if `nodes'[2,`i']==1{
|
||||
local tmp=`nodes'[1,`i']
|
||||
local partdetect `partdetect' `tmp'
|
||||
local tmp2=4+`tmp'
|
||||
forvalues j=5/`tmp2' {
|
||||
local tmp3=`nodes'[`j',`i']
|
||||
local scaledetect`compteur' `scaledetect`compteur'' ``tmp3''
|
||||
}
|
||||
local scaledetect `scaledetect' `scaledetect`compteur''
|
||||
local compteur=`compteur'+1
|
||||
}
|
||||
}
|
||||
qui detect `scaledetect' , partition(`partdetect')
|
||||
local detect`=`nbclusters'-1'=r(DETECT)
|
||||
local R`=`nbclusters'-1'=r(R)
|
||||
local Iss`=`nbclusters'-1'=r(Iss)
|
||||
}
|
||||
|
||||
|
||||
matrix drop `currentprox'
|
||||
matrix define `currentprox'=J(`=`nbclusters'-1',`=`nbclusters'-1',0)
|
||||
matrix drop `conclinesnodes'
|
||||
matrix define `conclinesnodes'=J(1,`=`nbclusters'-1',0)
|
||||
|
||||
local tmp=1
|
||||
forvalues i=1/`=`nbitems'+`k'' {
|
||||
if `nodes'[2,`i']==1 {
|
||||
matrix `conclinesnodes'[1,`tmp']=`i'
|
||||
local tmp=`tmp'+1
|
||||
}
|
||||
}
|
||||
forvalues i=1/`=`nbclusters'-1' {
|
||||
forvalues j=`=`i'+1'/`=`nbclusters'-1' {
|
||||
if "`method'"=="UPGMA" {
|
||||
local moy=0
|
||||
local linescl1=`conclinesnodes'[1,`i']
|
||||
local nbitemscl1=`nodes'[1,`linescl1']
|
||||
local linescl2=`conclinesnodes'[1,`j']
|
||||
local nbitemscl2=`nodes'[1,`linescl2']
|
||||
forvalues l=5/`=`nbitemscl1'+4' {
|
||||
forvalues m=5/`=`nbitemscl2'+4' {
|
||||
local item1=`nodes'[`l',`linescl1']
|
||||
local item2=`nodes'[`m',`linescl2']
|
||||
local tmp=`proximity'[`item1',`item2']
|
||||
local moy=`moy'+`tmp'
|
||||
}
|
||||
}
|
||||
matrix `currentprox'[`i',`j']=`moy'/(`nbitemscl1'*`nbitemscl2')
|
||||
matrix `currentprox'[`j',`i']=`moy'/(`nbitemscl1'*`nbitemscl2')
|
||||
}
|
||||
if "`method'"=="single" {
|
||||
local moy=0
|
||||
local linescl1=`conclinesnodes'[1,`i']
|
||||
local nbitemscl1=`nodes'[1,`linescl1']
|
||||
local linescl2=`conclinesnodes'[1,`j']
|
||||
local nbitemscl2=`nodes'[1,`linescl2']
|
||||
forvalues l=5/`=`nbitemscl1'+4' {
|
||||
forvalues m=5/`=`nbitemscl2'+4' {
|
||||
local item1=`nodes'[`l',`linescl1']
|
||||
local item2=`nodes'[`m',`linescl2']
|
||||
if `l'==5&`m'==5 {
|
||||
local distmin=`proximity'[`item1',`item2']
|
||||
}
|
||||
else {
|
||||
if `distmin'>`proximity'[`item1',`item2'] {
|
||||
local distmin=`proximity'[`item1',`item2']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
matrix `currentprox'[`i',`j']=`distmin'
|
||||
matrix `currentprox'[`j',`i']=`distmin'
|
||||
}
|
||||
if "`method'"=="complete" {
|
||||
local moy=0
|
||||
local linescl1=`conclinesnodes'[1,`i']
|
||||
local nbitemscl1=`nodes'[1,`linescl1']
|
||||
local linescl2=`conclinesnodes'[1,`j']
|
||||
local nbitemscl2=`nodes'[1,`linescl2']
|
||||
local distmax=0
|
||||
forvalues l=5/`=`nbitemscl1'+4' {
|
||||
forvalues m=5/`=`nbitemscl2'+4' {
|
||||
local item1=`nodes'[`l',`linescl1']
|
||||
local item2=`nodes'[`m',`linescl2']
|
||||
if `distmax'<`proximity'[`item1',`item2'] {
|
||||
local distmax=`proximity'[`item1',`item2']
|
||||
}
|
||||
}
|
||||
}
|
||||
matrix `currentprox'[`i',`j']=`distmax'
|
||||
matrix `currentprox'[`j',`i']=`distmax'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if `detect'!=0 {
|
||||
tempname indexes
|
||||
matrix define `indexes'=J(`detect',4,0)
|
||||
matrix colnames `indexes'=Clusters DETECT Iss R
|
||||
di ""
|
||||
di in green _col(7) "Indexes to test the `detect' latest partitions of the items"
|
||||
di ""
|
||||
di in green _col(29) "DETECT" _col(43) "Iss" _col(56) "R"
|
||||
di _col(5) in green "Only one cluster:" _col(27) in yellow %8.5f `detect1' _col(38) %8.5f `Iss1' _col(49) %8.5f `R1'
|
||||
matrix `indexes'[1,1]=1
|
||||
matrix `indexes'[1,2]=`detect1'
|
||||
matrix `indexes'[1,3]=`Iss1'
|
||||
matrix `indexes'[1,4]=`R1'
|
||||
forvalues k=2/`detect' {
|
||||
matrix `indexes'[`k',1]=`k'
|
||||
matrix `indexes'[`k',2]=`detect`k''
|
||||
matrix `indexes'[`k',3]=`Iss`k''
|
||||
matrix `indexes'[`k',4]=`R`k''
|
||||
di _col(5) in green "`k' clusters:" _col(27) in yellow %8.5f `detect`k'' _col(38) %8.5f `Iss`k'' _col(49) %8.5f `R`k''
|
||||
}
|
||||
return matrix indexes=`indexes'
|
||||
}
|
||||
|
||||
|
||||
forvalues k=1/`nbpart' {
|
||||
di ""
|
||||
local rowmempart=`nbitems'-`part`k''
|
||||
di in green _col(8) "Number of clusters : `part`k''"
|
||||
tempname affect`part`k''
|
||||
matrix define `affect`part`k'''=J(1,`nbitems',0)
|
||||
forvalues i=1/`part`k'' {
|
||||
di
|
||||
di in green _col(12) "Cluster `i':"
|
||||
local rownodes=`mempart'[`i',`rowmempart']
|
||||
local itemsinthecluster=`nodes'[1,`rownodes']
|
||||
forvalues j=5/`=4+`itemsinthecluster'' {
|
||||
local tmp=`nodes'[`j',`rownodes']
|
||||
matrix `affect`part`k'''[1,`tmp']=`i'
|
||||
di in yellow _col(13)"``tmp''"
|
||||
}
|
||||
}
|
||||
matrix colnames `affect`part`k'''=`varlist'
|
||||
return matrix affect`part`k''=`affect`part`k'''
|
||||
}
|
||||
|
||||
return matrix mempart `mempart'
|
||||
return matrix nodes `nodes'
|
||||
return local nbitems=`nbitems'
|
||||
return local varlist `varlist'
|
||||
end
|
||||
|
||||
/*********************************************************
|
||||
*Partition
|
||||
*Version 2 (May 10, 2004)
|
||||
*
|
||||
*Historic
|
||||
*Version 1 (January 18, 2004)
|
||||
***********************************************************/
|
||||
|
||||
program define partition
|
||||
version 8.0
|
||||
syntax anything(name=partition)
|
||||
|
||||
local nbitems=r(nbitems)
|
||||
tempname mempart nodes
|
||||
matrix `mempart'=r(mempart)
|
||||
matrix `nodes'=r(nodes)
|
||||
local varlist "`r(varlist)'"
|
||||
|
||||
local nbpart:word count `partition'
|
||||
tokenize `partition'
|
||||
|
||||
forvalues k=1/`nbpart' {
|
||||
local part`k'=``k''
|
||||
}
|
||||
tokenize `varlist'
|
||||
|
||||
forvalues k=1/`nbpart' {
|
||||
di ""
|
||||
local rowmempart=`nbitems'-`part`k''
|
||||
di in green _col(8) "Number of clusters : `part`k''"
|
||||
forvalues i=1/`part`k'' {
|
||||
di
|
||||
di in green _col(12) "Cluster `i':"
|
||||
local rownodes=`mempart'[`i',`rowmempart']
|
||||
local itemsinthecluster=`nodes'[1,`rownodes']
|
||||
forvalues j=5/`=4+`itemsinthecluster'' {
|
||||
local tmp=`nodes'[`j',`rownodes']
|
||||
di in yellow _col(13)"``tmp''"
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
@ -1,90 +0,0 @@
|
||||
{smcl}
|
||||
{* 12may2004}{...}
|
||||
{hline}
|
||||
help for {hi:hcaccprox}
|
||||
{hline}
|
||||
|
||||
{title:Hierarchical Clusters Analysis with conditional proximity measures}
|
||||
|
||||
{p 8 14 2}{cmd:hcaccprox} {it:varlist}
|
||||
[{cmd:,} {cmdab:prox:(}{it:keyword}{cmd:)} {cmdab:meth:od(}{it:keyword}{cmd:)} {cmdab:part:ition(}{it:numlist}{cmd:)}
|
||||
{cmdab:meas:ures} {cmdab:det:ails} {cmdab:det:ect:(}{it:#}{cmd:)} ]
|
||||
|
||||
{p 8 14 2}{cmd:partition} {it:numlist}
|
||||
|
||||
{title:Description}
|
||||
|
||||
{p 4 8 2}
|
||||
{cmd:hcaccprox} realize a Hierarchical Clusters Analysis on dichotomoux items
|
||||
based on specific measures of proximity as conditional proximity measures. The program
|
||||
permit to obtain indexes to test the obtained partition (the {help detect} program is
|
||||
necessary in this case).
|
||||
|
||||
{p 4 8 2}
|
||||
{cmd:partition} permit, after a {cmd:hcaccprox} step to obtain
|
||||
the composition of some specific partitions of the items.
|
||||
|
||||
{title:Options}
|
||||
|
||||
{p 4 8 2}{cmd:prox:(}{it:keyword}{cmd:)} define the method to compute the proximity between the items.
|
||||
Six measures are possible. The three first ones are unconditional measures named {it:a}, {it:ad} and {it:cor}.
|
||||
The three last ones are conditional measures named {it:ccov}, {it:ccor} and {it:mh}. See Roussos, Stout and Marden (1998)
|
||||
for details of these six measures. By default, the {it:ccov} option is used.
|
||||
|
||||
{p 4 8 2}{cmd:method} define the method to aggregate two clusters, {it:single} for a single linkage, {it:complete} for a complete
|
||||
linkage, and {it:UPGMA} for the Unweighted Pair-Group Method of Average. By default, the {it:UPGMA} option is used.
|
||||
|
||||
{p 4 8 2}{cmd:partition(}{it:numlist}{cmd:)} lists the partitions to detail by the program. List like {it:(2 4 6)} or {it:(2(2)6)}
|
||||
are authorized.
|
||||
|
||||
{p 4 8 2}{cmd:measures} display the used proximity measures between the items.
|
||||
|
||||
{p 4 8 2}{cmd:details} display the results of the algorithm of aggregation.
|
||||
|
||||
{p 4 8 2}{cmd:detect(}{it:#}{cmd:)} specifies for all the partitions with a number of clusters inferior or equal to {it:#}
|
||||
to compute the DETECT, Iss and R indexes.
|
||||
|
||||
{p 4 8 2}{it:numlist}, for the {cmd:partition} program, define the partitions with the number of clusters indicated in the {it:numlist}
|
||||
to detail.
|
||||
|
||||
{title:Examples}
|
||||
|
||||
{p 4 8 2}{cmd:. hcaccprox q1-q10}
|
||||
|
||||
{p 4 8 2}{cmd:. partition 3 5 6}
|
||||
|
||||
{p 4 8 2}{cmd:. hcaccprox item1-item9 dotest1-dotest6, detect(6) measures}
|
||||
|
||||
{p 4 8 2}{cmd:. hcaccprox c1 c2 c3 c4 c5 c6 c7, prox(a) method(single)}
|
||||
|
||||
{title:Outputs}
|
||||
|
||||
{p 4 8 2}{cmd:. r(varlist)} is a macro who contain {it:varlist}
|
||||
|
||||
{p 4 8 2}{cmd:. r(nbitems)} is a macro who contain the number of items
|
||||
|
||||
{p 4 8 2}{cmd:. r(nodes)} is a matrix who contain all the informations about all the possible clusters of items. Each column represent a node (the first ones represent each item of {it:varlist}, and the following columns represent each
|
||||
aggregation of clusters), the first line represent the number of items in each cluster, the third and the fourth lines represent the two cluster who are aggregated to form the new cluster, and the following lines represent the list of
|
||||
items composing each cluster
|
||||
|
||||
{p 4 8 2}{cmd:. r(mempart)} list the number of cluster composing each possible partition : the last column is the partition in only one cluster, the preceeding column represent the partition in two cluster, and so on
|
||||
|
||||
{p 4 8 2}{cmd:. r(affect#)} is obtained with the {it:partition} option. In this vector, the number of the cluster (of the partition in # clusters) is associated to each item
|
||||
|
||||
{p 4 8 2}{cmd:. r(indexes)} is obtained with the {it:detect} option. This matrix contain the DETECT, Iss and R indexes associated to each partition with a number of clusters inferior to the number defined in the {it:detect} option
|
||||
|
||||
|
||||
{title:Reference}
|
||||
|
||||
{p 4 8 2}{cmd:Roussos L. A, Stout W. F. and Marden J. I.}, {it:Using new proximity measures with hierarchical cluster analysis to detect multidimensionality}. Journal of Educational Measurement, {cmd:35}(1), pp 1-30, 1998.
|
||||
|
||||
{p 4 8 2}{cmd:Zhang J. and Stout W. F.}, {it:The theorical DETECT index of dimensionality and its application to approximate simple structure}. Psychometrika, {cmd:64}(2), pp 213-249, 1999.
|
||||
|
||||
{title:Also see}
|
||||
|
||||
{p 4 13 2} help for {help detect}
|
||||
|
||||
{title:Author}
|
||||
|
||||
{p 4 8 2}Jean-Benoit Hardouin, Regional Health Observatory (ORS) - 1, rue Porte Madeleine - BP 2439 - 45032 Orleans Cedex 1 - France.
|
||||
You can contact the author at {browse "mailto:jean-benoit.hardouin@neuf.fr":jean-benoit.hardouin@neuf.fr} and visit the websites {browse "http://anaqol.free.fr":AnaQol} and {browse "http://freeirt.free.fr":FreeIRT}
|
@ -1,509 +0,0 @@
|
||||
*! Version 3.6 19 July 2019
|
||||
*! Jean-Benoit Hardouin
|
||||
************************************************************************************************************
|
||||
* hcavar: Hierachical Clusters Analysis (HCA) of variables
|
||||
* Version 3.5 [2014-05-26], Jean-Benoit Hardouin /* dirsave and filesave options */
|
||||
*
|
||||
* Use the Detect Stata program (ssc install detect)
|
||||
*
|
||||
* Historic :
|
||||
* Under the name of -hcaccprox-
|
||||
* Version 1 [2004-01-18], Jean-Benoit Hardouin
|
||||
* Version 2 [2004-05-12], Jean-Benoit Hardouin
|
||||
* Version 3 [2005-12-31], Jean-Benoit Hardouin
|
||||
* Version 3.1 [2006-01-15], Jean-Benoit Hardouin /* correction if there is only one individual with a given score*/
|
||||
* Version 3.2 [2010-04-15], Jean-Benoit Hardouin /* Possibility to use Polytomous Items with CCOR, CCOV and MH*/
|
||||
* Version 3.3 [2014-05-07], Jean-Benoit Hardouin, Bastien Perrot /* HTML option, if option*/
|
||||
* Version 3.4 [2014-05-26], Jean-Benoit Hardouin, Bastien Perrot /* DETECT option available for polytomous items */
|
||||
* Version 3.5 [2019-07-18], Jean-Benoit Hardouin /* dirsave and filesave options */
|
||||
* Version 3.6 [2019-07-19], Jean-Benoit Hardouin /* loevH proximity */
|
||||
*
|
||||
* Jean-benoit Hardouin - University of Nantes - France
|
||||
* INSERM UMR 1246-SPHERE "Methods in Patient Centered Outcomes and Health Research", Nantes University, University of Tours
|
||||
* jean-benoit.hardouin@univ-nantes.fr
|
||||
*
|
||||
* News about this program :http://www.anaqol.org
|
||||
*
|
||||
* Copyright 2004-2006, 2010, 2019 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 hcavar, rclass
|
||||
version 9
|
||||
syntax varlist(min=2 numeric) [if] [in] [,PROX(string) METHod(string) PARTition(numlist) MEASures DETect MATrix(string) noDENDROgram HTML(string) DIRSave(string) FILESave]
|
||||
|
||||
tempfile hcaccproxfile
|
||||
qui save `hcaccproxfile',replace
|
||||
preserve
|
||||
|
||||
if "`if'"!="" {
|
||||
qui keep `if'
|
||||
}
|
||||
|
||||
if "`html'"!="" {
|
||||
//set scheme sj
|
||||
//local htmlregion "graphregion(fcolor(white) ifcolor(white))"
|
||||
di "<!-- SphereCalc start of response -->"
|
||||
di "<pre>"
|
||||
}
|
||||
|
||||
local nbitems : word count `varlist'
|
||||
tokenize `varlist'
|
||||
local type=0
|
||||
forvalues i=1/`nbitems' {
|
||||
qui drop if ``i''==.
|
||||
qui inspect ``i''
|
||||
if r(N_unique)>`type'&r(N_unique)!=. {
|
||||
local type=r(N_unique)
|
||||
}
|
||||
else if r(N_unique)>`type'&r(N_unique)==. {
|
||||
local type "100"
|
||||
}
|
||||
}
|
||||
if `type'==100 {
|
||||
local type ">99"
|
||||
}
|
||||
|
||||
tempname proximity whereitems
|
||||
|
||||
local prox=lower("`prox'")
|
||||
local method=lower("`method'")
|
||||
matrix define `proximity'=J(`nbitems',`nbitems',0)
|
||||
matrix define `whereitems'=J(`=`nbitems'-1',`nbitems',0)
|
||||
|
||||
/**************************PROXIMITIES MEASURES DESCRIPTION************************/
|
||||
|
||||
if "`matrix'"!="" {
|
||||
local desprox="Defined by the user"
|
||||
}
|
||||
if "`prox'"=="" {
|
||||
local prox="pearson"
|
||||
}
|
||||
else if "`prox'"=="a" {
|
||||
local prox="jaccard"
|
||||
}
|
||||
else if "`prox'"=="ad" {
|
||||
local prox="matching"
|
||||
}
|
||||
else if "`prox'"=="corr" {
|
||||
local prox="pearson"
|
||||
}
|
||||
if "`type'">"2"&"`prox'"!="pearson"&"`prox'"!="ccov"&"`prox'"!="ccor"&"`prox'"!="mh"&"`prox'"!="loevh" {
|
||||
di in red "Only the {hi:pearson}, {hi:ccov}, {hi:ccor}, {hi:mh} and {hi:loevh} measures of proximity are available with ordinal or numerous variables"
|
||||
di in red "Please correct your {hi:prox} option."
|
||||
exit
|
||||
}
|
||||
|
||||
if "`partition'"==""&"`detect'"!="" {
|
||||
di in ye "option partition() required"
|
||||
error 198
|
||||
}
|
||||
local existmeas=0
|
||||
foreach i in jaccard matching pearson russel dice ccor mh ccov loevh {
|
||||
if "`prox'"=="`i'" {
|
||||
local existmeas=1
|
||||
}
|
||||
}
|
||||
if `existmeas'==0 {
|
||||
di in red "You must define an existing measure of proximity (jaccard(a), matching(ad), pearson(cor), russel, dice, ccov, ccor, mh, loevh)."
|
||||
di in red "Please correct your {hi:prox} option."
|
||||
exit
|
||||
}
|
||||
if "`prox'"=="ccov"|"`prox'"=="mh" {
|
||||
local proxmin=0
|
||||
}
|
||||
|
||||
if "`prox'"=="matching" {
|
||||
local desprox="Matching"
|
||||
}
|
||||
else if "`prox'"=="jaccard" {
|
||||
local desprox="Jaccard"
|
||||
}
|
||||
else if "`prox'"=="russel" {
|
||||
local desprox="Russel"
|
||||
}
|
||||
else if "`prox'"=="dice" {
|
||||
local desprox="Dice"
|
||||
}
|
||||
else if "`prox'"=="pearson" {
|
||||
local desprox="Pearson"
|
||||
}
|
||||
else if "`prox'"=="ccov" {
|
||||
local desprox="Conditional covariances"
|
||||
}
|
||||
else if "`prox'"=="ccor" {
|
||||
local desprox="Conditional correlations"
|
||||
}
|
||||
else if "`prox'"=="mh" {
|
||||
local desprox="Mantel Hanzel"
|
||||
}
|
||||
|
||||
/**************************PROXIMITIES MEASURES DESCRIPTION************************/
|
||||
|
||||
if "`method'"=="upgma"|"`method'"=="" {
|
||||
local method="average"
|
||||
}
|
||||
if "`method'"=="wpgma"|"`method'"=="" {
|
||||
local method="waverage"
|
||||
}
|
||||
local vermethod=0
|
||||
foreach i in average waverage single centroid median complete wards {
|
||||
if "`method'"=="`i'" {
|
||||
local vermethod=1
|
||||
}
|
||||
}
|
||||
|
||||
if `vermethod'==0 {
|
||||
di in red "You must define an existing method to define the proximity between two clusters of items:"
|
||||
di in red _col(10) "- single: single linkage"
|
||||
di in red _col(10) "- complete: complete linkage "
|
||||
di in red _col(10) "- average(UPGMA): Unweighted Pair-Group Method of Average"
|
||||
di in red _col(10) "- waverage(WPGMA): Unweighted Pair-Group Method of Average"
|
||||
di in red _col(10) "- wards: Ward's linkage"
|
||||
di in red "Please correct your method option"
|
||||
exit
|
||||
}
|
||||
if "`method'"=="single"|"`method'"=="singlelinkage" {
|
||||
local method single
|
||||
local desmethod="Single linkage"
|
||||
}
|
||||
else if "`method'"=="complete"|"`method'"=="completelinkage" {
|
||||
local desmethod="Complete linkage"
|
||||
}
|
||||
else if "`method'"=="median"|"`method'"=="medianlinkage" {
|
||||
local desmethod="Median linkage (no dendrogram)"
|
||||
}
|
||||
else if "`method'"=="centroid"|"`method'"=="centroidlinkage" {
|
||||
local desmethod="Centroid linkage (no dendrogram)"
|
||||
}
|
||||
else if "`method'"=="average"|"`method'"=="averagelinkage" {
|
||||
local desmethod="Unweighted Pair-Group Method of Average"
|
||||
}
|
||||
else if "`method'"=="waverage"|"`method'"=="waveragelinkage" {
|
||||
local desmethod="Weighted Pair-Group Method of Average"
|
||||
}
|
||||
else if "`method'"=="wards"|"`method'"=="wardslinkage" {
|
||||
local desmethod="Ward's linkage"
|
||||
}
|
||||
|
||||
forvalues i=1/`nbitems' {
|
||||
matrix `whereitems'[1,`i']=`i'
|
||||
}
|
||||
|
||||
tempvar score
|
||||
genscore `varlist',score(`score')
|
||||
qui su `score'
|
||||
local maxscore=r(max)
|
||||
forvalues k=0/`maxscore' {
|
||||
qui count if `score'==`k'
|
||||
local nk`k'=r(N)
|
||||
}
|
||||
|
||||
qui count
|
||||
local N=r(N)
|
||||
|
||||
|
||||
di in green "{hline 80}"
|
||||
di in green "Number of individuals with none missing values: " in ye `N'
|
||||
di in green "Maximal number of modalities for a variable: " in ye "`type'"
|
||||
di in green "Proximity measures: " in ye "`desprox'"
|
||||
di in green "Method to aggregate clusters: " in ye "`desmethod'"
|
||||
di in green "{hline 80}"
|
||||
di
|
||||
di
|
||||
|
||||
|
||||
/*************************Measure of proximities*********************************/
|
||||
if "`matrix'"=="" {
|
||||
if "`prox'"=="loevh" {
|
||||
qui loevh `varlist', pairw pair
|
||||
matrix `proximity'=r(loevHjk)
|
||||
}
|
||||
|
||||
forvalues i=1/`nbitems' {
|
||||
forvalues j=`=`i'+1'/`nbitems' {
|
||||
/***********************************Proximity AD*************************/
|
||||
if "`prox'"=="matching" { /*ad*/
|
||||
qui count if ``i''==1&``j''==1
|
||||
local tmp11=r(N)
|
||||
qui count if ``i''==0&``j''==0
|
||||
local tmp00=r(N)
|
||||
|
||||
matrix `proximity'[`i',`j']=sqrt(1-(`tmp11'+`tmp00')/`N')
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
|
||||
/***********************************Proximity A**************************/
|
||||
else if "`prox'"=="jaccard" { /*a*/
|
||||
qui count if ``i''==1&``j''==1
|
||||
local tmp11=r(N)
|
||||
qui count if ``i''==0&``j''==0
|
||||
local tmp00=r(N)
|
||||
|
||||
matrix `proximity'[`i',`j']=sqrt(1-`tmp11'/(`N'-`tmp00'))
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
|
||||
/***********************************Proximity Russel**************************/
|
||||
else if "`prox'"=="russel" {
|
||||
qui count if ``i''==1&``j''==1
|
||||
local tmp11=r(N)
|
||||
|
||||
matrix `proximity'[`i',`j']=sqrt(1-`tmp11'/`N')
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
|
||||
/***********************************Proximity A**************************/
|
||||
else if "`prox'"=="dice" {
|
||||
qui count if ``i''==1&``j''==1
|
||||
local tmp11=r(N)
|
||||
qui count if ``i''==0&``j''==0
|
||||
local tmp00=r(N)
|
||||
|
||||
matrix `proximity'[`i',`j']=sqrt(1-2*`tmp11'/(`N'+`tmp11'-`tmp00'))
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
|
||||
/**********************************Proximity COR*************************/
|
||||
else if "`prox'"=="pearson" { /*corr*/
|
||||
qui corr ``i'' ``j''
|
||||
matrix `proximity'[`i',`j']=sqrt(2*(1-r(rho)))
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
|
||||
/***********************************Proximity CCOV**********************/
|
||||
else if "`prox'"=="ccov" {
|
||||
local dij=0
|
||||
local Ntemp=`N'
|
||||
forvalues k=1/`=`maxscore'-1' {
|
||||
if `nk`k''!=0 {
|
||||
if `nk`k''>1 {
|
||||
qui corr ``i'' ``j'' if `score'==`k',cov
|
||||
local covi`i'j`j'k`k'=r(cov_12)
|
||||
}
|
||||
else if `nk`k''==1 {
|
||||
local Ntemp=`Ntemp'-1
|
||||
local covi`i'j`j'k`k'=0
|
||||
}
|
||||
else {
|
||||
local covi`i'j`j'k`k'=0
|
||||
}
|
||||
local dij=`dij'+`covi`i'j`j'k`k''*`nk`k''
|
||||
}
|
||||
}
|
||||
|
||||
matrix `proximity'[`i',`j']=-`dij'/`Ntemp'
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
if `proxmin'<`dij'/`Ntemp' {
|
||||
local proxmin=`dij'/`Ntemp'
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************Proximity CCOR**********************/
|
||||
|
||||
else if "`prox'"=="ccor" {
|
||||
local dij=0
|
||||
local nnull=0
|
||||
local Ntemp=`N'
|
||||
forvalues k=1/`=`maxscore'-1' {
|
||||
if `nk`k''!=0 {
|
||||
if `nk`k''>1 {
|
||||
qui corr ``i'' ``j'' if `score'==`k'
|
||||
local cori`i'j`j'k`k'=r(rho)
|
||||
}
|
||||
else if `nk`k''==1 {
|
||||
local Ntemp=`Ntemp'-1
|
||||
local cori`i'j`j'k`k'=0
|
||||
}
|
||||
else {
|
||||
local cori`i'j`j'k`k'=0
|
||||
}
|
||||
if `cori`i'j`j'k`k''!=. {
|
||||
local dij=`dij'+`cori`i'j`j'k`k''*`nk`k''
|
||||
}
|
||||
else if `cori`i'j`j'k`k''==. {
|
||||
local nnull=`nnull'+`nk`k''
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
matrix `proximity'[`i',`j']=sqrt(2*(1-`dij'/(`Ntemp'-`nnull')))
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
|
||||
|
||||
/***********************************Proximity MH************************/
|
||||
|
||||
else if "`prox'"=="mh" {
|
||||
local numij=0
|
||||
local denom=0
|
||||
forvalues k=1/`=`maxscore'-1' {
|
||||
if `nk`k''!=0 {
|
||||
qui count if ``i''==1&``j''==1&`score'==`k'
|
||||
local A=r(N)
|
||||
qui count if ``i''==0&``j''==1&`score'==`k'
|
||||
local B=r(N)
|
||||
qui count if ``i''==1&``j''==0&`score'==`k'
|
||||
local C=r(N)
|
||||
qui count if ``i''==0&``j''==0&`score'==`k'
|
||||
local D=r(N)
|
||||
local numij=`numij'+`A'*`D'/`nk`k''
|
||||
local denomij=`denomij'+`B'*`C'/`nk`k''
|
||||
}
|
||||
}
|
||||
|
||||
matrix `proximity'[`i',`j']=-log(`numij'/`denomij')
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
if `proxmin'<log(`numij'/`denomij') {
|
||||
local proxmin=-`proximity'[`i',`j']
|
||||
}
|
||||
}
|
||||
/***********************************Proximity LoevH************************/
|
||||
|
||||
else if "`prox'"=="loevh" {
|
||||
matrix `proximity'[`i',`j']=1-`proximity'[`i',`j']
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
}
|
||||
}
|
||||
if "`prox'"=="ccov"|"`prox'"=="mh" {
|
||||
forvalues i=1/`nbitems' {
|
||||
forvalues j=`=`i'+1'/`nbitems' {
|
||||
matrix `proximity'[`i',`j']=`proximity'[`i',`j']+`proxmin'
|
||||
if `proximity'[`i',`j']<0 {
|
||||
matrix `proximity'[`i',`j']=0
|
||||
}
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**********************END OD THE COMPUTING OF THE PROXIMITIES**************************************/
|
||||
else {
|
||||
matrix `proximity'=`matrix'
|
||||
}
|
||||
matrix list `proximity'
|
||||
matrix rowname `proximity'=`varlist'
|
||||
matrix colname `proximity'=`varlist'
|
||||
|
||||
if "`measures'"!="" {
|
||||
di in green "{hline 50}"
|
||||
di in green "Measures of proximity between the items"
|
||||
di in green "{hline 50}"
|
||||
matrix list `proximity', noheader
|
||||
di
|
||||
}
|
||||
|
||||
/**********************CLUSTERING PROCEDURE **********************************************/
|
||||
|
||||
|
||||
qui clustermat `method' `proximity',clear labelvar(name)
|
||||
local hor "hor"
|
||||
if "`method'"!="centroid"&"`method'"!="median"&"`dendrogram'"=="" {
|
||||
if "`html'" != "" {
|
||||
qui local saving "saving(`c(tmpdir)'/`html'_dendro,replace) nodraw"
|
||||
qui cluster dendro ,labels(name) hor ylabel(,angle(0)) title("Hierarchical Cluster Analysis on variables") subtitle("`desmethod'") xtitle("`desprox' proximities") `saving'
|
||||
qui graph use `c(tmpdir)'/`html'_dendro.gph
|
||||
qui graph export `c(tmpdir)'/`html'_dendro.eps, replace
|
||||
di "<br />"
|
||||
di "<img src=" _char(34) "/data/`html'_dendro.png" _char(34)
|
||||
di " class=" _char(34) "resgraph" _char(34) " alt=" _char(34) "dendro" _char(34) " title= " _char(34) "Hierarchical Cluster Analysis on variables - click to enlarge" _char(34) " width=" _char(34) "350" _char(34) " height=" _char(34) "240" _char(34) " >"
|
||||
}
|
||||
else {
|
||||
if "`filesave'"!="" {
|
||||
qui local saving "saving(`dirsave'//dendrogram,replace) nodraw"
|
||||
}
|
||||
else {
|
||||
qui local saving
|
||||
}
|
||||
qui cluster dendro ,labels(name) hor ylabel(,angle(0)) title("Hierarchical Cluster Analysis on variables") subtitle("`desmethod'") xtitle("`desprox' proximities") `saving'
|
||||
}
|
||||
}
|
||||
|
||||
if "`partition'"!="" {
|
||||
foreach i of numlist `partition' {
|
||||
qui cluster gen cluster`i'=group(`i')
|
||||
}
|
||||
tempname clusters
|
||||
mkmat cluster* ,mat(`clusters')
|
||||
matrix rownames `clusters'=`varlist'
|
||||
local compteur=0
|
||||
foreach i of numlist `partition' {
|
||||
local ++compteur
|
||||
di
|
||||
di in green "{hline 30}"
|
||||
di in green "Partition in `i' cluster(s)"
|
||||
di in green "{hline 30}"
|
||||
di
|
||||
forvalues j=1/`i' {
|
||||
local cluster`i'_`j'
|
||||
local nbi`i'_`j'=0
|
||||
forvalues k=1/`nbitems' {
|
||||
if `clusters'[`k',`compteur']==`j' {
|
||||
local cluster`i'_`j' `cluster`i'_`j'' ``k''
|
||||
local ++nbi`i'_`j'
|
||||
}
|
||||
}
|
||||
di in green "Cluster `j': " in ye "`cluster`i'_`j''"
|
||||
}
|
||||
}
|
||||
return matrix clusters=`clusters'
|
||||
}
|
||||
|
||||
/**********************DETECT OPTION **************************************************/
|
||||
|
||||
use `hcaccproxfile',clear
|
||||
if "`detect'"!=""&"`partition'"!="" {
|
||||
foreach i of numlist `partition' {
|
||||
local liste
|
||||
local part
|
||||
forvalues j=1/`i' {
|
||||
local liste "`liste' `cluster`i'_`j''"
|
||||
local part "`part' `nbi`i'_`j''"
|
||||
}
|
||||
qui detect `liste',part(`part')
|
||||
local detect`i'=r(DETECT)
|
||||
local Iss`i'=r(Iss)
|
||||
local R`i'=r(R)
|
||||
}
|
||||
tempname indexes
|
||||
matrix define `indexes'=J(`compteur',4,0)
|
||||
matrix colnames `indexes'=Clusters DETECT Iss R
|
||||
di ""
|
||||
di in green "{hline 50}"
|
||||
di in green "Indexes to compare the partitions of the items"
|
||||
di in green "{hline 50}"
|
||||
di ""
|
||||
di in green _col(29) "DETECT" _col(43) "Iss" _col(56) "R"
|
||||
local compteur=0
|
||||
foreach k of numlist `partition' {
|
||||
local ++compteur
|
||||
matrix `indexes'[`compteur',1]=`k'
|
||||
matrix `indexes'[`compteur',2]=`detect`k''
|
||||
matrix `indexes'[`compteur',3]=`Iss`k''
|
||||
matrix `indexes'[`compteur',4]=`R`k''
|
||||
di _col(5) in green "`k' cluster(s):" _col(27) in yellow %8.5f `detect`k'' _col(38) %8.5f `Iss`k'' _col(49) %8.5f `R`k''
|
||||
}
|
||||
return matrix indexes=`indexes'
|
||||
}
|
||||
return local nbvar=`nbitems'
|
||||
return matrix measures=`proximity'
|
||||
restore, not
|
||||
*use `hcaccproxfile',clear
|
||||
|
||||
end
|
@ -1,100 +0,0 @@
|
||||
{smcl}
|
||||
{* 6december2012}{...}
|
||||
{hline}
|
||||
help for {hi:hcavar}{right:Jean-Benoit Hardouin}
|
||||
{hline}
|
||||
|
||||
{title:Hierarchical Clusters Analysis of variables}
|
||||
|
||||
{p 8 14 2}{cmd:hcavar} {it:varlist}
|
||||
[{cmd:,} {cmdab:prox}{it:(keyword)} {cmdab:mat:rix}{it:(matrix)} {cmdab:meth:od}{it:(keyword)}
|
||||
{cmdab:part:ition}{it:(numlist)} {cmdab:meas:ures} {cmdab:det:ect} {cmdab:nodendro:gram}]
|
||||
|
||||
{title:Description}
|
||||
|
||||
{p 4 8 2}
|
||||
{cmd:hcavar} is the new name of the old {cmd:hcaccprox} module.
|
||||
|
||||
{p 4 8 2}
|
||||
{cmd:hcavar} realizes a Hierarchical Clusters Analysis on variables.
|
||||
The variables can be numerous, ordinal or binary. The distances (dissimilarity
|
||||
measures for binary variables) between two variables are computed as the squared
|
||||
root of 2 times one minus the Pearson correlation. For binary variables, it is
|
||||
possible to use other similarity coefficients as Matching, Jaccard, Russel or Dice
|
||||
(See {help measure option} for more details). The distance matrix is computed as
|
||||
the squared root of one minus the value of these coefficients.
|
||||
In the field of Item Response Theory, it is possible to define conditional measures
|
||||
to the score as defined by Roussos, Stout and Marden (1998): conditional correlations,
|
||||
conditional covariance, or Mantel-Haenszel measures of similarity. In the same field,
|
||||
it is possible to compute, for a set of obtained partition of the items, the DETECT,
|
||||
Iss and R indexes defined by Zhang and Stout (1999).
|
||||
|
||||
{title:Options}
|
||||
|
||||
{p 4 8 2}{cmd:prox} defines the proximity measures to use : {it:jaccard}
|
||||
(alias {it:a}), {it: russel}, {it:dice}, {it:matching} (alias {it:ad}), {it:pearson}
|
||||
(alias {it:corr}), conditional covariance ({it:ccov}), conditional correlation
|
||||
({it:ccor}), or Mantel Haenszel ({it:mh}). By default, this option is put to
|
||||
{it:pearson}. {it:pearson} is the only one option available with ordinal or numerous
|
||||
variables.
|
||||
|
||||
{p 4 8 2}{cmd:matrix} allows using a matrix as distance matrix.
|
||||
|
||||
{p 4 8 2}{cmd:method} defines the method to aggregate two clusters. See {help cluster}
|
||||
for more details about these methods. The complete name of the method
|
||||
must be indicated (with or without "linkage"), none abbreviation is allowed.
|
||||
{it:waveragelinkage} is used by default.
|
||||
|
||||
{p 4 8 2}{cmd:partition} lists the partitions of variables to detail by
|
||||
the program.
|
||||
|
||||
{p 4 8 2}{cmd:measures} displays the used proximity measures matrix between
|
||||
the variables.
|
||||
|
||||
{p 4 8 2}{cmd:detect} computes the DETECT, Iss and R indexes
|
||||
for the partitions indicated in the {cmd:partitions} option.
|
||||
|
||||
{p 4 8 2}{cmdnodendrogram} enables the displaying of th dendrogram.
|
||||
|
||||
{title:Examples}
|
||||
|
||||
{p 4 8 2}{cmd:. hcavar var1-var10} /*displays only the dendrogram*/
|
||||
|
||||
{p 4 8 2}{cmd:. hcavar var*, partition(1/6) measures method(single)} /*Single linkage, details of 6 partitions*/
|
||||
|
||||
{p 4 8 2}{cmd:. hcavar itemA1-itemA7 itemB1-itemB7, prox(ccor) method(single) detect part(1/4)} /*details of 4 partitions, conditional correlations*/
|
||||
|
||||
{title:Outputs}
|
||||
|
||||
{p 4 8 2}{cmd:. r(nbvar)} contains the number of variables
|
||||
|
||||
{p 4 8 2}{cmd:. r(measures)} is the distances measures matrix between the variables
|
||||
|
||||
{p 4 8 2}{cmd:. r(clusters)} is a matrix obtained with the {cmd:partition} option
|
||||
containing the composition of the partitions defined with this option.
|
||||
|
||||
{p 4 8 2}{cmd:. r(indexes)} is obtained with the {cmd:detect} option.
|
||||
This matrix contain the DETECT, Iss and R indexes associated to each partition
|
||||
defined with the {cmd:partition} option.
|
||||
|
||||
|
||||
{title:Reference}
|
||||
|
||||
{p 4 8 2}{cmd:Roussos L. A, Stout W. F. and Marden J. I.}, {it:Using new proximity measures with hierarchical cluster analysis to detect multidimensionality}. Journal of Educational Measurement, {cmd:35}(1), pp 1-30, 1998.
|
||||
|
||||
{p 4 8 2}{cmd:Zhang J. and Stout W. F.}, {it:The theorical DETECT index of dimensionality and its application to approximate simple structure}. Psychometrika, {cmd:64}(2), pp 213-249, 1999.
|
||||
|
||||
{title:Also see}
|
||||
|
||||
{p 4 13 2} help for {help cluster}, help for {help detect} (if installed)
|
||||
|
||||
{title:Author}
|
||||
|
||||
{p 4 8 2}Jean-Benoit Hardouin, PhD, assistant professor{p_end}
|
||||
{p 4 8 2}EA 4275 SPHERE "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}Website {browse "http://www.anaqol.org":AnaQol}
|
@ -1,464 +0,0 @@
|
||||
*! Version 3.2 15 April 2010
|
||||
*! Jean-Benoit Hardouin
|
||||
************************************************************************************************************
|
||||
* hcavar: Hierachical Clusters Analysis (HCA) of variables
|
||||
* Version 3.2: April 15, 2010 /* Possibility to use Polytomous Items with CCOR, CCOV and MH*/
|
||||
*
|
||||
* Use the Detect Stata program (ssc install detect)
|
||||
*
|
||||
* Historic :
|
||||
* Under the name of -hcaccprox-
|
||||
* Version 1 [2004-01-18], Jean-Benoit Hardouin
|
||||
* Version 2 [2004-05-12], Jean-Benoit Hardouin
|
||||
* Version 3 [2005-12-31], Jean-Benoit Hardouin
|
||||
* Version 3.1 [2006-01-15], Jean-Benoit Hardouin /* correction if there is only one individual with a given score*/
|
||||
*
|
||||
* Jean-benoit Hardouin - Department of Biomathematics and Biostatistics - University of Nantes - France
|
||||
* EA 4275 "Biostatistics, Clinical Research and Subjective Measures in Health Sciences"
|
||||
* jean-benoit.hardouin@univ-nantes.fr
|
||||
*
|
||||
* News about this program :http://www.anaqol.org
|
||||
*
|
||||
* Copyright 2004-2006, 2010 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 hcavar , rclass
|
||||
version 9
|
||||
syntax varlist(min=2 numeric) [,PROX(string) METHod(string) PARTition(numlist) MEASures DETect MATrix(string) noDENDROgram]
|
||||
|
||||
tempfile hcaccproxfile
|
||||
qui save `hcaccproxfile',replace
|
||||
preserve
|
||||
|
||||
local nbitems : word count `varlist'
|
||||
tokenize `varlist'
|
||||
local type=0
|
||||
forvalues i=1/`nbitems' {
|
||||
qui drop if ``i''==.
|
||||
qui inspect ``i''
|
||||
if r(N_unique)>`type'&r(N_unique)!=. {
|
||||
local type=r(N_unique)
|
||||
}
|
||||
else if r(N_unique)>`type'&r(N_unique)==. {
|
||||
local type "100"
|
||||
}
|
||||
}
|
||||
if `type'==100 {
|
||||
local type ">99"
|
||||
}
|
||||
|
||||
tempname proximity whereitems
|
||||
|
||||
local prox=lower("`prox'")
|
||||
local method=lower("`method'")
|
||||
matrix define `proximity'=J(`nbitems',`nbitems',0)
|
||||
matrix define `whereitems'=J(`=`nbitems'-1',`nbitems',0)
|
||||
|
||||
/**************************PROXIMITIES MEASURES DESCRIPTION************************/
|
||||
|
||||
if "`matrix'"!="" {
|
||||
local desprox="Defined by the user"
|
||||
}
|
||||
if "`prox'"=="" {
|
||||
local prox="pearson"
|
||||
}
|
||||
else if "`prox'"=="a" {
|
||||
local prox="jaccard"
|
||||
}
|
||||
else if "`prox'"=="ad" {
|
||||
local prox="matching"
|
||||
}
|
||||
else if "`prox'"=="corr" {
|
||||
local prox="pearson"
|
||||
}
|
||||
if "`type'">"2"&"`prox'"!="pearson"&"`prox'"!="ccov"&"`prox'"!="ccor"&"`prox'"!="mh" {
|
||||
di in red "Only the {hi:pearson}, {hi:ccov} and {hi:ccor} measures of proximity are available with ordinal or numerous variables"
|
||||
di in red "Please correct your {hi:prox} option."
|
||||
exit
|
||||
}
|
||||
if "`type'">"2"&"`detect'"!="" {
|
||||
di in ye "The {hi:detect} option is available only with binary variables. This option is disabled."
|
||||
local detect
|
||||
di
|
||||
}
|
||||
local existmeas=0
|
||||
foreach i in jaccard matching pearson russel dice ccor mh ccov {
|
||||
if "`prox'"=="`i'" {
|
||||
local existmeas=1
|
||||
}
|
||||
}
|
||||
if `existmeas'==0 {
|
||||
di in red "You must define an existing measure of proximity (jaccard(a), matching(ad), pearson(cor), russel, dice, ccov, ccor, mh)."
|
||||
di in red "Please correct your {hi:prox} option."
|
||||
exit
|
||||
}
|
||||
if "`prox'"=="ccov"|"`prox'"=="mh" {
|
||||
local proxmin=0
|
||||
}
|
||||
|
||||
if "`prox'"=="matching" {
|
||||
local desprox="Matching"
|
||||
}
|
||||
else if "`prox'"=="jaccard" {
|
||||
local desprox="Jaccard"
|
||||
}
|
||||
else if "`prox'"=="russel" {
|
||||
local desprox="Russel"
|
||||
}
|
||||
else if "`prox'"=="dice" {
|
||||
local desprox="Dice"
|
||||
}
|
||||
else if "`prox'"=="pearson" {
|
||||
local desprox="Pearson"
|
||||
}
|
||||
else if "`prox'"=="ccov" {
|
||||
local desprox="Conditional covariances"
|
||||
}
|
||||
else if "`prox'"=="ccor" {
|
||||
local desprox="Conditional correlations"
|
||||
}
|
||||
else if "`prox'"=="mh" {
|
||||
local desprox="Mantel Hanzel"
|
||||
}
|
||||
|
||||
/**************************PROXIMITIES MEASURES DESCRIPTION************************/
|
||||
|
||||
if "`method'"=="upgma"|"`method'"=="" {
|
||||
local method="average"
|
||||
}
|
||||
if "`method'"=="wpgma"|"`method'"=="" {
|
||||
local method="waverage"
|
||||
}
|
||||
local vermethod=0
|
||||
foreach i in average waverage single centroid median complete wards {
|
||||
if "`method'"=="`i'" {
|
||||
local vermethod=1
|
||||
}
|
||||
}
|
||||
|
||||
if `vermethod'==0 {
|
||||
di in red "You must define an existing method to define the proximity between two clusters of items:"
|
||||
di in red _col(10) "- single: single linkage"
|
||||
di in red _col(10) "- complete: complete linkage "
|
||||
di in red _col(10) "- average(UPGMA): Unweighted Pair-Group Method of Average"
|
||||
di in red _col(10) "- waverage(WPGMA): Unweighted Pair-Group Method of Average"
|
||||
di in red _col(10) "- wards: Ward's linkage"
|
||||
di in red "Please correct your method option"
|
||||
exit
|
||||
}
|
||||
if "`method'"=="single"|"`method'"=="singlelinkage" {
|
||||
local method single
|
||||
local desmethod="Single linkage"
|
||||
}
|
||||
else if "`method'"=="complete"|"`method'"=="completelinkage" {
|
||||
local desmethod="Complete linkage"
|
||||
}
|
||||
else if "`method'"=="median"|"`method'"=="medianlinkage" {
|
||||
local desmethod="Median linkage (no dendrogram)"
|
||||
}
|
||||
else if "`method'"=="centroid"|"`method'"=="centroidlinkage" {
|
||||
local desmethod="Centroid linkage (no dendrogram)"
|
||||
}
|
||||
else if "`method'"=="average"|"`method'"=="averagelinkage" {
|
||||
local desmethod="Unweighted Pair-Group Method of Average"
|
||||
}
|
||||
else if "`method'"=="waverage"|"`method'"=="waveragelinkage" {
|
||||
local desmethod="Weighted Pair-Group Method of Average"
|
||||
}
|
||||
else if "`method'"=="wards"|"`method'"=="wardslinkage" {
|
||||
local desmethod="Ward's linkage"
|
||||
}
|
||||
|
||||
forvalues i=1/`nbitems' {
|
||||
matrix `whereitems'[1,`i']=`i'
|
||||
}
|
||||
|
||||
tempvar score
|
||||
genscore `varlist',score(`score')
|
||||
qui su `score'
|
||||
local maxscore=r(max)
|
||||
forvalues k=0/`maxscore' {
|
||||
qui count if `score'==`k'
|
||||
local nk`k'=r(N)
|
||||
}
|
||||
|
||||
qui count
|
||||
local N=r(N)
|
||||
|
||||
|
||||
di in green "{hline 80}"
|
||||
di in green "Number of individuals with none missing values: " in ye `N'
|
||||
di in green "Maximal number of modalities for a variable: " in ye "`type'"
|
||||
di in green "Proximity measures: " in ye "`desprox'"
|
||||
di in green "Method to aggregate clusters: " in ye "`desmethod'"
|
||||
di in green "{hline 80}"
|
||||
di
|
||||
di
|
||||
|
||||
/*************************Measure of proximities*********************************/
|
||||
if "`matrix'"=="" {
|
||||
forvalues i=1/`nbitems' {
|
||||
forvalues j=`=`i'+1'/`nbitems' {
|
||||
/***********************************Proximity AD*************************/
|
||||
if "`prox'"=="matching" { /*ad*/
|
||||
qui count if ``i''==1&``j''==1
|
||||
local tmp11=r(N)
|
||||
qui count if ``i''==0&``j''==0
|
||||
local tmp00=r(N)
|
||||
|
||||
matrix `proximity'[`i',`j']=sqrt(1-(`tmp11'+`tmp00')/`N')
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
|
||||
/***********************************Proximity A**************************/
|
||||
else if "`prox'"=="jaccard" { /*a*/
|
||||
qui count if ``i''==1&``j''==1
|
||||
local tmp11=r(N)
|
||||
qui count if ``i''==0&``j''==0
|
||||
local tmp00=r(N)
|
||||
|
||||
matrix `proximity'[`i',`j']=sqrt(1-`tmp11'/(`N'-`tmp00'))
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
|
||||
/***********************************Proximity Russel**************************/
|
||||
else if "`prox'"=="russel" {
|
||||
qui count if ``i''==1&``j''==1
|
||||
local tmp11=r(N)
|
||||
|
||||
matrix `proximity'[`i',`j']=sqrt(1-`tmp11'/`N')
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
|
||||
/***********************************Proximity A**************************/
|
||||
else if "`prox'"=="dice" {
|
||||
qui count if ``i''==1&``j''==1
|
||||
local tmp11=r(N)
|
||||
qui count if ``i''==0&``j''==0
|
||||
local tmp00=r(N)
|
||||
|
||||
matrix `proximity'[`i',`j']=sqrt(1-2*`tmp11'/(`N'+`tmp11'-`tmp00'))
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
|
||||
/**********************************Proximity COR*************************/
|
||||
else if "`prox'"=="pearson" { /*corr*/
|
||||
qui corr ``i'' ``j''
|
||||
matrix `proximity'[`i',`j']=sqrt(2*(1-r(rho)))
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
|
||||
/***********************************Proximity CCOV**********************/
|
||||
else if "`prox'"=="ccov" {
|
||||
local dij=0
|
||||
local Ntemp=`N'
|
||||
forvalues k=1/`=`maxscore'-1' {
|
||||
if `nk`k''!=0 {
|
||||
if `nk`k''>1 {
|
||||
qui corr ``i'' ``j'' if `score'==`k',cov
|
||||
local covi`i'j`j'k`k'=r(cov_12)
|
||||
}
|
||||
else if `nk`k''==1 {
|
||||
local Ntemp=`Ntemp'-1
|
||||
local covi`i'j`j'k`k'=0
|
||||
}
|
||||
else {
|
||||
local covi`i'j`j'k`k'=0
|
||||
}
|
||||
local dij=`dij'+`covi`i'j`j'k`k''*`nk`k''
|
||||
}
|
||||
}
|
||||
|
||||
matrix `proximity'[`i',`j']=-`dij'/`Ntemp'
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
if `proxmin'<`dij'/`Ntemp' {
|
||||
local proxmin=`dij'/`Ntemp'
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************Proximity CCOR**********************/
|
||||
|
||||
else if "`prox'"=="ccor" {
|
||||
local dij=0
|
||||
local nnull=0
|
||||
local Ntemp=`N'
|
||||
forvalues k=1/`=`maxscore'-1' {
|
||||
if `nk`k''!=0 {
|
||||
if `nk`k''>1 {
|
||||
qui corr ``i'' ``j'' if `score'==`k'
|
||||
local cori`i'j`j'k`k'=r(rho)
|
||||
}
|
||||
else if `nk`k''==1 {
|
||||
local Ntemp=`Ntemp'-1
|
||||
local cori`i'j`j'k`k'=0
|
||||
}
|
||||
else {
|
||||
local cori`i'j`j'k`k'=0
|
||||
}
|
||||
if `cori`i'j`j'k`k''!=. {
|
||||
local dij=`dij'+`cori`i'j`j'k`k''*`nk`k''
|
||||
}
|
||||
else if `cori`i'j`j'k`k''==. {
|
||||
local nnull=`nnull'+`nk`k''
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
matrix `proximity'[`i',`j']=sqrt(2*(1-`dij'/(`Ntemp'-`nnull')))
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
|
||||
|
||||
/***********************************Proximity MH************************/
|
||||
|
||||
else if "`prox'"=="mh" {
|
||||
local numij=0
|
||||
local denom=0
|
||||
forvalues k=1/`=`maxscore'-1' {
|
||||
if `nk`k''!=0 {
|
||||
qui count if ``i''==1&``j''==1&`score'==`k'
|
||||
local A=r(N)
|
||||
qui count if ``i''==0&``j''==1&`score'==`k'
|
||||
local B=r(N)
|
||||
qui count if ``i''==1&``j''==0&`score'==`k'
|
||||
local C=r(N)
|
||||
qui count if ``i''==0&``j''==0&`score'==`k'
|
||||
local D=r(N)
|
||||
local numij=`numij'+`A'*`D'/`nk`k''
|
||||
local denomij=`denomij'+`B'*`C'/`nk`k''
|
||||
}
|
||||
}
|
||||
|
||||
matrix `proximity'[`i',`j']=-log(`numij'/`denomij')
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
if `proxmin'<log(`numij'/`denomij') {
|
||||
local proxmin=-`proximity'[`i',`j']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if "`prox'"=="ccov"|"`prox'"=="mh" {
|
||||
forvalues i=1/`nbitems' {
|
||||
forvalues j=`=`i'+1'/`nbitems' {
|
||||
matrix `proximity'[`i',`j']=`proximity'[`i',`j']+`proxmin'
|
||||
if `proximity'[`i',`j']<0 {
|
||||
matrix `proximity'[`i',`j']=0
|
||||
}
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**********************END OD THE COMPUTING OF THE PROXIMITIES**************************************/
|
||||
else {
|
||||
matrix `proximity'=`matrix'
|
||||
}
|
||||
|
||||
matrix rowname `proximity'=`varlist'
|
||||
matrix colname `proximity'=`varlist'
|
||||
|
||||
if "`measures'"!="" {
|
||||
di in green "{hline 50}"
|
||||
di in green "Measures of proximity between the items"
|
||||
di in green "{hline 50}"
|
||||
matrix list `proximity', noheader
|
||||
di
|
||||
}
|
||||
|
||||
/**********************CLUSTERING PROCEDURE **********************************************/
|
||||
|
||||
|
||||
qui clustermat `method' `proximity',clear labelvar(name)
|
||||
local hor "hor"
|
||||
if "`method'"!="centroid"&"`method'"!="median"&"`dendrogram'"=="" {
|
||||
qui cluster dendro ,labels(name) hor ylabel(,angle(0)) title("Hierarchical Cluster Analysis on variables") subtitle("`desmethod'") xtitle("`desprox' proximities")
|
||||
}
|
||||
|
||||
if "`partition'"!="" {
|
||||
foreach i of numlist `partition' {
|
||||
qui cluster gen cluster`i'=group(`i')
|
||||
}
|
||||
tempname clusters
|
||||
mkmat cluster* ,mat(`clusters')
|
||||
matrix rownames `clusters'=`varlist'
|
||||
local compteur=0
|
||||
foreach i of numlist `partition' {
|
||||
local ++compteur
|
||||
di
|
||||
di in green "{hline 30}"
|
||||
di in green "Partition in `i' cluster(s)"
|
||||
di in green "{hline 30}"
|
||||
di
|
||||
forvalues j=1/`i' {
|
||||
local cluster`i'_`j'
|
||||
local nbi`i'_`j'=0
|
||||
forvalues k=1/`nbitems' {
|
||||
if `clusters'[`k',`compteur']==`j' {
|
||||
local cluster`i'_`j' `cluster`i'_`j'' ``k''
|
||||
local ++nbi`i'_`j'
|
||||
}
|
||||
}
|
||||
di in green "Cluster `j': " in ye "`cluster`i'_`j''"
|
||||
}
|
||||
}
|
||||
return matrix clusters=`clusters'
|
||||
}
|
||||
|
||||
/**********************DETECT OPTION **************************************************/
|
||||
|
||||
use `hcaccproxfile',clear
|
||||
if "`detect'"!="" {
|
||||
foreach i of numlist `partition' {
|
||||
local liste
|
||||
local part
|
||||
forvalues j=1/`i' {
|
||||
local liste "`liste' `cluster`i'_`j''"
|
||||
local part "`part' `nbi`i'_`j''"
|
||||
}
|
||||
qui detect `liste',part(`part')
|
||||
local detect`i'=r(DETECT)
|
||||
local Iss`i'=r(Iss)
|
||||
local R`i'=r(R)
|
||||
}
|
||||
tempname indexes
|
||||
matrix define `indexes'=J(`compteur',4,0)
|
||||
matrix colnames `indexes'=Clusters DETECT Iss R
|
||||
di ""
|
||||
di in green "{hline 50}"
|
||||
di in green "Indexes to compare the partitions of the items"
|
||||
di in green "{hline 50}"
|
||||
di ""
|
||||
di in green _col(29) "DETECT" _col(43) "Iss" _col(56) "R"
|
||||
local compteur=0
|
||||
foreach k of numlist `partition' {
|
||||
local ++compteur
|
||||
matrix `indexes'[`compteur',1]=`k'
|
||||
matrix `indexes'[`compteur',2]=`detect`k''
|
||||
matrix `indexes'[`compteur',3]=`Iss`k''
|
||||
matrix `indexes'[`compteur',4]=`R`k''
|
||||
di _col(5) in green "`k' cluster(s):" _col(27) in yellow %8.5f `detect`k'' _col(38) %8.5f `Iss`k'' _col(49) %8.5f `R`k''
|
||||
}
|
||||
return matrix indexes=`indexes'
|
||||
}
|
||||
return local nbvar=`nbitems'
|
||||
return matrix measures=`proximity'
|
||||
restore, not
|
||||
*use `hcaccproxfile',clear
|
||||
|
||||
end
|
@ -1,488 +0,0 @@
|
||||
*! Version 3.3 6 May 2014
|
||||
*! Jean-Benoit Hardouin
|
||||
************************************************************************************************************
|
||||
* hcavar: Hierachical Clusters Analysis (HCA) of variables
|
||||
* Version 3.3: May 7, 2014 /* HTML option, if option*/
|
||||
*
|
||||
* Use the Detect Stata program (ssc install detect)
|
||||
*
|
||||
* Historic :
|
||||
* Under the name of -hcaccprox-
|
||||
* Version 1 [2004-01-18], Jean-Benoit Hardouin
|
||||
* Version 2 [2004-05-12], Jean-Benoit Hardouin
|
||||
* Version 3 [2005-12-31], Jean-Benoit Hardouin
|
||||
* Version 3.1 [2006-01-15], Jean-Benoit Hardouin /* correction if there is only one individual with a given score*/
|
||||
* Version 3.2 [2010-04-15], Jean-Benoit Hardouin /* Possibility to use Polytomous Items with CCOR, CCOV and MH*/
|
||||
* Version 3.3 [2014-05-07], Jean-Benoit Hardouin, Bastien Perrot /* HTML option,, if option*/
|
||||
*
|
||||
* Jean-benoit Hardouin - Department of Biomathematics and Biostatistics - University of Nantes - France
|
||||
* EA 4275 "Biostatistics, Clinical Research and Subjective Measures in Health Sciences"
|
||||
* jean-benoit.hardouin@univ-nantes.fr
|
||||
*
|
||||
* News about this program :http://www.anaqol.org
|
||||
*
|
||||
* Copyright 2004-2006, 2010 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 hcavar33, rclass
|
||||
version 9
|
||||
syntax varlist(min=2 numeric) [if] [in] [,PROX(string) METHod(string) PARTition(numlist) MEASures DETect MATrix(string) noDENDROgram HTML(string)]
|
||||
|
||||
tempfile hcaccproxfile
|
||||
qui save `hcaccproxfile',replace
|
||||
preserve
|
||||
|
||||
if "`if'"!="" {
|
||||
qui keep `if'
|
||||
}
|
||||
|
||||
if "`html'"!="" {
|
||||
//set scheme sj
|
||||
//local htmlregion "graphregion(fcolor(white) ifcolor(white))"
|
||||
di "<!-- SphereCalc start of response -->"
|
||||
di "<pre>"
|
||||
}
|
||||
|
||||
local nbitems : word count `varlist'
|
||||
tokenize `varlist'
|
||||
local type=0
|
||||
forvalues i=1/`nbitems' {
|
||||
qui drop if ``i''==.
|
||||
qui inspect ``i''
|
||||
if r(N_unique)>`type'&r(N_unique)!=. {
|
||||
local type=r(N_unique)
|
||||
}
|
||||
else if r(N_unique)>`type'&r(N_unique)==. {
|
||||
local type "100"
|
||||
}
|
||||
}
|
||||
if `type'==100 {
|
||||
local type ">99"
|
||||
}
|
||||
|
||||
tempname proximity whereitems
|
||||
|
||||
local prox=lower("`prox'")
|
||||
local method=lower("`method'")
|
||||
matrix define `proximity'=J(`nbitems',`nbitems',0)
|
||||
matrix define `whereitems'=J(`=`nbitems'-1',`nbitems',0)
|
||||
|
||||
/**************************PROXIMITIES MEASURES DESCRIPTION************************/
|
||||
|
||||
if "`matrix'"!="" {
|
||||
local desprox="Defined by the user"
|
||||
}
|
||||
if "`prox'"=="" {
|
||||
local prox="pearson"
|
||||
}
|
||||
else if "`prox'"=="a" {
|
||||
local prox="jaccard"
|
||||
}
|
||||
else if "`prox'"=="ad" {
|
||||
local prox="matching"
|
||||
}
|
||||
else if "`prox'"=="corr" {
|
||||
local prox="pearson"
|
||||
}
|
||||
if "`type'">"2"&"`prox'"!="pearson"&"`prox'"!="ccov"&"`prox'"!="ccor"&"`prox'"!="mh" {
|
||||
di in red "Only the {hi:pearson}, {hi:ccov} and {hi:ccor} measures of proximity are available with ordinal or numerous variables"
|
||||
di in red "Please correct your {hi:prox} option."
|
||||
exit
|
||||
}
|
||||
if "`type'">"2"&"`detect'"!="" {
|
||||
di in ye "The {hi:detect} option is available only with binary variables. This option is disabled."
|
||||
local detect
|
||||
di
|
||||
}
|
||||
local existmeas=0
|
||||
foreach i in jaccard matching pearson russel dice ccor mh ccov {
|
||||
if "`prox'"=="`i'" {
|
||||
local existmeas=1
|
||||
}
|
||||
}
|
||||
if `existmeas'==0 {
|
||||
di in red "You must define an existing measure of proximity (jaccard(a), matching(ad), pearson(cor), russel, dice, ccov, ccor, mh)."
|
||||
di in red "Please correct your {hi:prox} option."
|
||||
exit
|
||||
}
|
||||
if "`prox'"=="ccov"|"`prox'"=="mh" {
|
||||
local proxmin=0
|
||||
}
|
||||
|
||||
if "`prox'"=="matching" {
|
||||
local desprox="Matching"
|
||||
}
|
||||
else if "`prox'"=="jaccard" {
|
||||
local desprox="Jaccard"
|
||||
}
|
||||
else if "`prox'"=="russel" {
|
||||
local desprox="Russel"
|
||||
}
|
||||
else if "`prox'"=="dice" {
|
||||
local desprox="Dice"
|
||||
}
|
||||
else if "`prox'"=="pearson" {
|
||||
local desprox="Pearson"
|
||||
}
|
||||
else if "`prox'"=="ccov" {
|
||||
local desprox="Conditional covariances"
|
||||
}
|
||||
else if "`prox'"=="ccor" {
|
||||
local desprox="Conditional correlations"
|
||||
}
|
||||
else if "`prox'"=="mh" {
|
||||
local desprox="Mantel Hanzel"
|
||||
}
|
||||
|
||||
/**************************PROXIMITIES MEASURES DESCRIPTION************************/
|
||||
|
||||
if "`method'"=="upgma"|"`method'"=="" {
|
||||
local method="average"
|
||||
}
|
||||
if "`method'"=="wpgma"|"`method'"=="" {
|
||||
local method="waverage"
|
||||
}
|
||||
local vermethod=0
|
||||
foreach i in average waverage single centroid median complete wards {
|
||||
if "`method'"=="`i'" {
|
||||
local vermethod=1
|
||||
}
|
||||
}
|
||||
|
||||
if `vermethod'==0 {
|
||||
di in red "You must define an existing method to define the proximity between two clusters of items:"
|
||||
di in red _col(10) "- single: single linkage"
|
||||
di in red _col(10) "- complete: complete linkage "
|
||||
di in red _col(10) "- average(UPGMA): Unweighted Pair-Group Method of Average"
|
||||
di in red _col(10) "- waverage(WPGMA): Unweighted Pair-Group Method of Average"
|
||||
di in red _col(10) "- wards: Ward's linkage"
|
||||
di in red "Please correct your method option"
|
||||
exit
|
||||
}
|
||||
if "`method'"=="single"|"`method'"=="singlelinkage" {
|
||||
local method single
|
||||
local desmethod="Single linkage"
|
||||
}
|
||||
else if "`method'"=="complete"|"`method'"=="completelinkage" {
|
||||
local desmethod="Complete linkage"
|
||||
}
|
||||
else if "`method'"=="median"|"`method'"=="medianlinkage" {
|
||||
local desmethod="Median linkage (no dendrogram)"
|
||||
}
|
||||
else if "`method'"=="centroid"|"`method'"=="centroidlinkage" {
|
||||
local desmethod="Centroid linkage (no dendrogram)"
|
||||
}
|
||||
else if "`method'"=="average"|"`method'"=="averagelinkage" {
|
||||
local desmethod="Unweighted Pair-Group Method of Average"
|
||||
}
|
||||
else if "`method'"=="waverage"|"`method'"=="waveragelinkage" {
|
||||
local desmethod="Weighted Pair-Group Method of Average"
|
||||
}
|
||||
else if "`method'"=="wards"|"`method'"=="wardslinkage" {
|
||||
local desmethod="Ward's linkage"
|
||||
}
|
||||
|
||||
forvalues i=1/`nbitems' {
|
||||
matrix `whereitems'[1,`i']=`i'
|
||||
}
|
||||
|
||||
tempvar score
|
||||
genscore `varlist',score(`score')
|
||||
qui su `score'
|
||||
local maxscore=r(max)
|
||||
forvalues k=0/`maxscore' {
|
||||
qui count if `score'==`k'
|
||||
local nk`k'=r(N)
|
||||
}
|
||||
|
||||
qui count
|
||||
local N=r(N)
|
||||
|
||||
|
||||
di in green "{hline 80}"
|
||||
di in green "Number of individuals with none missing values: " in ye `N'
|
||||
di in green "Maximal number of modalities for a variable: " in ye "`type'"
|
||||
di in green "Proximity measures: " in ye "`desprox'"
|
||||
di in green "Method to aggregate clusters: " in ye "`desmethod'"
|
||||
di in green "{hline 80}"
|
||||
di
|
||||
di
|
||||
|
||||
/*************************Measure of proximities*********************************/
|
||||
if "`matrix'"=="" {
|
||||
forvalues i=1/`nbitems' {
|
||||
forvalues j=`=`i'+1'/`nbitems' {
|
||||
/***********************************Proximity AD*************************/
|
||||
if "`prox'"=="matching" { /*ad*/
|
||||
qui count if ``i''==1&``j''==1
|
||||
local tmp11=r(N)
|
||||
qui count if ``i''==0&``j''==0
|
||||
local tmp00=r(N)
|
||||
|
||||
matrix `proximity'[`i',`j']=sqrt(1-(`tmp11'+`tmp00')/`N')
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
|
||||
/***********************************Proximity A**************************/
|
||||
else if "`prox'"=="jaccard" { /*a*/
|
||||
qui count if ``i''==1&``j''==1
|
||||
local tmp11=r(N)
|
||||
qui count if ``i''==0&``j''==0
|
||||
local tmp00=r(N)
|
||||
|
||||
matrix `proximity'[`i',`j']=sqrt(1-`tmp11'/(`N'-`tmp00'))
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
|
||||
/***********************************Proximity Russel**************************/
|
||||
else if "`prox'"=="russel" {
|
||||
qui count if ``i''==1&``j''==1
|
||||
local tmp11=r(N)
|
||||
|
||||
matrix `proximity'[`i',`j']=sqrt(1-`tmp11'/`N')
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
|
||||
/***********************************Proximity A**************************/
|
||||
else if "`prox'"=="dice" {
|
||||
qui count if ``i''==1&``j''==1
|
||||
local tmp11=r(N)
|
||||
qui count if ``i''==0&``j''==0
|
||||
local tmp00=r(N)
|
||||
|
||||
matrix `proximity'[`i',`j']=sqrt(1-2*`tmp11'/(`N'+`tmp11'-`tmp00'))
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
|
||||
/**********************************Proximity COR*************************/
|
||||
else if "`prox'"=="pearson" { /*corr*/
|
||||
qui corr ``i'' ``j''
|
||||
matrix `proximity'[`i',`j']=sqrt(2*(1-r(rho)))
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
|
||||
/***********************************Proximity CCOV**********************/
|
||||
else if "`prox'"=="ccov" {
|
||||
local dij=0
|
||||
local Ntemp=`N'
|
||||
forvalues k=1/`=`maxscore'-1' {
|
||||
if `nk`k''!=0 {
|
||||
if `nk`k''>1 {
|
||||
qui corr ``i'' ``j'' if `score'==`k',cov
|
||||
local covi`i'j`j'k`k'=r(cov_12)
|
||||
}
|
||||
else if `nk`k''==1 {
|
||||
local Ntemp=`Ntemp'-1
|
||||
local covi`i'j`j'k`k'=0
|
||||
}
|
||||
else {
|
||||
local covi`i'j`j'k`k'=0
|
||||
}
|
||||
local dij=`dij'+`covi`i'j`j'k`k''*`nk`k''
|
||||
}
|
||||
}
|
||||
|
||||
matrix `proximity'[`i',`j']=-`dij'/`Ntemp'
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
if `proxmin'<`dij'/`Ntemp' {
|
||||
local proxmin=`dij'/`Ntemp'
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************Proximity CCOR**********************/
|
||||
|
||||
else if "`prox'"=="ccor" {
|
||||
local dij=0
|
||||
local nnull=0
|
||||
local Ntemp=`N'
|
||||
forvalues k=1/`=`maxscore'-1' {
|
||||
if `nk`k''!=0 {
|
||||
if `nk`k''>1 {
|
||||
qui corr ``i'' ``j'' if `score'==`k'
|
||||
local cori`i'j`j'k`k'=r(rho)
|
||||
}
|
||||
else if `nk`k''==1 {
|
||||
local Ntemp=`Ntemp'-1
|
||||
local cori`i'j`j'k`k'=0
|
||||
}
|
||||
else {
|
||||
local cori`i'j`j'k`k'=0
|
||||
}
|
||||
if `cori`i'j`j'k`k''!=. {
|
||||
local dij=`dij'+`cori`i'j`j'k`k''*`nk`k''
|
||||
}
|
||||
else if `cori`i'j`j'k`k''==. {
|
||||
local nnull=`nnull'+`nk`k''
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
matrix `proximity'[`i',`j']=sqrt(2*(1-`dij'/(`Ntemp'-`nnull')))
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
|
||||
|
||||
/***********************************Proximity MH************************/
|
||||
|
||||
else if "`prox'"=="mh" {
|
||||
local numij=0
|
||||
local denom=0
|
||||
forvalues k=1/`=`maxscore'-1' {
|
||||
if `nk`k''!=0 {
|
||||
qui count if ``i''==1&``j''==1&`score'==`k'
|
||||
local A=r(N)
|
||||
qui count if ``i''==0&``j''==1&`score'==`k'
|
||||
local B=r(N)
|
||||
qui count if ``i''==1&``j''==0&`score'==`k'
|
||||
local C=r(N)
|
||||
qui count if ``i''==0&``j''==0&`score'==`k'
|
||||
local D=r(N)
|
||||
local numij=`numij'+`A'*`D'/`nk`k''
|
||||
local denomij=`denomij'+`B'*`C'/`nk`k''
|
||||
}
|
||||
}
|
||||
|
||||
matrix `proximity'[`i',`j']=-log(`numij'/`denomij')
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
if `proxmin'<log(`numij'/`denomij') {
|
||||
local proxmin=-`proximity'[`i',`j']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if "`prox'"=="ccov"|"`prox'"=="mh" {
|
||||
forvalues i=1/`nbitems' {
|
||||
forvalues j=`=`i'+1'/`nbitems' {
|
||||
matrix `proximity'[`i',`j']=`proximity'[`i',`j']+`proxmin'
|
||||
if `proximity'[`i',`j']<0 {
|
||||
matrix `proximity'[`i',`j']=0
|
||||
}
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**********************END OD THE COMPUTING OF THE PROXIMITIES**************************************/
|
||||
else {
|
||||
matrix `proximity'=`matrix'
|
||||
}
|
||||
|
||||
matrix rowname `proximity'=`varlist'
|
||||
matrix colname `proximity'=`varlist'
|
||||
|
||||
if "`measures'"!="" {
|
||||
di in green "{hline 50}"
|
||||
di in green "Measures of proximity between the items"
|
||||
di in green "{hline 50}"
|
||||
matrix list `proximity', noheader
|
||||
di
|
||||
}
|
||||
|
||||
/**********************CLUSTERING PROCEDURE **********************************************/
|
||||
|
||||
|
||||
qui clustermat `method' `proximity',clear labelvar(name)
|
||||
local hor "hor"
|
||||
if "`method'"!="centroid"&"`method'"!="median"&"`dendrogram'"=="" {
|
||||
if "`html'" != "" {
|
||||
qui local saving "saving(`c(tmpdir)'/`html'_dendro,replace) nodraw"
|
||||
qui cluster dendro ,labels(name) hor ylabel(,angle(0)) title("Hierarchical Cluster Analysis on variables") subtitle("`desmethod'") xtitle("`desprox' proximities") `saving'
|
||||
qui graph use `c(tmpdir)'/`html'_dendro.gph
|
||||
qui graph export `c(tmpdir)'/`html'_dendro.eps, replace
|
||||
di "<br />"
|
||||
di "<img src=" _char(34) "/data/`html'_dendro.png" _char(34)
|
||||
di " class=" _char(34) "resgraph" _char(34) " alt=" _char(34) "dendro" _char(34) " title= " _char(34) "Hierarchical Cluster Analysis on variables - click to enlarge" _char(34) " width=" _char(34) "350" _char(34) " height=" _char(34) "240" _char(34) " >"
|
||||
}
|
||||
else {
|
||||
qui cluster dendro ,labels(name) hor ylabel(,angle(0)) title("Hierarchical Cluster Analysis on variables") subtitle("`desmethod'") xtitle("`desprox' proximities")
|
||||
}
|
||||
}
|
||||
|
||||
if "`partition'"!="" {
|
||||
foreach i of numlist `partition' {
|
||||
qui cluster gen cluster`i'=group(`i')
|
||||
}
|
||||
tempname clusters
|
||||
mkmat cluster* ,mat(`clusters')
|
||||
matrix rownames `clusters'=`varlist'
|
||||
local compteur=0
|
||||
foreach i of numlist `partition' {
|
||||
local ++compteur
|
||||
di
|
||||
di in green "{hline 30}"
|
||||
di in green "Partition in `i' cluster(s)"
|
||||
di in green "{hline 30}"
|
||||
di
|
||||
forvalues j=1/`i' {
|
||||
local cluster`i'_`j'
|
||||
local nbi`i'_`j'=0
|
||||
forvalues k=1/`nbitems' {
|
||||
if `clusters'[`k',`compteur']==`j' {
|
||||
local cluster`i'_`j' `cluster`i'_`j'' ``k''
|
||||
local ++nbi`i'_`j'
|
||||
}
|
||||
}
|
||||
di in green "Cluster `j': " in ye "`cluster`i'_`j''"
|
||||
}
|
||||
}
|
||||
return matrix clusters=`clusters'
|
||||
}
|
||||
|
||||
/**********************DETECT OPTION **************************************************/
|
||||
|
||||
use `hcaccproxfile',clear
|
||||
if "`detect'"!="" {
|
||||
foreach i of numlist `partition' {
|
||||
local liste
|
||||
local part
|
||||
forvalues j=1/`i' {
|
||||
local liste "`liste' `cluster`i'_`j''"
|
||||
local part "`part' `nbi`i'_`j''"
|
||||
}
|
||||
qui detect `liste',part(`part')
|
||||
local detect`i'=r(DETECT)
|
||||
local Iss`i'=r(Iss)
|
||||
local R`i'=r(R)
|
||||
}
|
||||
tempname indexes
|
||||
matrix define `indexes'=J(`compteur',4,0)
|
||||
matrix colnames `indexes'=Clusters DETECT Iss R
|
||||
di ""
|
||||
di in green "{hline 50}"
|
||||
di in green "Indexes to compare the partitions of the items"
|
||||
di in green "{hline 50}"
|
||||
di ""
|
||||
di in green _col(29) "DETECT" _col(43) "Iss" _col(56) "R"
|
||||
local compteur=0
|
||||
foreach k of numlist `partition' {
|
||||
local ++compteur
|
||||
matrix `indexes'[`compteur',1]=`k'
|
||||
matrix `indexes'[`compteur',2]=`detect`k''
|
||||
matrix `indexes'[`compteur',3]=`Iss`k''
|
||||
matrix `indexes'[`compteur',4]=`R`k''
|
||||
di _col(5) in green "`k' cluster(s):" _col(27) in yellow %8.5f `detect`k'' _col(38) %8.5f `Iss`k'' _col(49) %8.5f `R`k''
|
||||
}
|
||||
return matrix indexes=`indexes'
|
||||
}
|
||||
return local nbvar=`nbitems'
|
||||
return matrix measures=`proximity'
|
||||
restore, not
|
||||
*use `hcaccproxfile',clear
|
||||
|
||||
end
|
@ -1,489 +0,0 @@
|
||||
*! Version 3.4 26 May 2014
|
||||
*! Jean-Benoit Hardouin
|
||||
************************************************************************************************************
|
||||
* hcavar: Hierachical Clusters Analysis (HCA) of variables
|
||||
* Version 3.4: May 26, 2014 /* DETECT option available for polytomous items */
|
||||
*
|
||||
* Use the Detect Stata program (ssc install detect)
|
||||
*
|
||||
* Historic :
|
||||
* Under the name of -hcaccprox-
|
||||
* Version 1 [2004-01-18], Jean-Benoit Hardouin
|
||||
* Version 2 [2004-05-12], Jean-Benoit Hardouin
|
||||
* Version 3 [2005-12-31], Jean-Benoit Hardouin
|
||||
* Version 3.1 [2006-01-15], Jean-Benoit Hardouin /* correction if there is only one individual with a given score*/
|
||||
* Version 3.2 [2010-04-15], Jean-Benoit Hardouin /* Possibility to use Polytomous Items with CCOR, CCOV and MH*/
|
||||
* Version 3.3 [2014-05-07], Jean-Benoit Hardouin, Bastien Perrot /* HTML option, if option*/
|
||||
* Version 3.4 [2014-05-26], Jean-Benoit Hardouin, Bastien Perrot /* DETECT option available for polytomous items */
|
||||
*
|
||||
* Jean-benoit Hardouin - Department of Biomathematics and Biostatistics - University of Nantes - France
|
||||
* EA 4275 "Biostatistics, Clinical Research and Subjective Measures in Health Sciences"
|
||||
* jean-benoit.hardouin@univ-nantes.fr
|
||||
*
|
||||
* News about this program :http://www.anaqol.org
|
||||
*
|
||||
* Copyright 2004-2006, 2010 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 hcavar34, rclass
|
||||
version 9
|
||||
syntax varlist(min=2 numeric) [if] [in] [,PROX(string) METHod(string) PARTition(numlist) MEASures DETect MATrix(string) noDENDROgram HTML(string)]
|
||||
|
||||
tempfile hcaccproxfile
|
||||
qui save `hcaccproxfile',replace
|
||||
preserve
|
||||
|
||||
if "`if'"!="" {
|
||||
qui keep `if'
|
||||
}
|
||||
|
||||
if "`html'"!="" {
|
||||
//set scheme sj
|
||||
//local htmlregion "graphregion(fcolor(white) ifcolor(white))"
|
||||
di "<!-- SphereCalc start of response -->"
|
||||
di "<pre>"
|
||||
}
|
||||
|
||||
local nbitems : word count `varlist'
|
||||
tokenize `varlist'
|
||||
local type=0
|
||||
forvalues i=1/`nbitems' {
|
||||
qui drop if ``i''==.
|
||||
qui inspect ``i''
|
||||
if r(N_unique)>`type'&r(N_unique)!=. {
|
||||
local type=r(N_unique)
|
||||
}
|
||||
else if r(N_unique)>`type'&r(N_unique)==. {
|
||||
local type "100"
|
||||
}
|
||||
}
|
||||
if `type'==100 {
|
||||
local type ">99"
|
||||
}
|
||||
|
||||
tempname proximity whereitems
|
||||
|
||||
local prox=lower("`prox'")
|
||||
local method=lower("`method'")
|
||||
matrix define `proximity'=J(`nbitems',`nbitems',0)
|
||||
matrix define `whereitems'=J(`=`nbitems'-1',`nbitems',0)
|
||||
|
||||
/**************************PROXIMITIES MEASURES DESCRIPTION************************/
|
||||
|
||||
if "`matrix'"!="" {
|
||||
local desprox="Defined by the user"
|
||||
}
|
||||
if "`prox'"=="" {
|
||||
local prox="pearson"
|
||||
}
|
||||
else if "`prox'"=="a" {
|
||||
local prox="jaccard"
|
||||
}
|
||||
else if "`prox'"=="ad" {
|
||||
local prox="matching"
|
||||
}
|
||||
else if "`prox'"=="corr" {
|
||||
local prox="pearson"
|
||||
}
|
||||
if "`type'">"2"&"`prox'"!="pearson"&"`prox'"!="ccov"&"`prox'"!="ccor"&"`prox'"!="mh" {
|
||||
di in red "Only the {hi:pearson}, {hi:ccov} and {hi:ccor} measures of proximity are available with ordinal or numerous variables"
|
||||
di in red "Please correct your {hi:prox} option."
|
||||
exit
|
||||
}
|
||||
|
||||
if "`partition'"==""&"`detect'"!="" {
|
||||
di in ye "option partition() required"
|
||||
error 198
|
||||
}
|
||||
local existmeas=0
|
||||
foreach i in jaccard matching pearson russel dice ccor mh ccov {
|
||||
if "`prox'"=="`i'" {
|
||||
local existmeas=1
|
||||
}
|
||||
}
|
||||
if `existmeas'==0 {
|
||||
di in red "You must define an existing measure of proximity (jaccard(a), matching(ad), pearson(cor), russel, dice, ccov, ccor, mh)."
|
||||
di in red "Please correct your {hi:prox} option."
|
||||
exit
|
||||
}
|
||||
if "`prox'"=="ccov"|"`prox'"=="mh" {
|
||||
local proxmin=0
|
||||
}
|
||||
|
||||
if "`prox'"=="matching" {
|
||||
local desprox="Matching"
|
||||
}
|
||||
else if "`prox'"=="jaccard" {
|
||||
local desprox="Jaccard"
|
||||
}
|
||||
else if "`prox'"=="russel" {
|
||||
local desprox="Russel"
|
||||
}
|
||||
else if "`prox'"=="dice" {
|
||||
local desprox="Dice"
|
||||
}
|
||||
else if "`prox'"=="pearson" {
|
||||
local desprox="Pearson"
|
||||
}
|
||||
else if "`prox'"=="ccov" {
|
||||
local desprox="Conditional covariances"
|
||||
}
|
||||
else if "`prox'"=="ccor" {
|
||||
local desprox="Conditional correlations"
|
||||
}
|
||||
else if "`prox'"=="mh" {
|
||||
local desprox="Mantel Hanzel"
|
||||
}
|
||||
|
||||
/**************************PROXIMITIES MEASURES DESCRIPTION************************/
|
||||
|
||||
if "`method'"=="upgma"|"`method'"=="" {
|
||||
local method="average"
|
||||
}
|
||||
if "`method'"=="wpgma"|"`method'"=="" {
|
||||
local method="waverage"
|
||||
}
|
||||
local vermethod=0
|
||||
foreach i in average waverage single centroid median complete wards {
|
||||
if "`method'"=="`i'" {
|
||||
local vermethod=1
|
||||
}
|
||||
}
|
||||
|
||||
if `vermethod'==0 {
|
||||
di in red "You must define an existing method to define the proximity between two clusters of items:"
|
||||
di in red _col(10) "- single: single linkage"
|
||||
di in red _col(10) "- complete: complete linkage "
|
||||
di in red _col(10) "- average(UPGMA): Unweighted Pair-Group Method of Average"
|
||||
di in red _col(10) "- waverage(WPGMA): Unweighted Pair-Group Method of Average"
|
||||
di in red _col(10) "- wards: Ward's linkage"
|
||||
di in red "Please correct your method option"
|
||||
exit
|
||||
}
|
||||
if "`method'"=="single"|"`method'"=="singlelinkage" {
|
||||
local method single
|
||||
local desmethod="Single linkage"
|
||||
}
|
||||
else if "`method'"=="complete"|"`method'"=="completelinkage" {
|
||||
local desmethod="Complete linkage"
|
||||
}
|
||||
else if "`method'"=="median"|"`method'"=="medianlinkage" {
|
||||
local desmethod="Median linkage (no dendrogram)"
|
||||
}
|
||||
else if "`method'"=="centroid"|"`method'"=="centroidlinkage" {
|
||||
local desmethod="Centroid linkage (no dendrogram)"
|
||||
}
|
||||
else if "`method'"=="average"|"`method'"=="averagelinkage" {
|
||||
local desmethod="Unweighted Pair-Group Method of Average"
|
||||
}
|
||||
else if "`method'"=="waverage"|"`method'"=="waveragelinkage" {
|
||||
local desmethod="Weighted Pair-Group Method of Average"
|
||||
}
|
||||
else if "`method'"=="wards"|"`method'"=="wardslinkage" {
|
||||
local desmethod="Ward's linkage"
|
||||
}
|
||||
|
||||
forvalues i=1/`nbitems' {
|
||||
matrix `whereitems'[1,`i']=`i'
|
||||
}
|
||||
|
||||
tempvar score
|
||||
genscore `varlist',score(`score')
|
||||
qui su `score'
|
||||
local maxscore=r(max)
|
||||
forvalues k=0/`maxscore' {
|
||||
qui count if `score'==`k'
|
||||
local nk`k'=r(N)
|
||||
}
|
||||
|
||||
qui count
|
||||
local N=r(N)
|
||||
|
||||
|
||||
di in green "{hline 80}"
|
||||
di in green "Number of individuals with none missing values: " in ye `N'
|
||||
di in green "Maximal number of modalities for a variable: " in ye "`type'"
|
||||
di in green "Proximity measures: " in ye "`desprox'"
|
||||
di in green "Method to aggregate clusters: " in ye "`desmethod'"
|
||||
di in green "{hline 80}"
|
||||
di
|
||||
di
|
||||
|
||||
/*************************Measure of proximities*********************************/
|
||||
if "`matrix'"=="" {
|
||||
forvalues i=1/`nbitems' {
|
||||
forvalues j=`=`i'+1'/`nbitems' {
|
||||
/***********************************Proximity AD*************************/
|
||||
if "`prox'"=="matching" { /*ad*/
|
||||
qui count if ``i''==1&``j''==1
|
||||
local tmp11=r(N)
|
||||
qui count if ``i''==0&``j''==0
|
||||
local tmp00=r(N)
|
||||
|
||||
matrix `proximity'[`i',`j']=sqrt(1-(`tmp11'+`tmp00')/`N')
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
|
||||
/***********************************Proximity A**************************/
|
||||
else if "`prox'"=="jaccard" { /*a*/
|
||||
qui count if ``i''==1&``j''==1
|
||||
local tmp11=r(N)
|
||||
qui count if ``i''==0&``j''==0
|
||||
local tmp00=r(N)
|
||||
|
||||
matrix `proximity'[`i',`j']=sqrt(1-`tmp11'/(`N'-`tmp00'))
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
|
||||
/***********************************Proximity Russel**************************/
|
||||
else if "`prox'"=="russel" {
|
||||
qui count if ``i''==1&``j''==1
|
||||
local tmp11=r(N)
|
||||
|
||||
matrix `proximity'[`i',`j']=sqrt(1-`tmp11'/`N')
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
|
||||
/***********************************Proximity A**************************/
|
||||
else if "`prox'"=="dice" {
|
||||
qui count if ``i''==1&``j''==1
|
||||
local tmp11=r(N)
|
||||
qui count if ``i''==0&``j''==0
|
||||
local tmp00=r(N)
|
||||
|
||||
matrix `proximity'[`i',`j']=sqrt(1-2*`tmp11'/(`N'+`tmp11'-`tmp00'))
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
|
||||
/**********************************Proximity COR*************************/
|
||||
else if "`prox'"=="pearson" { /*corr*/
|
||||
qui corr ``i'' ``j''
|
||||
matrix `proximity'[`i',`j']=sqrt(2*(1-r(rho)))
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
|
||||
/***********************************Proximity CCOV**********************/
|
||||
else if "`prox'"=="ccov" {
|
||||
local dij=0
|
||||
local Ntemp=`N'
|
||||
forvalues k=1/`=`maxscore'-1' {
|
||||
if `nk`k''!=0 {
|
||||
if `nk`k''>1 {
|
||||
qui corr ``i'' ``j'' if `score'==`k',cov
|
||||
local covi`i'j`j'k`k'=r(cov_12)
|
||||
}
|
||||
else if `nk`k''==1 {
|
||||
local Ntemp=`Ntemp'-1
|
||||
local covi`i'j`j'k`k'=0
|
||||
}
|
||||
else {
|
||||
local covi`i'j`j'k`k'=0
|
||||
}
|
||||
local dij=`dij'+`covi`i'j`j'k`k''*`nk`k''
|
||||
}
|
||||
}
|
||||
|
||||
matrix `proximity'[`i',`j']=-`dij'/`Ntemp'
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
if `proxmin'<`dij'/`Ntemp' {
|
||||
local proxmin=`dij'/`Ntemp'
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************Proximity CCOR**********************/
|
||||
|
||||
else if "`prox'"=="ccor" {
|
||||
local dij=0
|
||||
local nnull=0
|
||||
local Ntemp=`N'
|
||||
forvalues k=1/`=`maxscore'-1' {
|
||||
if `nk`k''!=0 {
|
||||
if `nk`k''>1 {
|
||||
qui corr ``i'' ``j'' if `score'==`k'
|
||||
local cori`i'j`j'k`k'=r(rho)
|
||||
}
|
||||
else if `nk`k''==1 {
|
||||
local Ntemp=`Ntemp'-1
|
||||
local cori`i'j`j'k`k'=0
|
||||
}
|
||||
else {
|
||||
local cori`i'j`j'k`k'=0
|
||||
}
|
||||
if `cori`i'j`j'k`k''!=. {
|
||||
local dij=`dij'+`cori`i'j`j'k`k''*`nk`k''
|
||||
}
|
||||
else if `cori`i'j`j'k`k''==. {
|
||||
local nnull=`nnull'+`nk`k''
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
matrix `proximity'[`i',`j']=sqrt(2*(1-`dij'/(`Ntemp'-`nnull')))
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
|
||||
|
||||
/***********************************Proximity MH************************/
|
||||
|
||||
else if "`prox'"=="mh" {
|
||||
local numij=0
|
||||
local denom=0
|
||||
forvalues k=1/`=`maxscore'-1' {
|
||||
if `nk`k''!=0 {
|
||||
qui count if ``i''==1&``j''==1&`score'==`k'
|
||||
local A=r(N)
|
||||
qui count if ``i''==0&``j''==1&`score'==`k'
|
||||
local B=r(N)
|
||||
qui count if ``i''==1&``j''==0&`score'==`k'
|
||||
local C=r(N)
|
||||
qui count if ``i''==0&``j''==0&`score'==`k'
|
||||
local D=r(N)
|
||||
local numij=`numij'+`A'*`D'/`nk`k''
|
||||
local denomij=`denomij'+`B'*`C'/`nk`k''
|
||||
}
|
||||
}
|
||||
|
||||
matrix `proximity'[`i',`j']=-log(`numij'/`denomij')
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
if `proxmin'<log(`numij'/`denomij') {
|
||||
local proxmin=-`proximity'[`i',`j']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if "`prox'"=="ccov"|"`prox'"=="mh" {
|
||||
forvalues i=1/`nbitems' {
|
||||
forvalues j=`=`i'+1'/`nbitems' {
|
||||
matrix `proximity'[`i',`j']=`proximity'[`i',`j']+`proxmin'
|
||||
if `proximity'[`i',`j']<0 {
|
||||
matrix `proximity'[`i',`j']=0
|
||||
}
|
||||
matrix `proximity'[`j',`i']=`proximity'[`i',`j']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**********************END OD THE COMPUTING OF THE PROXIMITIES**************************************/
|
||||
else {
|
||||
matrix `proximity'=`matrix'
|
||||
}
|
||||
|
||||
matrix rowname `proximity'=`varlist'
|
||||
matrix colname `proximity'=`varlist'
|
||||
|
||||
if "`measures'"!="" {
|
||||
di in green "{hline 50}"
|
||||
di in green "Measures of proximity between the items"
|
||||
di in green "{hline 50}"
|
||||
matrix list `proximity', noheader
|
||||
di
|
||||
}
|
||||
|
||||
/**********************CLUSTERING PROCEDURE **********************************************/
|
||||
|
||||
|
||||
qui clustermat `method' `proximity',clear labelvar(name)
|
||||
local hor "hor"
|
||||
if "`method'"!="centroid"&"`method'"!="median"&"`dendrogram'"=="" {
|
||||
if "`html'" != "" {
|
||||
qui local saving "saving(`c(tmpdir)'/`html'_dendro,replace) nodraw"
|
||||
qui cluster dendro ,labels(name) hor ylabel(,angle(0)) title("Hierarchical Cluster Analysis on variables") subtitle("`desmethod'") xtitle("`desprox' proximities") `saving'
|
||||
qui graph use `c(tmpdir)'/`html'_dendro.gph
|
||||
qui graph export `c(tmpdir)'/`html'_dendro.eps, replace
|
||||
di "<br />"
|
||||
di "<img src=" _char(34) "/data/`html'_dendro.png" _char(34)
|
||||
di " class=" _char(34) "resgraph" _char(34) " alt=" _char(34) "dendro" _char(34) " title= " _char(34) "Hierarchical Cluster Analysis on variables - click to enlarge" _char(34) " width=" _char(34) "350" _char(34) " height=" _char(34) "240" _char(34) " >"
|
||||
}
|
||||
else {
|
||||
qui cluster dendro ,labels(name) hor ylabel(,angle(0)) title("Hierarchical Cluster Analysis on variables") subtitle("`desmethod'") xtitle("`desprox' proximities")
|
||||
}
|
||||
}
|
||||
|
||||
if "`partition'"!="" {
|
||||
foreach i of numlist `partition' {
|
||||
qui cluster gen cluster`i'=group(`i')
|
||||
}
|
||||
tempname clusters
|
||||
mkmat cluster* ,mat(`clusters')
|
||||
matrix rownames `clusters'=`varlist'
|
||||
local compteur=0
|
||||
foreach i of numlist `partition' {
|
||||
local ++compteur
|
||||
di
|
||||
di in green "{hline 30}"
|
||||
di in green "Partition in `i' cluster(s)"
|
||||
di in green "{hline 30}"
|
||||
di
|
||||
forvalues j=1/`i' {
|
||||
local cluster`i'_`j'
|
||||
local nbi`i'_`j'=0
|
||||
forvalues k=1/`nbitems' {
|
||||
if `clusters'[`k',`compteur']==`j' {
|
||||
local cluster`i'_`j' `cluster`i'_`j'' ``k''
|
||||
local ++nbi`i'_`j'
|
||||
}
|
||||
}
|
||||
di in green "Cluster `j': " in ye "`cluster`i'_`j''"
|
||||
}
|
||||
}
|
||||
return matrix clusters=`clusters'
|
||||
}
|
||||
|
||||
/**********************DETECT OPTION **************************************************/
|
||||
|
||||
use `hcaccproxfile',clear
|
||||
if "`detect'"!="" {
|
||||
foreach i of numlist `partition' {
|
||||
local liste
|
||||
local part
|
||||
forvalues j=1/`i' {
|
||||
local liste "`liste' `cluster`i'_`j''"
|
||||
local part "`part' `nbi`i'_`j''"
|
||||
}
|
||||
qui detect `liste',part(`part')
|
||||
local detect`i'=r(DETECT)
|
||||
local Iss`i'=r(Iss)
|
||||
local R`i'=r(R)
|
||||
}
|
||||
tempname indexes
|
||||
matrix define `indexes'=J(`compteur',4,0)
|
||||
matrix colnames `indexes'=Clusters DETECT Iss R
|
||||
di ""
|
||||
di in green "{hline 50}"
|
||||
di in green "Indexes to compare the partitions of the items"
|
||||
di in green "{hline 50}"
|
||||
di ""
|
||||
di in green _col(29) "DETECT" _col(43) "Iss" _col(56) "R"
|
||||
local compteur=0
|
||||
foreach k of numlist `partition' {
|
||||
local ++compteur
|
||||
matrix `indexes'[`compteur',1]=`k'
|
||||
matrix `indexes'[`compteur',2]=`detect`k''
|
||||
matrix `indexes'[`compteur',3]=`Iss`k''
|
||||
matrix `indexes'[`compteur',4]=`R`k''
|
||||
di _col(5) in green "`k' cluster(s):" _col(27) in yellow %8.5f `detect`k'' _col(38) %8.5f `Iss`k'' _col(49) %8.5f `R`k''
|
||||
}
|
||||
return matrix indexes=`indexes'
|
||||
}
|
||||
return local nbvar=`nbitems'
|
||||
return matrix measures=`proximity'
|
||||
restore, not
|
||||
*use `hcaccproxfile',clear
|
||||
|
||||
end
|
Reference in New Issue
Block a user