Setup initial file structure
This commit is contained in:
Modules
ado
personal
_
a
b
bidonc
calcscore.adocalcul.adocfa.adocheckfor2.adocheckfor2.hlpcheckvars.adocheckvars.hlpclv.adoclv.sthlpclv212.adoclv214.adoclv215.adoclv216.adoclv27.adoclv29.adocompart.adocompart2.adoconc.adoconvdiv.ado
d
dege.adodelta.adodescitems.adodescscale.adodescscalev1.1.adodescscalev1.adodetect.adodetect.hlpdetect2.adodropmissing.ado
e
files
Pop8204Dep.dtacantons.dtacommpct.dtacommunes.dtacommze.dtadccentre8002.dtadcfrance8002.dtanais8003.dtarpf829099.dtarph829099.dtarphf829099.dta
g
gammasym.adogammasym.hlpgausshermite.adogausshermite.hlpgausshermite1.adogausshermite2.adogausshermite3.adogeekel2d.adogeekel2d.hlpgeekel2d4.adogengroup.adogengroup.hlpgengutt.adogenscore.adogenscore.hlpguttmax.adoguttmax1.ado
grec
h
i
imputeitems - Copie.adoimputeitems v2.4.adoimputeitems.adoimputeitems.hlpimputeitems.txtimputeitems2.adoimputeitems_1.adoimputemok.adoimputemok.hlpimputerasch.adoimputerasch.hlpirtpoly.adoisvar.ado
k
l
loevH7.adoloevH72.adoloevH73.adoloevH73.hlploevHv1.hlploevh - Copie au 17 juin 2017.adoloevh v8.2.adoloevh.adoloevh.hlploevh8-1-3.adoloevh8.adoloevh81.adoloevh812.ziploevh813.adoloevh82.adolstrfun.ado
m
Multirsoort_indicefit.adomatrixlisthtml.adomdreplace.adomi_twoway.adomi_twoway.hlpmmsrm.adommsrm.hlpmmsrm2.adomsp.adomsp.hlpmsp66.adomsp66.hlpmsp82.ado
n
p
pcm - Copie.adopcm 3.4.adopcm 4.0.adopcm 4.1.adopcm 4.2 sauv le 8nov2019.adopcm 4.2.adopcm 5.1.adopcm 5.2.adopcm 5.3.adopcm 5.4.adopcm.adopcm.sthlppcm.zippcm21.adopcm22.adopcm23.adopcm3.2.adopcm3.3.adopcm3.adopcm44.adopcm5.adopcmodel.hlppcmodel.sthlppcmodel22.adopcmodel_v.adopcmodelplus.adopcmold.adopcmtest.adopcmtest.hlppcmtest.sthlppredraschwlm.ado
qualmosta
r
old
raschfit2.adoraschfit31.adoraschpower - Copie version SIM.adoraschpower1.5.adoraschpower1.adoraschpowerpcm.adoraschpowers.hlpraschtest2.adoraschtest82.adoraschtest83.adoraschtestv7732.adoraschtestv7761.adoraschtestv7762.adoraschtestv78 avant COVARIABLES.adoraschtestv782.adoraschtestv785.adoraschtestv7jf.adorsoort.dorsoort1 (2).adorsoort1.ado
raschfit.adoraschfit.hlpraschlong.adoraschlongitudinal2.adoraschpce.adoraschpower.adoraschpower.hlpraschpower33.adoraschpower4.adoraschpower5.adoraschpower51.adoraschpower511.adoraschpower52.adoraschpower53.adoraschpower54.adoraschpower55.adoraschpower56.adoraschpower58.adoraschpower59.adoraschres.adoraschres.hlpraschtest v8.10.1.adoraschtest.adoraschtest.hlpraschtestv7.adoraschtestv7.hlpraschtestv787.adoraschtestv7v8.10.1.adoraschtestv7v8.10.adoraschtestv7v88.adoraschtestv8.10.adoraschtestv86.adorel.adorepet.adorosali.adorosali.sthlprosali22.adorosali22.sthlprosali23.adorsbynpirt.adorsoort.adorsoort.hlprsoort11.ziprsoort12.adorsoort13.adorsoortBP.ados
old
sascfa.adosenspescore.adosf36fr v1.6.adosf36fr v1.7.adosf36fr.adosf36fr.hlpsf36fr.zipsf36fr1.4.adosf36fr1.5.adosf36frv13.adosimirt - Copie.adosimirt v4.1.adosimirt v4.2.adosimirt v4.3.adosimirt v4.4.adosimirt.adosimirt.hlpsimirt.zipt
tcm.adotestclv.adotodate.adotorumm.adotosas.adotraces v4.adotraces v5 avec items numeric ne marche pas - Copie.adotraces.adotraces.hlptraces3.adotraces32.adotraces33.adotri.adotrouve.ado
v
valid.adovalid.dlgvalid.hlpvalidscale.adovalidscale.ado (old)validscale.dlgvalidscale.hlpvalidscale.sthlpvalidscaleXX.ado
w
zip
backrasch2.zipclv214.zipdetect31.zipgammasym.zipgammasym22.zipgausshermite1.zipgeekel2d43.zipgengroup12.ziphcavar32.zipimputeitems.zipimputeitems24.zipimputemok21.zipimputerasch2.ziploevH.ziploevh8.zipmmsrm4.zipmohand.zipmsp.zipmsp81.zipnpirt.zipraschfit4.zipraschpower1.4.zipraschpower1.5.zipraschpower1.zipraschpower2.zipraschpower32.zipraschtest.zipraschtest8.zipraschtest86.zipraschtest87.zipraschtestv7.zipsf36fr13.zipsimirt.zipsimirt34.zipsimirt35.ziptraces33.zip
plus
_
_eststo.ado_eststo.hlp_get_mlogit_bv.ado_get_mlogit_bvecv.ado_peabbv.ado_pebase.ado_pebase.hlp_pecats.ado_pecats.hlp_peciboot.ado_peciboot.hlp_pecidelta.ado_pecidelta.hlp_peciml.ado_pecmdcheck.ado_pecollect.ado_pecollect.hlp_pedum.ado_pedum.hlp_peife.ado_peife.hlp_pemarg.ado_pemarg.hlp_penocon.ado_penocon.hlp_pepred.ado_pepred.hlp_perhs.ado_perhs.hlp_pesum.ado_pesum.hlp_petrap.ado_petrap.hlp_peunvec.ado_peunvec.hlp_pexstring.ado
a
b
bagroup.adobagroup.hlpbamat.adobamat.hlpbaplot.adobaplot.hlpbatplot.adobatplot.hlpbinolist.adobinolist.hlpblandaltman.adobollenstine.adobollenstine.sthlpbothlist.adobothlist.hlpbrant.adobrant.hlp
backup.trkc
caplog.adocaplog.hlpcase2alt.adocase2alt.hlpcfa1.adocfa1.hlpcfa1_lf.adocheckfor2.adocheckfor2.hlpchoplist.adochoplist.hlpcmdchk.adocollist.adocollist.hlpconcord.adoconcord.dlgconcord.hlpconfa.adoconfa.mataconfa.sthlpconfa_estat.adoconfa_estat.sthlpconfa_lf.adoconfa_lfm.adoconfa_p.adoconfirmdir.adoconfirmdir.hlpconvlist.adoconvlist.hlpcountfit.adocountfit.hlpcseplist.adocseplist.hlpcvarlist.adocvarlist.hlp
d
dellist.adodellist.hlpdelta.adodelta.hlpdifflist.adodifflist.hlpdiscrim2.adodiscrim2.hlpdropvars.adodropvars.hlp
e
elapse.adoelapse.hlpeq_g.hlpeqlist.adoeqlist.hlpespoisson.adoespoisson.hlpespoisson_ll.adoespoisson_p.adoestadd.adoestadd.hlpestout.adoestout.hlpestpost.adoestpost.hlpeststo.adoeststo.hlpesttab.adoesttab.hlpexspoisson.adoexspoisson_ll.adoexspoisson_p.ado
f
g
galbr.adogalbr.dlggalbr.hlpghquad.adoghquadm.adoghquadm.hlpgllam_ll.adogllamm.adogllamm.hlpgllapred.adogllapred.hlpgllarob.adogllas_yu.adogllasim.adogllasim.hlp
h
i
i2ci.adoicc23.adoicc23.hlpiccconf.adoiccconf.hlpice.adoice.hlpiclassr.adoiclassr.hlpiclassr2.adoiclassr2.hlpimputeitems.adoimputeitems.hlpinslist.adoinslist.hlpisvar.adoisvar.hlp
j
l
l1way.adol1way.hlplabbe.adolabbe.dlglabbe.hlplclist.adolclist.hlplconfa.mlibleastlikely.adoleastlikely.hlplistblck.adolistblck.hlplistcoef.adolistcoef.hlplistutil.hlplog2html.adolog2html.hlplog2html7.adolog2html7.hlplogout.adologout.hlp
m
maplist.adomaplist.hlpmeta.dlgmeta_dialog.hlpmetabias.adometabias.dlgmetabias.hlpmetacum.dlgmetafunnel.adometafunnel.dlgmetafunnel.hlpmetainf.adometainf.dlgmetainf.hlpmetan.adometan.dlgmetan.hlpmetan7.adometan7.dlgmetan7.hlpmetan_examples.adometaninf.adometaninf.dlgmetaninf.hlpmetannt.adometannt.dlgmetannt.hlpmetap.dlgmetareg.adometareg.dlgmetareg.hlpmetareg_ll.adometareg_p.adometareg_pm.adometatrim.dlgmhplot.adomicombine.adomicombine.hlpmijoin.adomijoin.hlpmisplit.adomisplit.hlpmisschk.adomisschk.sthlpmlogplot.adomlogplot.hlpmlogtest.adomlogtest.sthlpmlogview.adomlogview.hlpmnthlist.adomnthlist.hlpmvtab1.adomvtab1.hlp
n
nct.adonct.hlpnct2.adonct2.hlpnct2inv.adonct2inv.hlpnctinv.adonctinv.hlpnctn.adonctn.hlpnctncp.adonctncp.hlpnctprob.adonctprob.hlpnicenum.adonmlab.adonmlab.hlp
o
p
polych_ll.adopolychoric.adopolychoric.hlppolychoric.zippolychoricpca.adopolychoricpca.hlppolychoricpca.zippolyser_ll.adoposlist.adoposlist.hlppostlist.adopostlist.hlppraccum.adopraccum.hlpprchange.adoprchange.hlpprcounts.adoprcounts.hlpprdc.adoprdc.hlpprelist.adoprelist.hlpprgen.adoprgen.hlpprodlist.adoprodlist.hlpprtab.adoprtab.hlpprvalue.adoprvalue.hlpprwhich.ado
r
remcor.adoreop_ll.adoreopc_ll.adoreoprob.adoreoprob.hlpreplist.adoreplist.hlprevlist.adorevlist.hlprfpr_ll1.adorfprobit.adorfprobit.hlprotlist.adorotlist.hlp
s
sasexe.adosaswrapper.adosaswrapper.hlpsavasas.adosavasas.hlpsavastata.sassdpair.adosdpair.hlpseeout.adoseeout.hlpsellist.adosellist.hlpseqlist.adoseqlist.hlpshellout.adoshellout.hlpshortdir.adoshortdir.hlpsjlatex.adosjlatex.hlpsjlog.adosjlog.hlpsjlog_7.adosortlist.adosortlist.hlpspex.adospex.hlpspost.hlpspost_footer.ihlpspostupdate.adosublist.adosublist.hlpsumlist.adosumlist.hlp
stata.trkt
takelist.adotakelist.hlptmpdir.adotmpdir.hlptorumm.adotorumm.hlptraces.adotraces.hlptraj.adotraj.hlptraj.plugintrajplot.adotrajplot.hlptrnclist.adotrnclist.hlp
u
v
w
x
rosali_custom
simirt.R
501
Modules/ado/personal/h/hcaccprox.ado
Normal file
501
Modules/ado/personal/h/hcaccprox.ado
Normal file
@ -0,0 +1,501 @@
|
||||
************************************************************************************************************
|
||||
* 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
|
||||
|
Reference in New Issue
Block a user