Setup initial file structure
This commit is contained in:
315
Modules/ado/personal/r/old/raschfit2.ado
Normal file
315
Modules/ado/personal/r/old/raschfit2.ado
Normal file
@ -0,0 +1,315 @@
|
||||
************************************************************************************************************
|
||||
* Stata program : Raschfit
|
||||
* The Raschfit and the Raschfit-fast procedures to construct sub-scales of items
|
||||
* Release 2 : June 8, 2004
|
||||
*
|
||||
* Historic
|
||||
* Version 1 (2004-05-06) [Jean-Benoit Hardouin]
|
||||
*
|
||||
* Jean-benoit Hardouin, Regional Health Observatory of Orl<72>ans - France
|
||||
* jean-benoit.hardouin@neuf.fr
|
||||
*
|
||||
* Use the Stata programs mmsrm, raschtest and gammasym who can be download on http://anaqol.free.fr
|
||||
* News about this program :http://anaqol.free.fr
|
||||
*
|
||||
* FreeIRT Project website : 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 raschfit,rclass
|
||||
version 7.0
|
||||
syntax varlist(min=2 numeric) [,KERnel(integer 0) NBSCales(integer 1) ITEMSorder(string) nofast]
|
||||
if "`itemsorder'"=="" {
|
||||
local itemsorder mspinv
|
||||
}
|
||||
local nbitemstot : word count `varlist'
|
||||
tokenize `varlist'
|
||||
|
||||
tempfile raschfitfile
|
||||
qui save `raschfitfile',replace
|
||||
preserve
|
||||
|
||||
tempname affect
|
||||
matrix define `affect'=J(1,`nbitemstot',0)
|
||||
matrix colnames `affect'=`varlist'
|
||||
|
||||
tempname rep item matbetadim1 matbetadim2
|
||||
if `kernel'!=0 {
|
||||
local listkernel
|
||||
forvalues i=1/`kernel' {
|
||||
local listkernel `listkernel' `rep'`i'
|
||||
matrix `affect'[1,`i']=1
|
||||
}
|
||||
}
|
||||
|
||||
local dim=0
|
||||
local nbitemsnosel=`nbitemstot'
|
||||
local nbitemstotdim1=`nbitemstot'
|
||||
local nbitemsnoselukernel=`nbitemstot'-`kernel'
|
||||
|
||||
|
||||
tempvar id betadim1 betadim2
|
||||
forvalues i=1/`nbitemstot' {
|
||||
qui drop if ``i''==.
|
||||
rename ``i'' `rep'`i'
|
||||
}
|
||||
qui gen `id'=_n
|
||||
tempfile filescale
|
||||
qui save `filescale',replace
|
||||
|
||||
|
||||
while `nbitemsnosel'>2&`dim'<`nbscales' {
|
||||
use `filescale',replace
|
||||
local iteration=0
|
||||
local dim=`dim'+1
|
||||
if `dim'>1 {
|
||||
local kernel=0
|
||||
local listkernel
|
||||
}
|
||||
|
||||
di in green "SCALE: " in yellow `dim'
|
||||
di in green "{hline 9}"
|
||||
di
|
||||
tempname result`dim'
|
||||
local listitemsnosel
|
||||
local varlist`dim'
|
||||
tokenize `varlist'
|
||||
forvalues i=1/`nbitemstot' {
|
||||
if `affect'[1,`i']==0 {
|
||||
local varlist`dim' `varlist`dim'' ``i''
|
||||
local listitemsnosel `listitemsnosel' `rep'`i'
|
||||
}
|
||||
}
|
||||
local nbitemsnosel:word count `listitemsnosel'
|
||||
if `dim'>1 {
|
||||
local nbitemstotdim`dim':word count `listitemsnosel'
|
||||
}
|
||||
|
||||
if `kernel'>=2 {
|
||||
local fixed=`kernel'
|
||||
}
|
||||
else {
|
||||
local fixed=2
|
||||
}
|
||||
matrix define `result`dim''=J(`=`nbitemstotdim`dim''-`fixed'',`=`nbitemstotdim`dim''+7',0)
|
||||
|
||||
tempname order`dim' affect`dim'
|
||||
matrix `order`dim''=J(1,`nbitemstotdim`dim'',0)
|
||||
matrix `affect`dim''=J(1,`nbitemstotdim`dim'',0)
|
||||
|
||||
if "`itemsorder'"=="msp"|"`itemsorder'"=="mspinv" {
|
||||
di in green _col(0) "The program is ordering the items"
|
||||
qui msp `listkernel' `listitemsnosel',c(-99) notest kernel(`kernel')
|
||||
local scale1 "`r(scale1)'"
|
||||
local scalenum1 "`r(scalenum1)'"
|
||||
tokenize `scalenum1'
|
||||
local listitemsselnum
|
||||
forvalues j=`=`nbitemstotdim`dim''+1-`fixed''/`nbitemstotdim`dim'' {
|
||||
matrix `order`dim''[1,``j'']=1
|
||||
local k:word `j' of `scalenum1'
|
||||
matrix `affect`dim''[1,`k']=1
|
||||
local listitemsselnum `listitemsselnum' `k'
|
||||
}
|
||||
forvalues j=1/`nbitemsnosel' {
|
||||
matrix `order`dim''[1,`j']=`=`nbitemsnosel'+1-`j''
|
||||
}
|
||||
tokenize `scale1'
|
||||
local listitemssel ``=`nbitemstotdim`dim''-1'' ``nbitemstotdim`dim'''
|
||||
|
||||
local listitemsnosel
|
||||
local listitemsnoselnum
|
||||
|
||||
if "`itemsorder'"=="mspinv" {
|
||||
forvalues j=1/`=`nbitemstotdim`dim''-`fixed'' {
|
||||
local listitemsnosel `listitemsnosel' ``j''
|
||||
local k:word `j' of `scalenum1'
|
||||
local listitemsnoselnum `listitemsnoselnum' `k'
|
||||
}
|
||||
}
|
||||
else if "`itemsorder'"=="msp"{
|
||||
forvalues j=`=`nbitemstotdim`dim''-`fixed''(-1)1 {
|
||||
local listitemsnosel `listitemsnosel' ``j''
|
||||
local k:word `j' of `scalenum1'
|
||||
local listitemsnoselnum `listitemsnoselnum' `k'
|
||||
}
|
||||
}
|
||||
}
|
||||
else if "`itemsorder'"=="order" {
|
||||
tokenize `listkernel' `varlist`dim''
|
||||
local listitemssel
|
||||
local listitemsselnum
|
||||
local listitemsnosel
|
||||
local listitemsnoselnum
|
||||
forvalues j=1/`fixed'{
|
||||
local listitemssel `listitemssel' `rep'`j'
|
||||
local listitemsselnum `listitemsselnum' `j'
|
||||
matrix `affect`dim''[1,`j']=1
|
||||
}
|
||||
forvalues j=`=`fixed'+1'/`nbitemstotdim`dim'' {
|
||||
local listitemsnosel `listitemsnosel' `rep'`j'
|
||||
local listitemsnoselnum `listitemsnoselnum' `j'
|
||||
}
|
||||
}
|
||||
|
||||
if `dim'>1 {
|
||||
tokenize `varlist`dim''
|
||||
}
|
||||
else {
|
||||
tokenize `varlist'
|
||||
}
|
||||
|
||||
local nbitemsnosel:word count `listitemsnosel'
|
||||
local list
|
||||
*tokenize `varlist'
|
||||
forvalues i=1/`=`nbitemsnosel'+`fixed'' {
|
||||
local tmp:word `i' of "`listitemsnosel' `listitemssel'"
|
||||
local list `list' ``i''
|
||||
}
|
||||
|
||||
matrix colnames `result`dim''=`list' iteration nbitems ll1 AIC1 ll2 AIC2 choose
|
||||
|
||||
di _col(0) in green "The kernel of the scale is " in yellow _continue
|
||||
forvalues i=1/`fixed' {
|
||||
local inum:word `i' of `listitemsselnum'
|
||||
di in yellow "``inum'' " _continue
|
||||
}
|
||||
di
|
||||
tokenize `listitemsnosel'
|
||||
forvalues i=1/`=`nbitemsnosel-2'' {
|
||||
local iteration=`iteration'+1
|
||||
di
|
||||
di in green _col(10) "iteration:" in yellow" `iteration'"
|
||||
di in green _col(10) "{hline 13}"
|
||||
di
|
||||
qui use `filescale' , clear
|
||||
local i2:word `i' of `listitemsnosel'
|
||||
local i2num:word `i' of `listitemsnoselnum'
|
||||
qui keep `id' `listitemssel' `i2'
|
||||
tempname score1 score2
|
||||
qui gen `score2'=0
|
||||
tokenize `listitemssel'
|
||||
local nbitemssel: word count `listitemssel'
|
||||
forvalues j=1/`i' {
|
||||
local j2num:word `j' of `listitemsnoselnum'
|
||||
if `affect`dim''[1,`j2num']==1 {
|
||||
matrix `result`dim''[`iteration',`j']=1
|
||||
}
|
||||
}
|
||||
forvalues j=1/`nbitemssel' {
|
||||
local j2:word `j' of `listitemssel'
|
||||
local j2num:word `j' of `listitemsselnum'
|
||||
qui replace `score2'=`score2'+`j2'
|
||||
}
|
||||
tokenize `listitemsnosel'
|
||||
qui gen `score1'=`score2'+`i2'
|
||||
forvalues j=`=`nbitemsnosel'+1'/`=`nbitemsnosel'+`nbitemssel'' {
|
||||
matrix `result`dim''[`iteration',`j']=1
|
||||
}
|
||||
matrix `result`dim''[`iteration',`=`nbitemstotdim`dim''+1']=`iteration'
|
||||
matrix `result`dim''[`iteration',`=`nbitemstotdim`dim''+2']=`nbitemssel'
|
||||
matrix `result`dim''[`iteration',`i']=2
|
||||
|
||||
if "`fast'"=="" {
|
||||
qui count if `score1'!=`=`nbitemssel'+1'&`score1'!=0&`score2'!=`nbitemssel'
|
||||
local N=r(N)
|
||||
di in green _col(10)"The program is estimating the parameters of the models (N=" in yellow "`N'" in green ")"
|
||||
qui raschtest `listitemssel' `i2' if `score1'!=3&`score1'!=0&`score2'!=2, mml notest
|
||||
|
||||
matrix `matbetadim1'=e(beta),0
|
||||
qui raschtest `listitemssel' if `score1'!=3&`score1'!=0&`score2'!=2, mml notest
|
||||
matrix `matbetadim2'=e(beta),0
|
||||
qui reshape long `rep' , i(`id') j(`item')
|
||||
qui gen `betadim1'=0
|
||||
qui gen `betadim2'=0
|
||||
|
||||
forvalues j=1/`nbitemssel' {
|
||||
local j2num:word `j' of `listitemsselnum'
|
||||
qui replace `betadim1'=-`matbetadim1'[1,`j'] if `item'==`j2num'
|
||||
qui replace `betadim2'=-`matbetadim2'[1,`j'] if `item'==`j2num'
|
||||
}
|
||||
qui replace `betadim1'= -`matbetadim1'[1,`=`nbitemssel'+1'] if `item'==`i2num'
|
||||
qui count if `rep'==1&`item'==`i2num'&`score1'!=`=`nbitemssel'+1'&`score1'!=0&`score2'!=`nbitemssel'
|
||||
local nb1=r(N)
|
||||
qui count if `item'==`i2num'&`score1'!=`=`nbitemssel'+1'&`score1'!=0&`score2'!=`nbitemssel'
|
||||
local nb2=r(N)
|
||||
|
||||
qui replace `betadim2'= log(`nb1'/(`nb2'-`nb1')) if `item'==`i2num'
|
||||
qui xi:logit `rep' i.`score1' if `score1'!=`=`nbitemssel'+1'&`score1'!=0&`score2'!=`nbitemssel', nocons offset(`betadim1') iter(100)
|
||||
local N1=e(N)
|
||||
matrix `result`dim''[`iteration',`=`nbitemstotdim`dim''+3']=e(ll)
|
||||
matrix `result`dim''[`iteration',`=`nbitemstotdim`dim''+4']=2*(-e(ll)+2*(`nbitemssel'+1)-1)
|
||||
|
||||
tempvar newscore2
|
||||
qui gen `newscore2'=`score2'
|
||||
qui replace `newscore2'=99 if `item'==`i2num'
|
||||
qui xi:logit `rep' i.`newscore2' if `score1'!=`=`nbitemssel'+1'&`score1'!=0&`score2'!=`nbitemssel', offset(`betadim2') iter(100)
|
||||
local N2=e(N)
|
||||
local ll=e(ll)
|
||||
matrix `result`dim''[`iteration',`=`nbitemstotdim`dim''+5']=e(ll)
|
||||
matrix `result`dim''[`iteration',`=`nbitemstotdim`dim''+6']=2*(-e(ll)+2*(`nbitemssel'+1)-2)
|
||||
}
|
||||
else {
|
||||
qui count
|
||||
local N=r(N)
|
||||
di in green _col(10)"The program is estimating the parameters of the models (N=" in yellow "`N'" in green ")"
|
||||
qui raschtest `listitemssel' `i2' , mml notest
|
||||
matrix `result`dim''[`iteration',`=`nbitemstotdim`dim''+3']=e(ll)
|
||||
matrix `result`dim''[`iteration',`=`nbitemstotdim`dim''+4']=2*(-e(ll)+`nbitemssel'+2)
|
||||
|
||||
local nb1:word count `listitemssel'
|
||||
qui mmsrm `listitemssel' `i2' , part(`nb1' 1)
|
||||
matrix `result`dim''[`iteration',`=`nbitemstotdim`dim''+5']=e(ll)
|
||||
matrix `result`dim''[`iteration',`=`nbitemstotdim`dim''+6']=2*(-e(ll)+`nbitemssel'+4)
|
||||
}
|
||||
di in green _col(10)"Unidimensional model: " _col(32) "ll: " in yellow _col(37) %12.4f `result`dim''[`iteration',`=`nbitemstotdim`dim''+3'] _col(52) in green "AIC: " in yellow _col(57) %12.4f `result`dim''[`iteration',`=`nbitemstotdim`dim''+4']
|
||||
di in green _col(10)"Bidimensional model: " _col(32) "ll: " in yellow _col(37) %12.4f `result`dim''[`iteration',`=`nbitemstotdim`dim''+5'] _col(52) in green "AIC: " in yellow _col(57) %12.4f `result`dim''[`iteration',`=`nbitemstotdim`dim''+6']
|
||||
tokenize `listkernel' `varlist`dim''
|
||||
if `result`dim''[`iteration',`=`nbitemstot'+4']<=`result`dim''[`iteration',`=`nbitemstot'+6'] {
|
||||
matrix `result`dim''[`iteration',`i']=1
|
||||
matrix `result`dim''[`iteration',`=`nbitemstotdim`dim''+7']=1
|
||||
local nbitemssel=`nbitemssel'+1
|
||||
local nbitemsnosel=`nbitemsnosel'-1
|
||||
local listitemssel `listitemssel' `rep'`i2num'
|
||||
local listitemsselnum `listitemsselnum' `i2num'
|
||||
matrix `affect`dim''[1,`i2num']=1
|
||||
di _col(10) in green "The item " in yellow "``i2num''" in green " is selected in the scale " in yellow `dim'
|
||||
}
|
||||
else {
|
||||
matrix `result`dim''[`iteration',`=`nbitemstotdim`dim''+7']=2
|
||||
di _col(10) in green "The item "in yellow "``i2num''" in green " is not selected in the scale " in yellow `dim'
|
||||
|
||||
}
|
||||
}
|
||||
return matrix result`dim' `result`dim''
|
||||
local j=`kernel'+1
|
||||
forvalues i=`=`kernel'+1'/`nbitemstot' {
|
||||
if `affect'[1,`i']==0 {
|
||||
if `affect`dim''[1,`j']==1 {
|
||||
matrix `affect'[1,`i']=`dim'
|
||||
}
|
||||
local j=`j'+1
|
||||
}
|
||||
}
|
||||
}
|
||||
use `raschfitfile',clear
|
||||
|
||||
return matrix affect `affect'
|
||||
|
||||
end
|
336
Modules/ado/personal/r/old/raschfit31.ado
Normal file
336
Modules/ado/personal/r/old/raschfit31.ado
Normal file
@ -0,0 +1,336 @@
|
||||
*! Raschfit version 3.1 (29 January 2006)
|
||||
*! Jean-Benoit Hardouin
|
||||
************************************************************************************************************
|
||||
* Stata program : Raschfit
|
||||
* The Raschfit and the Raschfit-fast procedures to construct sub-scales of items
|
||||
* Release 3.1 : January 29, 2006 /*MEAN option in raschtestv7, correction of a bug when there is several scales*/
|
||||
*
|
||||
* Historic
|
||||
* Version 1 (2004-05-06) [Jean-Benoit Hardouin]
|
||||
* Version 2 (2004-06-08) [Jean-Benoit Hardouin]
|
||||
* Version 3 (2005-12-28) [Jean-Benoit Hardouin]
|
||||
*
|
||||
* Jean-benoit Hardouin, Regional Health Observatory of Orl<72>ans - France
|
||||
* jean-benoit.hardouin@neuf.fr
|
||||
*
|
||||
* Use the Stata programs mmsrm, raschtest and gammasym who can be download on http://anaqol.free.fr
|
||||
* News about this program :http://anaqol.free.fr
|
||||
*
|
||||
* FreeIRT Project website : http://freeirt.free.fr
|
||||
*
|
||||
* Copyright 2004-2006 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 raschfit,rclass
|
||||
version 7
|
||||
syntax varlist(min=2 numeric) [,KERnel(integer 0) NBSCales(integer 1) ITEMSorder(string) nofast ]
|
||||
if "`itemsorder'"=="" {
|
||||
local itemsorder mspinv
|
||||
}
|
||||
local nbitemstot : word count `varlist'
|
||||
tokenize `varlist'
|
||||
|
||||
tempfile raschfitfile
|
||||
qui save `raschfitfile',replace
|
||||
preserve
|
||||
|
||||
tempname affect
|
||||
matrix define `affect'=J(1,`nbitemstot',0)
|
||||
matrix colnames `affect'=`varlist'
|
||||
|
||||
tempname rep item matbetadim1 matbetadim2
|
||||
if `kernel'!=0 {
|
||||
local listkernel
|
||||
forvalues i=1/`kernel' {
|
||||
local listkernel `listkernel' `rep'`i'
|
||||
matrix `affect'[1,`i']=1
|
||||
}
|
||||
}
|
||||
|
||||
local dim=0
|
||||
local nbitemsnosel=`nbitemstot'
|
||||
local nbitemstotdim1=`nbitemstot'
|
||||
local nbitemsnoselukernel=`nbitemstot'-`kernel'
|
||||
|
||||
|
||||
tempvar id betadim1 betadim2
|
||||
forvalues i=1/`nbitemstot' {
|
||||
qui drop if ``i''==.
|
||||
rename ``i'' `rep'`i'
|
||||
}
|
||||
qui gen `id'=_n
|
||||
tempfile filescale
|
||||
qui save `filescale',replace
|
||||
|
||||
di in green "{hline 55}"
|
||||
qui count
|
||||
local N=r(N)
|
||||
if "`fast'"!="" {
|
||||
di in green "Method: " in ye "Raschfit"
|
||||
}
|
||||
else {
|
||||
di in green "Method: " in ye "Raschfit-Fast"
|
||||
}
|
||||
di in green "Number of individuals: " in ye `N' in green " (with none missing values)"
|
||||
di in green "Number of items: " in ye `nbitemstot'
|
||||
di in green "{hline 55}"
|
||||
di
|
||||
di in green "{hline 100}"
|
||||
if "`fast'"!="" {
|
||||
di in green "Model 1: " in ye "Rasch model"
|
||||
di in green "Model 2: " in ye "MMSRM"
|
||||
}
|
||||
else {
|
||||
di in green "Model 1: " in ye "Rasch model"
|
||||
di in green "Model 2: " in ye "Adapted Rasch model (the response of the new item is not influenced by the latent trait)"
|
||||
}
|
||||
di in green "Order of the items:" _c
|
||||
if "`itemsorder'"=="order" {
|
||||
di in ye " order of {it:varlist}"
|
||||
}
|
||||
else if "`itemsorder'"=="msp" {
|
||||
di in ye " Obtained with MSP (from the first selected item to the last one)"
|
||||
}
|
||||
else if "`itemsorder'"=="mspinv" {
|
||||
di in ye " Obtained with MSP (from the last selected item to the first one)"
|
||||
}
|
||||
if `kernel'!=0 {
|
||||
di in green "Kernel of the first scale: " _c
|
||||
forvalues i=1/`kernel' {
|
||||
di in ye " ``i''" _c
|
||||
}
|
||||
di
|
||||
}
|
||||
di in green "{hline 100}"
|
||||
di
|
||||
|
||||
while `nbitemsnosel'>2&`dim'<`nbscales' {
|
||||
use `filescale',replace
|
||||
local iteration=0
|
||||
local dim=`dim'+1
|
||||
if `dim'>1 {
|
||||
local kernel=0
|
||||
local listkernel
|
||||
}
|
||||
|
||||
di in green "SCALE: " in yellow `dim'
|
||||
di in green "{hline 9}"
|
||||
di
|
||||
tempname result`dim'
|
||||
local listitemsnosel
|
||||
local varlist`dim'
|
||||
tokenize `varlist'
|
||||
forvalues i=1/`nbitemstot' {
|
||||
if `affect'[1,`i']==0 {
|
||||
local varlist`dim' `varlist`dim'' ``i''
|
||||
local listitemsnosel `listitemsnosel' `rep'`i'
|
||||
}
|
||||
}
|
||||
local nbitemsnosel:word count `listitemsnosel'
|
||||
if `dim'>1 {
|
||||
local nbitemstotdim`dim':word count `listitemsnosel'
|
||||
}
|
||||
|
||||
if `kernel'>=2 {
|
||||
local fixed=`kernel'
|
||||
}
|
||||
else {
|
||||
local fixed=2
|
||||
}
|
||||
matrix define `result`dim''=J(`=`nbitemstotdim`dim''-`fixed'',`=`nbitemstotdim`dim''+7',0)
|
||||
|
||||
tempname order`dim' affect`dim'
|
||||
matrix `order`dim''=J(1,`nbitemstotdim`dim'',0)
|
||||
matrix `affect`dim''=J(1,`nbitemstotdim`dim'',0)
|
||||
|
||||
if "`itemsorder'"=="msp"|"`itemsorder'"=="mspinv" {
|
||||
di in green _col(0) "The program is ordering the items"
|
||||
di
|
||||
qui msp `listkernel' `listitemsnosel',c(-99) notest kernel(`kernel')
|
||||
local scale1 "`r(scale1)'"
|
||||
local scalenum1 "`r(scalenum1)'"
|
||||
tokenize `scalenum1'
|
||||
local listitemsselnum
|
||||
forvalues j=`=`nbitemstotdim`dim''+1-`fixed''/`nbitemstotdim`dim'' {
|
||||
matrix `order`dim''[1,`j']=1
|
||||
local k:word `j' of `scalenum1'
|
||||
matrix `affect`dim''[1,`k']=1
|
||||
local listitemsselnum `listitemsselnum' `k'
|
||||
}
|
||||
forvalues j=1/`nbitemsnosel' {
|
||||
matrix `order`dim''[1,`j']=`=`nbitemsnosel'+1-`j''
|
||||
}
|
||||
tokenize `scale1'
|
||||
local listitemssel ``=`nbitemstotdim`dim''-1'' ``nbitemstotdim`dim'''
|
||||
|
||||
local listitemsnosel
|
||||
local listitemsnoselnum
|
||||
|
||||
if "`itemsorder'"=="mspinv" {
|
||||
forvalues j=1/`=`nbitemstotdim`dim''-`fixed'' {
|
||||
local listitemsnosel `listitemsnosel' ``j''
|
||||
local k:word `j' of `scalenum1'
|
||||
local listitemsnoselnum `listitemsnoselnum' `k'
|
||||
}
|
||||
}
|
||||
else if "`itemsorder'"=="msp"{
|
||||
forvalues j=`=`nbitemstotdim`dim''-`fixed''(-1)1 {
|
||||
local listitemsnosel `listitemsnosel' ``j''
|
||||
local k:word `j' of `scalenum1'
|
||||
local listitemsnoselnum `listitemsnoselnum' `k'
|
||||
}
|
||||
}
|
||||
}
|
||||
else if "`itemsorder'"=="order" {
|
||||
tokenize `listkernel' `varlist`dim''
|
||||
local listitemssel
|
||||
local listitemsselnum
|
||||
local listitemsnosel
|
||||
local listitemsnoselnum
|
||||
forvalues j=1/`fixed'{
|
||||
local listitemssel `listitemssel' `rep'`j'
|
||||
local listitemsselnum `listitemsselnum' `j'
|
||||
matrix `affect`dim''[1,`j']=1
|
||||
}
|
||||
forvalues j=`=`fixed'+1'/`nbitemstotdim`dim'' {
|
||||
local listitemsnosel `listitemsnosel' `rep'`j'
|
||||
local listitemsnoselnum `listitemsnoselnum' `j'
|
||||
}
|
||||
}
|
||||
|
||||
if `dim'>1 {
|
||||
tokenize `varlist`dim''
|
||||
}
|
||||
else {
|
||||
tokenize `varlist'
|
||||
}
|
||||
|
||||
local nbitemsnosel:word count `listitemsnosel'
|
||||
local list
|
||||
tokenize `varlist`dim''
|
||||
forvalues i=1/`=`nbitemsnosel'+`fixed'' {
|
||||
local tmp:word `i' of `listitemsnoselnum' `listitemsselnum'
|
||||
local list `list' ``tmp''
|
||||
}
|
||||
matrix colnames `result`dim''=`list' Iteration Nbitems ll1 AIC1 ll2 AIC2 Selected
|
||||
|
||||
di _col(0) in green "The kernel of the scale is " in yellow _continue
|
||||
forvalues i=1/`fixed' {
|
||||
local inum:word `i' of `listitemsselnum'
|
||||
di in yellow "``inum'' " _continue
|
||||
}
|
||||
di
|
||||
di
|
||||
tokenize `listitemsnosel'
|
||||
di in green "{hline 90}"
|
||||
di in green _col(36) "Log-Likelihood" _col(58) "Akaike Criterion (AIC)"
|
||||
di in green _col(4) "Iteration" _col(20) "New Item" _col(34) "Model 1" _col(47) "Model 2" _col(60) "Model 1" _col(73) "Model 2" _col(81) "Selected"
|
||||
di in green "{hline 90}"
|
||||
forvalues i=1/`=`nbitemsnosel-2'' {
|
||||
local iteration=`iteration'+1
|
||||
qui use `filescale' , clear
|
||||
local i2:word `i' of `listitemsnosel'
|
||||
local i2num:word `i' of `listitemsnoselnum'
|
||||
qui keep `id' `listitemssel' `i2'
|
||||
tempname score1 score2
|
||||
qui gen `score2'=0
|
||||
tokenize `listitemssel'
|
||||
local nbitemssel: word count `listitemssel'
|
||||
forvalues j=1/`i' {
|
||||
local j2num:word `j' of `listitemsnoselnum'
|
||||
if `affect`dim''[1,`j2num']==1 {
|
||||
matrix `result`dim''[`iteration',`j']=1
|
||||
}
|
||||
}
|
||||
forvalues j=1/`nbitemssel' {
|
||||
local j2:word `j' of `listitemssel'
|
||||
local j2num:word `j' of `listitemsselnum'
|
||||
qui replace `score2'=`score2'+`j2'
|
||||
}
|
||||
tokenize `listitemsnosel'
|
||||
qui gen `score1'=`score2'+`i2'
|
||||
forvalues j=`=`nbitemsnosel'+1'/`=`nbitemsnosel'+`nbitemssel'' {
|
||||
matrix `result`dim''[`iteration',`j']=1
|
||||
}
|
||||
matrix `result`dim''[`iteration',`=`nbitemstotdim`dim''+1']=`iteration'
|
||||
matrix `result`dim''[`iteration',`=`nbitemstotdim`dim''+2']=`nbitemssel'
|
||||
matrix `result`dim''[`iteration',`i']=2
|
||||
|
||||
if "`fast'"=="" {
|
||||
qui count
|
||||
local N=r(N)
|
||||
* di "qui raschtestv7 `listitemssel' `i2' , mean method(cml) test(none)"
|
||||
qui raschtestv7 `listitemssel' `i2' , mean method(cml) test(none)
|
||||
matrix `result`dim''[`iteration',`=`nbitemstotdim`dim''+3']=r(ll)
|
||||
matrix `result`dim''[`iteration',`=`nbitemstotdim`dim''+4']=2*(-r(ll)+(2*`nbitemssel'+3))
|
||||
|
||||
local nb1:word count `listitemssel'
|
||||
qui raschtestv7 `listitemssel',trace test(none) mean
|
||||
matrix `result`dim''[`iteration',`=`nbitemstotdim`dim''+5']=r(ll)
|
||||
qui logit `i2'
|
||||
matrix `result`dim''[`iteration',`=`nbitemstotdim`dim''+5']=`result`dim''[`iteration',`=`nbitemstotdim`dim''+5']+e(ll)
|
||||
matrix `result`dim''[`iteration',`=`nbitemstotdim`dim''+6']=2*(-`result`dim''[`iteration',`=`nbitemstotdim`dim''+5']+(2*`nbitemssel'+3))
|
||||
}
|
||||
else {
|
||||
qui count
|
||||
local N=r(N)
|
||||
qui raschtestv7 `listitemssel' `i2' , method(mml) test(none)
|
||||
matrix `result`dim''[`iteration',`=`nbitemstotdim`dim''+3']=r(ll)
|
||||
matrix `result`dim''[`iteration',`=`nbitemstotdim`dim''+4']=2*(-r(ll)+`nbitemssel'+2)
|
||||
|
||||
local nb1:word count `listitemssel'
|
||||
qui mmsrm `listitemssel' `i2' , part(`nb1' 1) iterate(20)
|
||||
matrix `result`dim''[`iteration',`=`nbitemstotdim`dim''+5']=e(ll)
|
||||
matrix `result`dim''[`iteration',`=`nbitemstotdim`dim''+6']=2*(-e(ll)+`nbitemssel'+4)
|
||||
}
|
||||
tokenize `listkernel' `varlist`dim''
|
||||
di in ye _col(4) %9.0f `iteration' _col(14) %14s abbrev("``i2num''",14) _col(29) %12.4f `result`dim''[`iteration',`=`nbitemstotdim`dim''+3'] _col(42) %12.4f `result`dim''[`iteration',`=`nbitemstotdim`dim''+5'] _col(55) %12.4f `result`dim''[`iteration',`=`nbitemstotdim`dim''+4'] _col(68) %12.4f `result`dim''[`iteration',`=`nbitemstotdim`dim''+6'] _c
|
||||
if `result`dim''[`iteration',`=`nbitemstot'+4']<=`result`dim''[`iteration',`=`nbitemstot'+6'] {
|
||||
matrix `result`dim''[`iteration',`i']=1
|
||||
matrix `result`dim''[`iteration',`=`nbitemstotdim`dim''+7']=1
|
||||
local nbitemssel=`nbitemssel'+1
|
||||
local nbitemsnosel=`nbitemsnosel'-1
|
||||
* local listitemssel `listitemssel' `rep'`i2num'
|
||||
local listitemssel `listitemssel' `i2'
|
||||
local listitemsselnum `listitemsselnum' `i2num'
|
||||
matrix `affect`dim''[1,`i2num']=1
|
||||
di in ye _col(88) "X"
|
||||
}
|
||||
else {
|
||||
matrix `result`dim''[`iteration',`=`nbitemstotdim`dim''+7']=2
|
||||
di
|
||||
}
|
||||
}
|
||||
di in green "{hline 90}"
|
||||
return matrix result`dim' `result`dim''
|
||||
local j=`kernel'+1
|
||||
forvalues i=`=`kernel'+1'/`nbitemstot' {
|
||||
if `affect'[1,`i']==0 {
|
||||
if `affect`dim''[1,`j']==1 {
|
||||
matrix `affect'[1,`i']=`dim'
|
||||
}
|
||||
local j=`j'+1
|
||||
}
|
||||
}
|
||||
}
|
||||
use `raschfitfile',clear
|
||||
|
||||
return matrix affect `affect'
|
||||
|
||||
end
|
217
Modules/ado/personal/r/old/raschpower - Copie version SIM.ado
Normal file
217
Modules/ado/personal/r/old/raschpower - Copie version SIM.ado
Normal file
@ -0,0 +1,217 @@
|
||||
*! version 1.2 November 1st, 2010
|
||||
*! Jean-Benoit Hardouin
|
||||
************************************************************************************************************
|
||||
* raschpower: Estimation of the power of the Wald test in order to compare the means of the latent trait in two groups of individuals
|
||||
*
|
||||
* Version 1 : January 25, 2010 (Jean-Benoit Hardouin)
|
||||
* Version 1.1 : January 26, 2010 (Jean-Benoit Hardouin)
|
||||
* Version 1.1 : November 1st, 2010 (Jean-Benoit Hardouin)
|
||||
*
|
||||
* Jean-benoit Hardouin, Faculty of Pharmaceutical Sciences - University of Nantes - France
|
||||
* jean-benoit.hardouin@univ-nantes.fr
|
||||
*
|
||||
* News about this program : http://www.anaqol.org
|
||||
* FreeIRT Project : http://www.freeirt.org
|
||||
*
|
||||
* Copyright 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 raschpower,rclass
|
||||
syntax [varlist] [, n0(int 100) n1(int 100) gamma(real .5) d(string) var(real 1) nodes(int 12)]
|
||||
version 11
|
||||
|
||||
|
||||
if "`d'"=="" {
|
||||
tempname d
|
||||
matrix `d'=[-1\-.5\0\.5\1]
|
||||
}
|
||||
|
||||
|
||||
/*tempname abs weight
|
||||
ghquadm `nodes' `abs' `weight'
|
||||
matrix `abs'=`abs''
|
||||
matrix `weight'=`weight''
|
||||
|
||||
matrix `abs'=`abs'*sqrt(`var')
|
||||
*matrix list `abs'
|
||||
matrix `abs'=[5.50090170446774,4.27182584793228,3.22370982877010,2.25946445100080,1.34037519715162,0.444403001944139,-5.50090170446774,-4.27182584793228,-3.22370982877010,-2.25946445100080,-1.34037519715162,-0.444403001944139]
|
||||
matrix `abs'=`abs''*sqrt(`var')
|
||||
matrix `weight'=[0.000000375975985,0.000121250244966,0.005523056331147,0.072984713184739,0.368391758069477,0.806292983509187,0.000000375975985,0.000121250244966,0.005523056331147,0.072984713184739,0.368391758069477,0.806292983509187]
|
||||
matrix `weight'=`weight''
|
||||
*matrix list `abs'
|
||||
*/
|
||||
local nbitems=rowsof(`d')
|
||||
|
||||
di in gr "Number of individuals in the first group: " in ye `n0'
|
||||
di in gr "Number of individuals in the second group: " in ye `n1'
|
||||
di in green "Group effect: " in ye `gamma'
|
||||
di in gr "Variance of the latent trait: " in ye `var'
|
||||
di in gr "Number of items: " in ye `nbitems'
|
||||
di in green "Difficulties parameters of the items: " _c
|
||||
tempname dd
|
||||
matrix `dd'=`d''
|
||||
matrix list `dd',noblank nohalf nonames noheader
|
||||
|
||||
matrix `dd'=`d'/sqrt(`var')
|
||||
local gamma=`gamma'/sqrt(`var')
|
||||
|
||||
|
||||
clear
|
||||
local temp=2^(`nbitems')
|
||||
qui range x 0 `=`temp'-1' `temp'
|
||||
qui g t=x
|
||||
loc i=1
|
||||
qui count if t>0
|
||||
loc z=r(N)
|
||||
qui while `z'>0 {
|
||||
qui g item`i'=mod(t,2^`i')==2^`=`i'-1'
|
||||
qui replace t=t-item`i'*2^`=`i'-1'
|
||||
qui count if t>0
|
||||
loc z=r(N)
|
||||
loc i=`i'+1
|
||||
}
|
||||
drop t
|
||||
qui expand 2
|
||||
qui gen group=0 in 1/`temp'
|
||||
qui replace group=1 in `=`temp'+1'/`=2*`temp''
|
||||
qui gen mean=-`n1'*`gamma'/(`n0'+`n1') if group==0
|
||||
qui replace mean=`n0'*`gamma'/(`n0'+`n1') if group==1
|
||||
qui gen proba=1
|
||||
forvalues i=1/`nbitems' {
|
||||
qui gen eps`i'=exp(mean-`d'[`i',1])
|
||||
qui replace proba=proba*eps`i'^item`i'/(1+eps`i')
|
||||
}
|
||||
|
||||
*list item* proba
|
||||
|
||||
qui gen eff=.
|
||||
forvalues i=0/1 {
|
||||
qui replace eff=proba*`n`i'' if group==`i'
|
||||
}
|
||||
|
||||
/*
|
||||
forvalues i=1/`nbitems' {
|
||||
qui gen f`i'=eps`i'^item`i'/(1+eps`i')
|
||||
qui gen fp`i'=(item`i'*eps`i'^item`i'+(item`i'-1)*eps`i'^(item`i'+1))/(1+eps`i')^2
|
||||
qui gen fpp`i'=((item`i'^2*eps`i'^item`i'+(item`i'^2-1)*eps`i'^(item`i'+1))*(1+eps`i')^2-2*eps`i'*(1+eps`i')*(item`i'*eps`i'^item`i'+(item`i'-1)*eps`i'^(item`i'+1)))/(1+eps`i')^4
|
||||
}
|
||||
*/
|
||||
qui replace eff=proba
|
||||
keep item* eff group proba
|
||||
|
||||
local p1=1/`n1'
|
||||
local p0=1/`n0'
|
||||
qui gen eff2=.
|
||||
qui replace eff2=floor(eff/`p1') if group==1
|
||||
qui replace eff2=floor(eff/`p0') if group==0
|
||||
|
||||
|
||||
qui replace eff=eff-eff2*(`p1'*group+`p0'*(1-group))
|
||||
qui su eff2 if group==1
|
||||
local aff1=r(sum)
|
||||
qui su eff2 if group==0
|
||||
local aff0=r(sum)
|
||||
|
||||
*di "Nombre de patients affectes : `aff1' dans groupe 1 (sur `n1') et `aff0' dans le groupe 0 (sur `n0')"
|
||||
|
||||
local unaff1=`n1'-`aff1'
|
||||
local unaff0=`n0'-`aff0'
|
||||
*di "Nombre de patients non affectes : `unaff1' dans groupe 1 (sur `n1') et `unaff0' dans le groupe 0 (sur `n0')"
|
||||
|
||||
|
||||
di "avant sort"
|
||||
list item* group proba eff2
|
||||
|
||||
|
||||
qui gsort + group - eff
|
||||
list item* group proba eff2
|
||||
qui replace eff2=eff2+1 in 1/`unaff0'
|
||||
di "apres sort"
|
||||
qui gsort - group - eff
|
||||
qui replace eff2=eff2+1 in 1/`unaff1'
|
||||
list item* group proba eff2
|
||||
su proba
|
||||
return list
|
||||
|
||||
*list eff eff2 group proba
|
||||
|
||||
qui drop if eff2==0
|
||||
|
||||
qui expand eff2
|
||||
qui gen i=_n
|
||||
|
||||
tempname diff
|
||||
matrix `diff'=`dd''
|
||||
|
||||
/***************************A REVOIR
|
||||
forvalues i=1/`nbitems' {
|
||||
qui su item`i'
|
||||
local var=r(Var)
|
||||
if `var'==0 {
|
||||
qui drop item`i'
|
||||
}
|
||||
}
|
||||
****************************FIN A REVOIR*/
|
||||
|
||||
*irtpoly item*, fixedvar(1) rasch fixed(`diff') covariablemean(group) sasout
|
||||
|
||||
qui drop proba eff eff2
|
||||
qui reshape long item, i(i)
|
||||
qui rename item rep
|
||||
qui rename _j item
|
||||
|
||||
qui gen offset=0
|
||||
forvalues i=1/`nbitems' {
|
||||
qui replace offset=-`diff'[1,`i'] if item==`i'
|
||||
}
|
||||
constraint 1 _cons=0
|
||||
qui gen groupc=group-.5
|
||||
qui xtlogit rep groupc ,nocons i(i) offset(offset) constraint(1)
|
||||
|
||||
tempname b V
|
||||
matrix `b'=e(b)
|
||||
matrix `V'=e(V)
|
||||
local gammaest=`b'[1,1]*sqrt(`var')
|
||||
local se=`V'[1,1]^.5*sqrt(`var')
|
||||
di
|
||||
di
|
||||
di in gr "{hline 76}"
|
||||
di _col(50) "Estimation with the "
|
||||
di _col(40) "Cramer-Rao bound" _col(60) "classical formula"
|
||||
di in gr "{hline 76}"
|
||||
di in green "Estimated value of the group effect" _col(49) in ye %7.2f `gammaest'
|
||||
di in green "Standard Error of this estimation" _col(49) in ye %7.2f `se'
|
||||
di in green "Variance of this estimation" _col(46) in ye %10.4f `=`se'^2'
|
||||
local power=1-normal(1.96-`gamma'*sqrt(`var')/`se')
|
||||
local clpower=normal(sqrt(`n1'*`gamma'^2/(`n1'/`n0'+1))-1.96)
|
||||
di in green "Estimated value of the power" _col(50) in ye %6.4f `power' _col(71) in ye %6.4f `clpower'
|
||||
local clnsn=(`n1'/`n0'+1)/((`n1'/`n0')*`gamma'^2)*(1.96-invnorm(1-`power'))^2
|
||||
di in green "Number of patients for a power of" %6.2f `=`power'*100' "%" _col(49) in ye `n0' "/" `n1' _col(62) in ye %7.2f `clnsn' "/" %7.2f `clnsn'
|
||||
di in green "Ratio of the number of patients" in ye %6.2f _col(55)`=(`n0'+`n1')/(2*`clnsn')'
|
||||
di in gr "{hline 76}"
|
||||
|
||||
return scalar EstGamma=`gammaest'
|
||||
return scalar CRbound=`=`se'^2'
|
||||
return scalar CRPower=`power'
|
||||
return scalar ClPower=`clpower'
|
||||
return scalar ClSS=`clnsn'
|
||||
return scalar Ratio=`=`n0'/`clnsn''
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
220
Modules/ado/personal/r/old/raschpower1.5.ado
Normal file
220
Modules/ado/personal/r/old/raschpower1.5.ado
Normal file
@ -0,0 +1,220 @@
|
||||
*! version 1.5 : July 11th, 2011
|
||||
*! Jean-Benoit Hardouin
|
||||
************************************************************************************************************
|
||||
* raschpower: Estimation of the power of the Wald test in order to compare the means of the latent trait in two groups of individuals
|
||||
*
|
||||
* Version 1 : January 25, 2010 (Jean-Benoit Hardouin)
|
||||
* Version 1.1 : January 26, 2010 (Jean-Benoit Hardouin)
|
||||
* Version 1.2 : November 1st, 2010 (Jean-Benoit Hardouin)
|
||||
* version 1.3 : May 2th, 2011 (Jean-Benoit Hardouin)
|
||||
* version 1.4 : July 7th, 2011 (Jean-Benoit Hardouin) : minor corrections
|
||||
* version 1.5 : July 11th, 2011 (Jean-Benoit Hardouin) : minor corrections
|
||||
*
|
||||
* Jean-benoit Hardouin, Faculty of Pharmaceutical Sciences - University of Nantes - France
|
||||
* jean-benoit.hardouin@univ-nantes.fr
|
||||
*
|
||||
* News about this program : http://www.anaqol.org
|
||||
* FreeIRT Project : http://www.freeirt.org
|
||||
*
|
||||
* Copyright 2010-2011 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 raschpower,rclass
|
||||
syntax [varlist] [, n0(int 100) n1(int 100) gamma(real .5) d(string) var(real 1) fast nodata gammafix EXPectedpower(real -1)]
|
||||
version 11
|
||||
|
||||
tempfile raschpowerfile
|
||||
capture qui save "`raschpowerfile'",replace
|
||||
if "`d'"=="" {
|
||||
tempname d
|
||||
matrix `d'=[-1\-.5\0\.5\1]
|
||||
}
|
||||
|
||||
local nbitems=rowsof(`d')
|
||||
|
||||
di in gr "Number of individuals in the first group: " in ye `n0'
|
||||
di in gr "Number of individuals in the second group: " in ye `n1'
|
||||
di in green "Group effect: " in ye `gamma'
|
||||
di in gr "Variance of the latent trait: " in ye `var'
|
||||
di in gr "Number of items: " in ye `nbitems'
|
||||
di in green "Difficulties parameters of the items: " _c
|
||||
tempname dd
|
||||
matrix `dd'=`d''
|
||||
matrix list `dd',noblank nohalf nonames noheader
|
||||
|
||||
matrix `dd'=`d'/*sqrt(`var')*/
|
||||
local gamma=`gamma'/*sqrt(`var')*/
|
||||
|
||||
if "`data'"=="" {
|
||||
clear
|
||||
local temp=2^(`nbitems')
|
||||
qui range x 0 `=`temp'-1' `temp'
|
||||
qui g t=x
|
||||
loc i=1
|
||||
qui count if t>0
|
||||
loc z=r(N)
|
||||
qui while `z'>0 {
|
||||
qui g item`i'=mod(t,2^`i')==2^`=`i'-1'
|
||||
qui replace t=t-item`i'*2^`=`i'-1'
|
||||
qui count if t>0
|
||||
loc z=r(N)
|
||||
loc i=`i'+1
|
||||
}
|
||||
drop t
|
||||
qui expand 2
|
||||
qui gen group=0 in 1/`temp'
|
||||
qui replace group=1 in `=`temp'+1'/`=2*`temp''
|
||||
qui gen mean=-`n1'*`gamma'/(`n0'+`n1') if group==0
|
||||
qui replace mean=`n0'*`gamma'/(`n0'+`n1') if group==1
|
||||
|
||||
if "`fast'"=="" {
|
||||
qui gen proba=.
|
||||
forvalues i=1/`=2*`temp'' {
|
||||
local int=1
|
||||
forvalues j=1/`nbitems' {
|
||||
qui su item`j' in `i'
|
||||
local rep=r(mean)
|
||||
local diff=`d'[`j',1]
|
||||
local int "`int'*exp(`rep'*(x-`diff'))/(1+exp(x-`diff'))"
|
||||
}
|
||||
qui su mean in `i'
|
||||
local mean=r(mean)
|
||||
qui gausshermite `int',mu(`mean') sigma(`=sqrt(`var')') display
|
||||
qui replace proba=r(int) in `i'
|
||||
}
|
||||
}
|
||||
else {
|
||||
qui gen proba=1
|
||||
forvalues i=1/`nbitems' {
|
||||
qui gen eps`i'=exp(mean-`d'[`i',1])
|
||||
qui replace proba=proba*eps`i'^item`i'/(1+eps`i')
|
||||
}
|
||||
}
|
||||
qui gen eff=.
|
||||
forvalues i=0/1 {
|
||||
qui replace eff=proba*`n`i'' if group==`i'
|
||||
}
|
||||
qui replace eff=proba
|
||||
keep item* eff group proba
|
||||
|
||||
local p1=1/`n1'
|
||||
local p0=1/`n0'
|
||||
qui gen eff2=.
|
||||
qui replace eff2=floor(eff/`p1') if group==1
|
||||
qui replace eff2=floor(eff/`p0') if group==0
|
||||
qui replace eff=eff-eff2*(`p1'*group+`p0'*(1-group))
|
||||
qui su eff2 if group==1
|
||||
local aff1=r(sum)
|
||||
qui su eff2 if group==0
|
||||
local aff0=r(sum)
|
||||
|
||||
local unaff1=`n1'-`aff1'
|
||||
local unaff0=`n0'-`aff0'
|
||||
gen efftmp=eff2
|
||||
|
||||
qui gsort + group - eff
|
||||
qui replace eff2=eff2+1 in 1/`unaff0'
|
||||
qui gsort - group - eff
|
||||
qui replace eff2=eff2+1 in 1/`unaff1'
|
||||
|
||||
*qui drop if eff2==0
|
||||
gsort group item*
|
||||
gen res=proba*50
|
||||
*list item* group efftmp eff2 proba
|
||||
|
||||
qui expand eff2
|
||||
qui drop proba eff eff2
|
||||
}
|
||||
qui gen i=_n
|
||||
|
||||
*su
|
||||
qui alpha item*
|
||||
local alpha=r(alpha)
|
||||
|
||||
tempname diff
|
||||
matrix `diff'=`dd''
|
||||
|
||||
qui reshape long item, i(i)
|
||||
qui rename item rep
|
||||
qui rename _j item
|
||||
|
||||
qui gen offset=0
|
||||
forvalues i=1/`nbitems' {
|
||||
qui replace offset=-`diff'[1,`i'] if item==`i'
|
||||
}
|
||||
qui gen groupc=group-.5
|
||||
matrix est=(`gamma',`=sqrt(`var')')
|
||||
|
||||
|
||||
|
||||
if "`gammafix'"=="" {
|
||||
constraint 1 _cons=`=ln(`var')'
|
||||
qui xtlogit rep groupc ,nocons i(i) offset(offset) constraint(1)
|
||||
}
|
||||
else {
|
||||
qui gllamm rep groupc, nocons i(i) offset(offset) iterate(0) fam(bin) link(logit) from(est) copy
|
||||
}
|
||||
|
||||
|
||||
tempname b V
|
||||
matrix `b'=e(b)
|
||||
matrix `V'=e(V)
|
||||
local gammaest=`b'[1,1]/*sqrt(`var')*/
|
||||
local se=`V'[1,1]^.5/*sqrt(`var')*/
|
||||
di
|
||||
di
|
||||
di in gr "{hline 91}"
|
||||
di _col(60) "Estimation with the "
|
||||
di _col(50) "Cramer-Rao bound" _col(75) "classical formula"
|
||||
di in gr "{hline 91}"
|
||||
if "`gammafixed'"=="" {
|
||||
di in green "Estimated value of the group effect" _col(59) in ye %7.2f `gammaest'
|
||||
}
|
||||
di in green "Estimation of the s.e. of the group effect" _col(59) in ye %7.2f `se'
|
||||
di in green "Estimation of the variance of the group effect" _col(56) in ye %10.4f `=`se'^2'
|
||||
local power=1-normal(1.96-`gamma'/*sqrt(`var')*//`se')+normal(-1.96-`gamma'*sqrt(`var')/`se')
|
||||
local poweruni=1-normal(1.96-`gamma'/*sqrt(`var')*//`se')
|
||||
local clpower=normal(sqrt(`n1'*`gamma'^2/(`n1'/`n0'+1))-1.96)
|
||||
/*si on ne n<>glige pas le deuxi<78>me terme, la bonne puissance est*/
|
||||
*di in green "Estimation of the power" _col(60) in ye %6.4f `power' _col(86) in ye %6.4f `clpower'
|
||||
di in green "Estimation of the power" _col(60) in ye %6.4f `poweruni' _col(86) in ye %6.4f `clpower'
|
||||
/*si on ne n<>glige pas le deuci<63>me terme, la bonne puissance est*/
|
||||
*local clnsn=(`n1'/`n0'+1)/((`n1'/`n0')*(`gamma'/sqrt(`var'))^2)*(1.96-invnorm(1-`power'))^2
|
||||
local clnsn=(`n1'/`n0'+1)/((`n1'/`n0')*(`gamma'/sqrt(`var'))^2)*(1.96-invnorm(1-`poweruni'))^2
|
||||
di in green "Number of patients for a power of" %6.2f `=`poweruni'*100' "%" _col(59) in ye `n0' "/" `n1' _col(77) in ye %7.2f `clnsn' "/" %7.2f `clnsn'
|
||||
di in green "Ratio of the number of patients" in ye %6.2f _col(68)`=(`n0'+`n1')/(2*`clnsn')'
|
||||
if `expectedpower'!=-1 {
|
||||
qui sampsi `=-`gamma'/2' `=`gamma'/2', sd1(`=sqrt(`var')') sd2(`=sqrt(`var')') alpha(0.05) power(`expectedpower')
|
||||
local expn=r(N_1)
|
||||
local expn2=`expn'*`=(`n0'+`n1')/(2*`clnsn')'
|
||||
di in green "Number of patients for a power of" %6.2f `=`expectedpower'*100' "%" _col(51) in ye %7.2f `expn2' "/" %7.2f `expn2' _col(77) in ye %7.2f `expn' "/" %7.2f `expn'
|
||||
}
|
||||
di in gr "{hline 91}"
|
||||
|
||||
return scalar EstGamma=`gammaest'
|
||||
return scalar CRbound=`=`se'^2'
|
||||
return scalar CRPower=`poweruni'
|
||||
return scalar ClPower=`clpower'
|
||||
return scalar ClSS=`clnsn'
|
||||
return scalar Ratio=`=`n0'/`clnsn''
|
||||
return scalar CronbachAlpha=`alpha'
|
||||
|
||||
|
||||
|
||||
capture qui use `raschpowerfile',clear
|
||||
|
||||
end
|
193
Modules/ado/personal/r/old/raschpower1.ado
Normal file
193
Modules/ado/personal/r/old/raschpower1.ado
Normal file
@ -0,0 +1,193 @@
|
||||
*! version 1 january 25th, 2010
|
||||
*! Jean-Benoit Hardouin
|
||||
************************************************************************************************************
|
||||
* raschpower: Estimation of the power of the Wald test in order to compare the means of the latent trait in two groups of individuals
|
||||
*
|
||||
* Version 1 : January 25, 2010 (Jean-Benoit Hardouin)
|
||||
*
|
||||
* Jean-benoit Hardouin, Faculty of Pharmaceutical Sciences - University of Nantes - France
|
||||
* jean-benoit.hardouin@univ-nantes.fr
|
||||
*
|
||||
* News about this program : http://www.anaqol.org
|
||||
* FreeIRT Project : http://www.freeirt.org
|
||||
*
|
||||
* Copyright 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 raschpower1,rclass
|
||||
syntax [varlist] [, n0(int 100) n1(int 100) gamma(real .5) d(string) var(real 1) nodes(int 12)]
|
||||
|
||||
|
||||
|
||||
if "`d'"=="" {
|
||||
tempname d
|
||||
matrix `d'=[-1\-.5\0\.5\1]
|
||||
}
|
||||
|
||||
/*tempname abs weight
|
||||
ghquadm `nodes' `abs' `weight'
|
||||
matrix `abs'=`abs''
|
||||
matrix `weight'=`weight''
|
||||
|
||||
matrix `abs'=`abs'*sqrt(`var')
|
||||
*matrix list `abs'
|
||||
matrix `abs'=[5.50090170446774,4.27182584793228,3.22370982877010,2.25946445100080,1.34037519715162,0.444403001944139,-5.50090170446774,-4.27182584793228,-3.22370982877010,-2.25946445100080,-1.34037519715162,-0.444403001944139]
|
||||
matrix `abs'=`abs''*sqrt(`var')
|
||||
matrix `weight'=[0.000000375975985,0.000121250244966,0.005523056331147,0.072984713184739,0.368391758069477,0.806292983509187,0.000000375975985,0.000121250244966,0.005523056331147,0.072984713184739,0.368391758069477,0.806292983509187]
|
||||
matrix `weight'=`weight''
|
||||
*matrix list `abs'
|
||||
*/
|
||||
local nbitems=rowsof(`d')
|
||||
|
||||
di in gr "Number of individuals in the first group: " in ye `n0'
|
||||
di in gr "Number of individuals in the second group: " in ye `n1'
|
||||
di in green "Group effect: " in ye `gamma'
|
||||
di in gr "Variance of the latent trait: " in ye `var'
|
||||
di in gr "Number of items: " in ye `nbitems'
|
||||
di in green "Difficulties parameters of the items: " _c
|
||||
tempname dd
|
||||
matrix `dd'=`d''
|
||||
matrix list `dd',noblank nohalf nonames noheader
|
||||
|
||||
|
||||
|
||||
clear
|
||||
local temp=2^(`nbitems')
|
||||
qui range x 0 `=`temp'-1' `temp'
|
||||
qui g t=x
|
||||
loc i=1
|
||||
qui count if t>0
|
||||
loc z=r(N)
|
||||
qui while `z'>0 {
|
||||
qui g item`i'=mod(t,2^`i')==2^`=`i'-1'
|
||||
qui replace t=t-item`i'*2^`=`i'-1'
|
||||
qui count if t>0
|
||||
loc z=r(N)
|
||||
loc i=`i'+1
|
||||
}
|
||||
drop t
|
||||
qui expand 2
|
||||
qui gen group=0 in 1/`temp'
|
||||
qui replace group=1 in `=`temp'+1'/`=2*`temp''
|
||||
qui gen mean=(-1)^(1-group)*`gamma'*sqrt(`var')/2
|
||||
qui gen proba=1
|
||||
forvalues i=1/`nbitems' {
|
||||
qui gen eps`i'=exp(mean-`d'[`i',1])
|
||||
qui replace proba=proba*eps`i'^item`i'/(1+eps`i')
|
||||
}
|
||||
qui gen eff=.
|
||||
forvalues i=0/1 {
|
||||
qui replace eff=proba*`n`i'' if group==`i'
|
||||
}
|
||||
forvalues i=1/`nbitems' {
|
||||
qui gen f`i'=eps`i'^item`i'/(1+eps`i')
|
||||
qui gen fp`i'=(item`i'*eps`i'^item`i'+(item`i'-1)*eps`i'^(item`i'+1))/(1+eps`i')^2
|
||||
qui gen fpp`i'=((item`i'^2*eps`i'^item`i'+(item`i'^2-1)*eps`i'^(item`i'+1))*(1+eps`i')^2-2*eps`i'*(1+eps`i')*(item`i'*eps`i'^item`i'+(item`i'-1)*eps`i'^(item`i'+1)))/(1+eps`i')^4
|
||||
}
|
||||
qui replace eff=proba
|
||||
keep item* eff group proba
|
||||
|
||||
local p1=1/`n1'
|
||||
local p0=1/`n0'
|
||||
qui gen eff2=.
|
||||
qui replace eff2=floor(eff/`p1') if group==1
|
||||
qui replace eff2=floor(eff/`p0') if group==0
|
||||
qui replace eff=eff-eff2*(`p1'*group+`p0'*(1-group))
|
||||
qui su eff2 if group==1
|
||||
local aff1=r(sum)
|
||||
qui su eff2 if group==0
|
||||
local aff0=r(sum)
|
||||
|
||||
*di "Nombre de patients affectes : `aff1' dans groupe 1 (sur `n1') et `aff0' dans le groupe 0 (sur `n0')"
|
||||
|
||||
local unaff1=`n1'-`aff1'
|
||||
local unaff0=`n0'-`aff0'
|
||||
*di "Nombre de patients non affectes : `unaff1' dans groupe 1 (sur `n1') et `unaff0' dans le groupe 0 (sur `n0')"
|
||||
|
||||
qui gsort + group - eff
|
||||
qui replace eff2=eff2+1 in 1/`unaff0'
|
||||
qui gsort - group - eff
|
||||
qui replace eff2=eff2+1 in 1/`unaff1'
|
||||
|
||||
*list eff eff2 group proba
|
||||
|
||||
qui drop if eff2==0
|
||||
|
||||
qui expand eff2
|
||||
qui gen i=_n
|
||||
|
||||
tempname diff
|
||||
matrix `diff'=`d''
|
||||
|
||||
/***************************A REVOIR
|
||||
forvalues i=1/`nbitems' {
|
||||
qui su item`i'
|
||||
local var=r(Var)
|
||||
if `var'==0 {
|
||||
qui drop item`i'
|
||||
}
|
||||
}
|
||||
****************************FIN A REVOIR*/
|
||||
|
||||
*irtpoly item*, fixedvar(1) rasch fixed(`diff') covariablemean(group) sasout
|
||||
|
||||
qui drop proba eff eff2
|
||||
qui reshape long item, i(i)
|
||||
qui rename item rep
|
||||
qui rename _j item
|
||||
|
||||
qui gen offset=0
|
||||
forvalues i=1/`nbitems' {
|
||||
qui replace offset=-`diff'[1,`i'] if item==`i'
|
||||
}
|
||||
constraint 1 _cons=0
|
||||
qui gen groupc=group-.5
|
||||
xtlogit rep groupc ,nocons i(i) offset(offset) constraint(1)
|
||||
|
||||
tempname b V
|
||||
matrix `b'=e(b)
|
||||
matrix `V'=e(V)
|
||||
local gammaest=`b'[1,1]
|
||||
local se=`V'[1,1]^.5
|
||||
di
|
||||
di
|
||||
di in gr "{hline 76}"
|
||||
di _col(50) "Estimation with the "
|
||||
di _col(40) "Cramer-Rao bound" _col(60) "classical formula"
|
||||
di in gr "{hline 76}"
|
||||
di in green "Estimated value of the group effect" _col(49) in ye %7.2f `gammaest'
|
||||
di in green "Standard Error of this estimation" _col(49) in ye %7.2f `se'
|
||||
di in green "Variance if this estimation" _col(46) in ye %10.4f `=`se'^2'
|
||||
local power=1-normal(1.96-`gamma'/`se')
|
||||
local clpower=normal(sqrt(`n0'*`gamma'^2/2)-1.96)
|
||||
di in green "Estimated value of the power" _col(50) in ye %6.4f `power' _col(71) in ye %6.4f `clpower'
|
||||
local clnsn=2/`gamma'^2*(1.96-invnorm(1-`power'))^2
|
||||
di in green "Number of patients for a power of" %6.2f `=`power'*100' "%" _col(49) in ye `n0' "/" `n1' _col(62) in ye %7.2f `clnsn' "/" %7.2f `clnsn'
|
||||
di in green "Ratio of the number of patients" in ye %6.2f _col(55)`=(`n0'+`n1')/(2*`clnsn')'
|
||||
di in gr "{hline 76}"
|
||||
|
||||
return scalar EstGamma=`gammaest'
|
||||
return scalar CRbound=`=`se'^2'
|
||||
return scalar CRPower=`power'
|
||||
return scalar ClPower=`clpower'
|
||||
return scalar ClSS=`clnsn'
|
||||
return scalar Ratio=`=`n0'/`clnsn''
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
374
Modules/ado/personal/r/old/raschpowerpcm.ado
Normal file
374
Modules/ado/personal/r/old/raschpowerpcm.ado
Normal file
@ -0,0 +1,374 @@
|
||||
*! version 3.1 : October 25th, 2011
|
||||
*! Jean-Benoit Hardouin, Myriam Blanchin
|
||||
************************************************************************************************************
|
||||
* raschpower: Estimation of the power of the Wald test in order to compare the means of the latent trait in two groups of individuals
|
||||
*
|
||||
* Version 1 : January 25, 2010 (Jean-Benoit Hardouin)
|
||||
* Version 1.1 : January 26, 2010 (Jean-Benoit Hardouin)
|
||||
* Version 1.2 : November 1st, 2010 (Jean-Benoit Hardouin)
|
||||
* version 1.3 : May 2th, 2011 (Jean-Benoit Hardouin)
|
||||
* version 1.4 : July 7th, 2011 (Jean-Benoit Hardouin) : minor corrections
|
||||
* version 1.5 : July 11th, 2011 (Jean-Benoit Hardouin) : minor corrections
|
||||
* version 2 : August 30th, 2011 (Jean-Benoit Hardouin, Myriam Blanchin) : corrections
|
||||
* version 3 : October 18th, 2011 (Jean-Benoit Hardouin, Myriam Blanchin) : Extension to the PCM, -method- option, -nbpatterns- options, changes in the presentation of the results
|
||||
* version 3.1 : October 25th, 2011 (Jean-Benoit Hardouin, Myriam Blanchin) : POPULATION+GH method
|
||||
*
|
||||
* Jean-benoit Hardouin, jean-benoit.hardouin@univ-nantes.fr
|
||||
* Myriam Blanchin, myriam.blanchin@univ-nantes.fr
|
||||
* EA 4275 "Biostatistics, Pharmacoepidemiology and Subjectives Measures in Health"
|
||||
* Faculty of Pharmaceutical Sciences - University of Nantes - France
|
||||
*
|
||||
* News about this program : http://www.anaqol.org
|
||||
* FreeIRT Project : http://www.freeirt.org
|
||||
*
|
||||
* Copyright 2010-2011 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 raschpowerpcm,rclass
|
||||
syntax [varlist] [, n0(int 100) n1(int 100) Gamma(real .5) Difficulties(string) Var(real 1) Method(string) NBPatterns(int 2) nodata gammafix EXPectedpower(real -1)]
|
||||
version 11
|
||||
|
||||
tempfile raschpowerfile
|
||||
capture qui save "`raschpowerfile'",replace
|
||||
tempname db d
|
||||
if "`difficulties'"=="" {
|
||||
*matrix `d'=[-1\-.5\0\.5\1]
|
||||
matrix `d'=[-1.151, -0.987\-0.615, -0.325\-0.184, -0.043\0.246, 0.554\0.782, 1.724]
|
||||
*matrix `d'=[ -1.527, -1.019\-1.100, -0.793\-0.796, -0.369\-0.540, 0.152\-0.306, -0.220\-0.077, 0.147\0.156, 0.431\0.412, 0.685\0.716, 1.332\1.043, 1.572]
|
||||
}
|
||||
else {
|
||||
matrix `d'=`difficulties'
|
||||
}
|
||||
local nbitems=rowsof(`d')
|
||||
local nbmodat=colsof(`d')+1
|
||||
if "`method'"=="MEAN+GH"&`nbpatterns'*(`n1'+`n0')>=`=`nbmodat'^`nbitems'*2' {
|
||||
di in gr "The MEAN+GH will be inefficient compared to GH since the maximal number of pattern's responses"
|
||||
di in gr "is lesser than the number of pattern retained by the MEAN+GH method."
|
||||
di in gr "The -method- option is replaced by GH."
|
||||
local method GH
|
||||
}
|
||||
else if "`method'"=="" {
|
||||
if `nbmodat'^`nbitems'*2<1000 {
|
||||
local method GH
|
||||
}
|
||||
else if `nbmodat'^`nbitems'<10000 {
|
||||
local method MEAN+GH
|
||||
}
|
||||
else if `nbmodat'^`nbitems'<1000000 {
|
||||
local method MEAN
|
||||
}
|
||||
else {
|
||||
local method POPULATION+GH
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
di in gr "Method: " in ye "`method'"
|
||||
di in gr "Number of individuals in the first group: " in ye `n0'
|
||||
di in gr "Number of individuals in the second group: " in ye `n1'
|
||||
di in green "Group effect: " in ye `gamma'
|
||||
di in gr "Variance of the latent trait: " in ye `var'
|
||||
di in gr "Number of items: " in ye `nbitems'
|
||||
di in green "Difficulties parameters of the items: "
|
||||
tempname dd
|
||||
matrix `dd'=`d''
|
||||
local items
|
||||
forvalues i=1/`nbitems' {
|
||||
local items "`items' item`i'"
|
||||
}
|
||||
local modalities
|
||||
forvalues i=1/`=`nbmodat'-1' {
|
||||
local modalities "`modalities' delta_`i'"
|
||||
}
|
||||
|
||||
matrix colnames `dd'=`items'
|
||||
matrix rownames `dd'=`modalities'
|
||||
matrix list `dd',noblank nohalf noheader
|
||||
di in gr "Number of studied response's patterns: " in ye `=`nbmodat'^`nbitems'*2'
|
||||
|
||||
matrix `dd'=`d'
|
||||
local gamma=`gamma'
|
||||
|
||||
local tmp=1
|
||||
qui matrix `db'=J(`=`nbitems'*(`nbmodat'-1)',1,.)
|
||||
forvalues j=1/`nbitems' {
|
||||
forvalues m=1/`=`nbmodat'-1' {
|
||||
qui matrix `db'[`tmp',1]=`d'[`j',`m']
|
||||
local ++tmp
|
||||
}
|
||||
}
|
||||
|
||||
if "`data'"=="" {
|
||||
clear
|
||||
if "`method'"!="POPULATION+GH"&"`method'"!="POPULATION+MEAN" {
|
||||
local temp=`nbmodat'^(`nbitems')
|
||||
qui range x 0 `=`temp'-1' `temp'
|
||||
qui g t=x
|
||||
loc i=`nbitems'
|
||||
qui count if t>0
|
||||
loc z=r(N)
|
||||
qui while `z'>0 {
|
||||
qui gen item`=`nbitems'-`i'+1'=floor(t/`nbmodat'^`=`i'-1')
|
||||
qui replace t=mod(t,`nbmodat'^`=`i'-1')
|
||||
qui count if t>0
|
||||
loc z=r(N)
|
||||
loc i=`i'-1
|
||||
}
|
||||
drop t
|
||||
qui expand 2
|
||||
qui gen group=0 in 1/`temp'
|
||||
qui replace group=1 in `=`temp'+1'/`=2*`temp''
|
||||
}
|
||||
else {
|
||||
qui simirt, clear pcm(`difficulties') cov(`var') group(`=`n1'/(`n1'+`n0')') deltagroup(`gamma') nbobs(1000000)
|
||||
qui drop lt1
|
||||
qui contract item* group, freq(freq)
|
||||
qui gen keep=0
|
||||
qui gsort +group -freq
|
||||
qui replace keep=1 in 1/`=`nbpatterns'*`n1''
|
||||
qui gsort -group -freq
|
||||
qui replace keep=1 in 1/`=`nbpatterns'*`n0''
|
||||
qui keep if keep==1
|
||||
qui count
|
||||
local tmp=r(N)
|
||||
di "Number of kept patterns:`tmp'"
|
||||
local method GH
|
||||
}
|
||||
qui gen mean=-`n1'*`gamma'/(`n0'+`n1') if group==0
|
||||
qui replace mean=`n0'*`gamma'/(`n0'+`n1') if group==1
|
||||
|
||||
if "`method'"=="GH" {
|
||||
local temp=`nbmodat'^(`nbitems')
|
||||
local diff0=0
|
||||
qui gen proba=.
|
||||
local dixj=10
|
||||
qui count
|
||||
local tmp=r(N)
|
||||
forvalues i=1/`tmp' {
|
||||
local dix=floor(`tmp'/10)
|
||||
if mod(`i',`dix')==0 {
|
||||
if "`dixj'"!="10" {
|
||||
di ".." _c
|
||||
}
|
||||
di "`dixj'%" _c
|
||||
local dixj=`dixj'+10
|
||||
}
|
||||
local int=1
|
||||
forvalues j=1/`nbitems' {
|
||||
qui su item`j' in `i'
|
||||
local rep=r(mean)
|
||||
local diff0=0
|
||||
local diff1=`d'[`j',1]
|
||||
local sum "1+exp(x-`diff1')"
|
||||
forvalues m=2/`=`nbmodat'-1' {
|
||||
local diff`m'=`diff`=`m'-1''+`d'[`j',`m']
|
||||
local sum "`sum'+exp(`m'*x-`diff`m'')"
|
||||
}
|
||||
local int "(`int'*exp(`rep'*x-`diff`rep''))/(`sum')"
|
||||
}
|
||||
qui su mean in `i'
|
||||
local mean=r(mean)
|
||||
qui gausshermite `int',mu(`mean') sigma(`=sqrt(`var')') display
|
||||
qui replace proba=r(int) in `i'
|
||||
}
|
||||
di
|
||||
}
|
||||
else {
|
||||
qui gen proba=1
|
||||
forvalues i=1/`nbitems' {
|
||||
local diff0=0
|
||||
local diff1=`d'[`i',1]
|
||||
qui gen eps0=1
|
||||
qui gen eps1=exp(mean-`diff1')
|
||||
qui gen d=eps0+eps1
|
||||
forvalues m=2/`=`nbmodat'-1' {
|
||||
local diff`m'=`diff`=`m'-1''+`d'[`i',`m']
|
||||
qui gen eps`m'=exp(`m'*mean-`diff`m'')
|
||||
qui replace d=d+eps`m'
|
||||
}
|
||||
local listeps
|
||||
forvalues m=0/`=`nbmodat'-1' {
|
||||
qui replace proba=proba*eps`m'/d if item`i'==`m'
|
||||
local listeps `listeps' eps`m'
|
||||
}
|
||||
qui drop `listeps' d
|
||||
}
|
||||
if "`method'"=="MEAN+GH" {
|
||||
set tracedepth 1
|
||||
qui gen keep=0
|
||||
qui gsort -group -proba
|
||||
local min=min(`=`nbmodat'^`nbitems'',`=`n1'*`nbpatterns'')
|
||||
qui replace keep=1 in 1/`min'
|
||||
qui gsort +group -proba
|
||||
local min=min(`=`nbmodat'^`nbitems'',`=`n0'*`nbpatterns'')
|
||||
qui replace keep=1 in 1/`min'
|
||||
qui keep if keep==1
|
||||
qui su proba if group==0
|
||||
local sumproba0=r(sum)*100
|
||||
qui su proba if group==1
|
||||
local sumproba1=r(sum)*100
|
||||
|
||||
|
||||
qui drop keep proba
|
||||
local diff0=0
|
||||
qui gen proba=.
|
||||
qui count
|
||||
local nnew=r(N)
|
||||
di in gr "Number of studied response's patterns for the GH step: " in ye `nnew'
|
||||
di in gr "(" in ye %6.2f `sumproba0' in gr "% of the group 0 and " in ye %6.2f `sumproba1' in gr "% of the group 1)"
|
||||
local dixj=10
|
||||
forvalues i=1/`nnew' {
|
||||
local dix=floor(`nnew'/10)
|
||||
if mod(`i',`dix')==0 {
|
||||
if "`dixj'"!="10" {
|
||||
di ".." _c
|
||||
}
|
||||
di "`dixj'%" _c
|
||||
local dixj=`dixj'+10
|
||||
}
|
||||
local int=1
|
||||
forvalues j=1/`nbitems' {
|
||||
qui su item`j' in `i'
|
||||
local rep=r(mean)
|
||||
local diff0=0
|
||||
local diff1=`d'[`j',1]
|
||||
local sum "1+exp(x-`diff1')"
|
||||
forvalues m=2/`=`nbmodat'-1' {
|
||||
local diff`m'=`diff`=`m'-1''+`d'[`j',`m']
|
||||
local sum "`sum'+exp(`m'*x-`diff`m'')"
|
||||
}
|
||||
local int "(`int'*exp(`rep'*x-`diff`rep''))/(`sum')"
|
||||
}
|
||||
qui su mean in `i'
|
||||
local mean=r(mean)
|
||||
qui gausshermite `int',mu(`mean') sigma(`=sqrt(`var')') display
|
||||
qui replace proba=r(int) in `i'
|
||||
}
|
||||
}
|
||||
}
|
||||
qui gen eff=.
|
||||
forvalues i=0/1 {
|
||||
qui replace eff=proba*`n`i'' if group==`i'
|
||||
}
|
||||
qui replace eff=proba
|
||||
qui keep item* eff group proba
|
||||
|
||||
local p1=1/`n1'
|
||||
local p0=1/`n0'
|
||||
qui gen eff2=.
|
||||
qui replace eff2=floor(eff/`p1') if group==1
|
||||
qui replace eff2=floor(eff/`p0') if group==0
|
||||
qui replace eff=eff-eff2*(`p1'*group+`p0'*(1-group))
|
||||
qui su eff2 if group==1
|
||||
local aff1=r(sum)
|
||||
qui su eff2 if group==0
|
||||
local aff0=r(sum)
|
||||
|
||||
local unaff1=`n1'-`aff1'
|
||||
local unaff0=`n0'-`aff0'
|
||||
qui gen efftmp=eff2
|
||||
qui gsort + group - eff
|
||||
qui replace eff2=eff2+1 in 1/`unaff0'
|
||||
qui gsort - group - eff
|
||||
qui replace eff2=eff2+1 in 1/`unaff1'
|
||||
|
||||
qui drop if eff2==0
|
||||
gsort group item*
|
||||
qui expand eff2
|
||||
qui drop proba eff eff2
|
||||
}
|
||||
|
||||
qui alpha item*
|
||||
local alpha=r(alpha)
|
||||
qui gen groupc=group-.5
|
||||
if `nbmodat'==1 {
|
||||
qui gen i=_n
|
||||
|
||||
tempname diff
|
||||
matrix `diff'=`dd''
|
||||
|
||||
qui reshape long item, i(i)
|
||||
qui rename item rep
|
||||
qui rename _j item
|
||||
|
||||
qui gen offset=0
|
||||
forvalues i=1/`nbitems' {
|
||||
qui replace offset=-`diff'[1,`i'] if item==`i'
|
||||
}
|
||||
matrix est=(`gamma',`=sqrt(`var')')
|
||||
|
||||
if "`gammafix'"=="" {
|
||||
constraint 1 _cons=`=ln(`var')'
|
||||
qui xtlogit rep groupc ,nocons i(i) offset(offset) constraint(1)
|
||||
}
|
||||
else {
|
||||
qui gllamm rep groupc, nocons i(i) offset(offset) iterate(0) fam(bin) link(logit) from(est) copy
|
||||
}
|
||||
tempname b V
|
||||
}
|
||||
else {
|
||||
matrix `db'=`db''
|
||||
qui pcm item*, fixed(`db') covariates(groupc) fixedmu fixedvar(`var')
|
||||
}
|
||||
tempname b V
|
||||
matrix `b'=e(b)
|
||||
matrix `V'=e(V)
|
||||
local gammaest=`b'[1,1]
|
||||
local se=`V'[1,1]^.5
|
||||
|
||||
|
||||
di
|
||||
di
|
||||
di in gr "{hline 91}"
|
||||
di _col(60) "Estimation with the "
|
||||
di _col(50) "Cramer-Rao bound" _col(75) "classical formula"
|
||||
di in gr "{hline 91}"
|
||||
if "`gammafixed'"=="" {
|
||||
di in green "Estimated value of the group effect" _col(59) in ye %7.2f `gammaest'
|
||||
}
|
||||
di in green "Estimation of the s.e. of the group effect" _col(59) in ye %7.2f `se'
|
||||
di in green "Estimation of the variance of the group effect" _col(56) in ye %10.4f `=`se'^2'
|
||||
local power=1-normal(1.96-`gamma'/`se')+normal(-1.96-`gamma'/`se')
|
||||
local poweruni=1-normal(1.96-`gamma'/`se')
|
||||
local clpower=normal(sqrt(`n1'*`gamma'^2/((`n1'/`n0'+1)*`var'))-1.96)
|
||||
di in green "Estimation of the power" _col(60) in ye %6.4f `poweruni' _col(86) in ye %6.4f `clpower'
|
||||
local clnsn=(`n1'/`n0'+1)/((`n1'/`n0')*(`gamma'/sqrt(`var'))^2)*(1.96+invnorm(`poweruni'))^2
|
||||
di in green "Number of patients for a power of" %6.2f `=`poweruni'*100' "%" _col(59) in ye `n0' "/" `n1' _col(77) in ye %7.2f `clnsn' "/" %7.2f `=`clnsn'*`n1'/`n0''
|
||||
local ratio=(`n0'+`n1')/(`clnsn'*(1+`n1'/`n0'))
|
||||
di in green "Ratio of the number of patients" in ye %6.2f _col(68)`ratio'
|
||||
if `expectedpower'!=-1 {
|
||||
qui sampsi `=-`gamma'/2' `=`gamma'/2', sd1(`=sqrt(`var')') sd2(`=sqrt(`var')') alpha(0.05) power(`expectedpower') ratio(`=`n1'/`n0'')
|
||||
local expn_1=r(N_1)
|
||||
local expn_2=r(N_2)
|
||||
local expn2=`expn_1'*`ratio'
|
||||
di in green "Number of patients for a power of" %6.2f `=`expectedpower'*100' "%" _col(51) in ye %7.2f `expn2' "/" %7.2f `=`expn2'*`n1'/`n0'' _col(77) in ye %7.2f `expn_1' "/" %7.2f `expn_2'
|
||||
}
|
||||
di in gr "{hline 91}"
|
||||
return scalar EstGamma=`gammaest'
|
||||
return scalar CRbound=`=`se'^2'
|
||||
return scalar CRPower=`poweruni'
|
||||
return scalar ClPower=`clpower'
|
||||
return scalar ClSS=`clnsn'
|
||||
return scalar Ratio=`ratio'
|
||||
return scalar CronbachAlpha=`alpha'
|
||||
|
||||
|
||||
|
||||
capture qui use `raschpowerfile',clear
|
||||
|
||||
end
|
51
Modules/ado/personal/r/old/raschpowers.hlp
Normal file
51
Modules/ado/personal/r/old/raschpowers.hlp
Normal file
@ -0,0 +1,51 @@
|
||||
{smcl}
|
||||
{* 7july2011}{...}
|
||||
{hline}
|
||||
help for {hi:raschpower}{right:Jean-Benoit Hardouin, Myriam Blanchin}
|
||||
{hline}
|
||||
|
||||
{title:Estimation of the power of the Wald test in order to compare the means of the latent trait in two groups of individuals}
|
||||
|
||||
{p 8 14 2}{cmd:raschpower} [{cmd:,} {cmdab:n0}({it:#}) {cmdab:n1}({it:#})
|
||||
{cmdab:gamma}({it:#}) {cmdab:var}({it:#}) {cmdab:d}({it:vector})]
|
||||
|
||||
|
||||
{title:Description}
|
||||
|
||||
{p 4 8 2}{cmd:raschpower} allows estimating the power of the Wald test comparing the means of two groups of patients in the context of the Rasch model. The estimation is based on the estimation of the variance of the difference of the means based on the Cramer-Rao bound.
|
||||
|
||||
{title:Options}
|
||||
|
||||
{p 4 8 2}{cmd:n0} and {cmd:n1} indicates the numbers of individuals in the two groups (100 by default).
|
||||
|
||||
{p 4 8 2}{cmd:gamma} indicates the group effect (difference between the two means) [0.5 by default].
|
||||
|
||||
{p 4 8 2}{cmd:var} indicates the value of the variance of the latent trait [1 by default].
|
||||
|
||||
{p 4 8 2}{cmd:d} is a vector containing the difficulties of the items [one row per item, one column - (-1,-0.5,0,0.5,1)' by default].
|
||||
|
||||
{title:Example}
|
||||
|
||||
{p 4 8 2}{cmd:. raschpower}
|
||||
|
||||
{p 4 8 2}{cmd:. raschpower, n0(200) n1(200) gamma(0.4) var(1.3)}
|
||||
|
||||
{p 4 8 2}{cmd:. matrix diff=(-1.47\-0.97\-.23\-0.12\0.02\0.1)}{p_end}
|
||||
{p 4 8 2}{cmd:. raschpower, n0(127) n1(134) gamma(0.23) d(diff) var(2.58)}{p_end}
|
||||
|
||||
{title:References}
|
||||
|
||||
{p 4 8 2}Hardouin J.B., Amri S., Feddag M., S<>bille V. (2011) Towards Power And Sample Size Calculations For The Comparison Of Two Groups Of Patients With Item Response Theory Models. Accept to appear in Statistics in Medicine.
|
||||
|
||||
|
||||
{title:Author}
|
||||
|
||||
{p 4 8 2}Jean-Benoit Hardouin, PhD, assistant professor{p_end}
|
||||
{p 4 8 2}EA4275 "Biostatistics, Clinical Research and Subjective Measures in Health Sciences"{p_end}
|
||||
{p 4 8 2}University of Nantes - Faculty of Pharmaceutical Sciences{p_end}
|
||||
{p 4 8 2}1, rue Gaston Veil - BP 53508{p_end}
|
||||
{p 4 8 2}44035 Nantes Cedex 1 - FRANCE{p_end}
|
||||
{p 4 8 2}Email:
|
||||
{browse "mailto:jean-benoit.hardouin@univ-nantes.fr":jean-benoit.hardouin@univ-nantes.fr}{p_end}
|
||||
{p 4 8 2}Websites {browse "http://www.anaqol.org":AnaQol}
|
||||
and {browse "http://www.freeirt.org":FreeIRT}
|
200
Modules/ado/personal/r/old/raschtest2.ado
Normal file
200
Modules/ado/personal/r/old/raschtest2.ado
Normal file
@ -0,0 +1,200 @@
|
||||
*! version 8 25june2009
|
||||
*! Jean-Benoit Hardouin
|
||||
************************************************************************************************************
|
||||
* Raschtest: Rasch model, fit tests and graphical validation
|
||||
*
|
||||
* Historic:
|
||||
* Version 1 (2003-06-30): Jean-Benoit Hardouin
|
||||
* Version 2 (2003-07-07): Jean-Benoit Hardouin
|
||||
* Version 3 (2004-01-02): Jean-Benoit Hardouin
|
||||
* Version 4 (2004-01-21): Jean-Benoit Hardouin
|
||||
* Version 5 (2004-01-24): Jean-Benoit Hardouin
|
||||
* Version 6 (2004-02-05): Jean-Benoit Hardouin
|
||||
* Version 6.1 (2004-03-29): Jean-Benoit Hardouin
|
||||
* Version 6.2 (2004-04-06): Jean-Benoit Hardouin
|
||||
* Version 6.3 (2004-07-08) : Jean-Benoit Hardouin
|
||||
* Version 7 (2005-04-02) : Jean-Benoit Hardouin
|
||||
* Version 7.2 (2005-05-20) : Jean-Benoit Hardouin
|
||||
* Version 7.3 (2005-07-02) : Jean-Benoit Hardouin
|
||||
* Version 7.4 (2006-01-15) : Jean-Benoit Hardouin
|
||||
* Version 7.5 (2006-04-20) : Jean-Benoit Hardouin
|
||||
* Version 7.6 (2008-06-20) : Jean-Benoit Hardouin /*nold option*/
|
||||
* Version 8 (2009-06-20) : Jean-Benoit Hardouin /*DIFFICULTIES and COVARIATES options*/
|
||||
*
|
||||
* Needed modules :
|
||||
* raschtestv7jf version 8.1 (http://freeirt.free.fr)
|
||||
* gammasym version 2.2 (http://www.freeirt.org)
|
||||
* gausshermite version 1 (http://www.freeirt.org)
|
||||
* geekel2d version 4.3 (http://www.freeirt.org)
|
||||
* genscore version 1.4 (http://www.freeirt.org)
|
||||
* ghquadm (findit ghquadm)
|
||||
* gllamm version 2.3.14 (ssc describe gllamm)
|
||||
* gllapred version 2.3.7 (ssc describe gllapred)
|
||||
* elapse (ssc describe elapse)
|
||||
*
|
||||
* 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
|
||||
* FreeIRT Project : http://www.freeirt.org
|
||||
*
|
||||
* Copyright 2003-2009 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
|
||||
************************************************************************************************************/
|
||||
|
||||
|
||||
/***********************************************************************************************************
|
||||
INTRODUCTION
|
||||
***********************************************************************************************************/
|
||||
|
||||
|
||||
program define raschtest2,eclass
|
||||
syntax varlist(min=1 numeric) [if] [in] , ID(varname) [ MEANdiff DIRsave(string) FILESsave nodraw PAUse REPlace ICC INFormation SPLITtests FITgraph Method(string) group(numlist >0 ascen) AUTOGroup Test(string) q2 GENLT(string) GENSCOre(string) GENFIT(string) GRAph COMp(varname) dif(varlist) time TRace Details nold iterate(int 200) DIFFiculties(string) COVariates(string) ]
|
||||
|
||||
local nbitems:word count `varlist'
|
||||
if "`method'"=="" {
|
||||
local method "cml"
|
||||
}
|
||||
else {
|
||||
local method=lower("`method'")
|
||||
}
|
||||
if "`test'"=="" {
|
||||
local test "R"
|
||||
}
|
||||
else {
|
||||
local test=upper("`test'")
|
||||
}
|
||||
if "`dirsave'"!="" {
|
||||
local dirsavev8 "dirsave(`dirsave')"
|
||||
}
|
||||
if "`method'"!="" {
|
||||
local methodv8 "method(`method')"
|
||||
}
|
||||
if "`test'"!="" {
|
||||
local testv8 "test(`test')"
|
||||
}
|
||||
if "`group'"!="" {
|
||||
local groupv8 "group(`group')"
|
||||
}
|
||||
if "`genlt'"!="" {
|
||||
local genltv8 "genlt(`genlt')"
|
||||
}
|
||||
if "`genscore'"!="" {
|
||||
local genscorev8 "genscore(`genscore')"
|
||||
}
|
||||
if "`genfit'"!="" {
|
||||
local genfitv8 "genfit(`genfit')"
|
||||
}
|
||||
if "`comp'"!="" {
|
||||
local compv8 "comp(`comp')"
|
||||
}
|
||||
if "`dif'"!="" {
|
||||
local difv8 "dif(`dif')"
|
||||
}
|
||||
if "`iterate'"!="" {
|
||||
local iteratev8 "iterate(`iterate')"
|
||||
}
|
||||
if "`difficulties'"!="" {
|
||||
local difficultiesv8 "difficulties(`difficulties')"
|
||||
}
|
||||
if "`covariates'"!="" {
|
||||
local covariatesv8 "covariates(`covariates')"
|
||||
}
|
||||
|
||||
raschtestv7jf `varlist' `if' `in' , id(`id') `meandiff' `dirsavev8' `filessave' `nodraw' `pause' `replace' `icc' `information' `splittests' `fitgraph' `methodv8' `groupv8' `autogroup' `testv8' `q2' `genltv8' `genscorev8' `genfitv8' `graph' v8 `compv8' `difv8' `time' `trace' `details' `ld' `iteratev8' `difficultiesv8' `covariatesv8'
|
||||
|
||||
/***********************************************************************************************************
|
||||
RETURN
|
||||
************************************************************************************************************/
|
||||
|
||||
ereturn clear
|
||||
if `nbitems'>=3 {
|
||||
if "`method'"=="cml" {
|
||||
if "`test'"!="none" {
|
||||
tempname AndersenZv8
|
||||
matrix `AndersenZv8'=r(AndersenZ)
|
||||
ereturn matrix AndersenZ=`AndersenZv8'
|
||||
}
|
||||
if "`dif'"!="" {
|
||||
tempname DIFv8
|
||||
matrix `DIFv8'=r(DIF)
|
||||
ereturn matrix DIF=`DIFv8'
|
||||
}
|
||||
tempname cllv8
|
||||
scalar `cllv8'=r(cll)
|
||||
ereturn scalar cll=`cllv8'
|
||||
|
||||
}
|
||||
if "`test'"!="NONE" {
|
||||
tempname itemFitv8 globalFitv8
|
||||
matrix `itemFitv8'=r(itemFit)
|
||||
matrix `globalFitv8'=r(globalFit)
|
||||
ereturn matrix itemFit=`itemFitv8'
|
||||
ereturn matrix globalFit=`globalFitv8'
|
||||
}
|
||||
}
|
||||
|
||||
if "`method'"!="cml" {
|
||||
tempname sigmav8 sesigmav8
|
||||
local `sigmav8'=`r(sigma)'
|
||||
local `sesigmav8'=`r(sesigma)'
|
||||
ereturn scalar sigma=``sigmav8''
|
||||
ereturn scalar sesigma=``sesigmav8''
|
||||
}
|
||||
|
||||
tempname betav8 Varbetav8 thetav8 Varthetav8 llv8 AICv8
|
||||
matrix `betav8'=r(beta)
|
||||
matrix `Varbetav8'=r(Varbeta)
|
||||
ereturn matrix beta=`betav8'
|
||||
ereturn matrix Varbeta=`Varbetav8'
|
||||
matrix `thetav8'=r(theta)
|
||||
matrix `Varthetav8'=r(Vartheta)
|
||||
ereturn matrix theta=`thetav8'
|
||||
ereturn matrix Vartheta=`Varthetav8'
|
||||
scalar `llv8'=`r(ll)'
|
||||
scalar `AICv8'=`r(AIC)'
|
||||
ereturn scalar ll=`llv8'
|
||||
ereturn scalar AIC=`AICv8'
|
||||
ereturn scalar Zcomp=r(Zcomp)
|
||||
ereturn scalar pZcomp=r(pZcomp)
|
||||
|
||||
|
||||
if "`method'"=="mml" {
|
||||
local psi=r(PSI)
|
||||
local psiadj=r(PSIadj)
|
||||
ereturn scalar PSI=`psi'
|
||||
ereturn scalar PSIadj=`psiadj'
|
||||
}
|
||||
if "`covariates'"!="" {
|
||||
tempname betacovariates Vbetacovariates zcovariates pcovariates
|
||||
matrix `betacovariates'=r(betacovariates)
|
||||
matrix `Vbetacovariates'=r(Vbetacovariates)
|
||||
matrix `zcovariates'=r(zcovariates)
|
||||
matrix `pcovariates'=r(pcovariates)
|
||||
|
||||
ereturn matrix betacovariates=`betacovariates'
|
||||
ereturn matrix Vbetacovariates=`Vbetacovariates'
|
||||
ereturn matrix zcovariates=`zcovariates'
|
||||
ereturn matrix pcovariates=`pcovariates'
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return clear
|
||||
|
||||
end
|
200
Modules/ado/personal/r/old/raschtest82.ado
Normal file
200
Modules/ado/personal/r/old/raschtest82.ado
Normal file
@ -0,0 +1,200 @@
|
||||
*! version 8 25june2009
|
||||
*! Jean-Benoit Hardouin
|
||||
************************************************************************************************************
|
||||
* Raschtest: Rasch model, fit tests and graphical validation
|
||||
*
|
||||
* Historic:
|
||||
* Version 1 (2003-06-30): Jean-Benoit Hardouin
|
||||
* Version 2 (2003-07-07): Jean-Benoit Hardouin
|
||||
* Version 3 (2004-01-02): Jean-Benoit Hardouin
|
||||
* Version 4 (2004-01-21): Jean-Benoit Hardouin
|
||||
* Version 5 (2004-01-24): Jean-Benoit Hardouin
|
||||
* Version 6 (2004-02-05): Jean-Benoit Hardouin
|
||||
* Version 6.1 (2004-03-29): Jean-Benoit Hardouin
|
||||
* Version 6.2 (2004-04-06): Jean-Benoit Hardouin
|
||||
* Version 6.3 (2004-07-08) : Jean-Benoit Hardouin
|
||||
* Version 7 (2005-04-02) : Jean-Benoit Hardouin
|
||||
* Version 7.2 (2005-05-20) : Jean-Benoit Hardouin
|
||||
* Version 7.3 (2005-07-02) : Jean-Benoit Hardouin
|
||||
* Version 7.4 (2006-01-15) : Jean-Benoit Hardouin
|
||||
* Version 7.5 (2006-04-20) : Jean-Benoit Hardouin
|
||||
* Version 7.6 (2008-06-20) : Jean-Benoit Hardouin /*nold option*/
|
||||
* Version 8 (2009-06-20) : Jean-Benoit Hardouin /*DIFFICULTIES and COVARIATES options*/
|
||||
*
|
||||
* Needed modules :
|
||||
* raschtestv7 version 8.1 (http://freeirt.free.fr)
|
||||
* gammasym version 2.2 (http://www.freeirt.org)
|
||||
* gausshermite version 1 (http://www.freeirt.org)
|
||||
* geekel2d version 4.3 (http://www.freeirt.org)
|
||||
* genscore version 1.4 (http://www.freeirt.org)
|
||||
* ghquadm (findit ghquadm)
|
||||
* gllamm version 2.3.14 (ssc describe gllamm)
|
||||
* gllapred version 2.3.7 (ssc describe gllapred)
|
||||
* elapse (ssc describe elapse)
|
||||
*
|
||||
* 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
|
||||
* FreeIRT Project : http://www.freeirt.org
|
||||
*
|
||||
* Copyright 2003-2009 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
|
||||
************************************************************************************************************/
|
||||
|
||||
|
||||
/***********************************************************************************************************
|
||||
INTRODUCTION
|
||||
***********************************************************************************************************/
|
||||
|
||||
|
||||
program define raschtest,eclass
|
||||
syntax varlist(min=1 numeric) [if] [in] , ID(varname) [ MEANdiff DIRsave(string) FILESsave nodraw PAUse REPlace ICC INFormation SPLITtests FITgraph Method(string) group(numlist >0 ascen) AUTOGroup Test(string) q2 GENLT(string) GENSCOre(string) GENFIT(string) GRAph COMp(varname) dif(varlist) time TRace Details nold iterate(int 200) DIFFiculties(string) COVariates(string) ]
|
||||
|
||||
local nbitems:word count `varlist'
|
||||
if "`method'"=="" {
|
||||
local method "cml"
|
||||
}
|
||||
else {
|
||||
local method=lower("`method'")
|
||||
}
|
||||
if "`test'"=="" {
|
||||
local test "R"
|
||||
}
|
||||
else {
|
||||
local test=upper("`test'")
|
||||
}
|
||||
if "`dirsave'"!="" {
|
||||
local dirsavev8 "dirsave(`dirsave')"
|
||||
}
|
||||
if "`method'"!="" {
|
||||
local methodv8 "method(`method')"
|
||||
}
|
||||
if "`test'"!="" {
|
||||
local testv8 "test(`test')"
|
||||
}
|
||||
if "`group'"!="" {
|
||||
local groupv8 "group(`group')"
|
||||
}
|
||||
if "`genlt'"!="" {
|
||||
local genltv8 "genlt(`genlt')"
|
||||
}
|
||||
if "`genscore'"!="" {
|
||||
local genscorev8 "genscore(`genscore')"
|
||||
}
|
||||
if "`genfit'"!="" {
|
||||
local genfitv8 "genfit(`genfit')"
|
||||
}
|
||||
if "`comp'"!="" {
|
||||
local compv8 "comp(`comp')"
|
||||
}
|
||||
if "`dif'"!="" {
|
||||
local difv8 "dif(`dif')"
|
||||
}
|
||||
if "`iterate'"!="" {
|
||||
local iteratev8 "iterate(`iterate')"
|
||||
}
|
||||
if "`difficulties'"!="" {
|
||||
local difficultiesv8 "difficulties(`difficulties')"
|
||||
}
|
||||
if "`covariates'"!="" {
|
||||
local covariatesv8 "covariates(`covariates')"
|
||||
}
|
||||
|
||||
raschtestv7 `varlist' `if' `in' , id(`id') `meandiff' `dirsavev8' `filessave' `nodraw' `pause' `replace' `icc' `information' `splittests' `fitgraph' `methodv8' `groupv8' `autogroup' `testv8' `q2' `genltv8' `genscorev8' `genfitv8' `graph' v8 `compv8' `difv8' `time' `trace' `details' `ld' `iteratev8' `difficultiesv8' `covariatesv8'
|
||||
|
||||
/***********************************************************************************************************
|
||||
RETURN
|
||||
************************************************************************************************************/
|
||||
|
||||
ereturn clear
|
||||
if `nbitems'>=3 {
|
||||
if "`method'"=="cml" {
|
||||
if "`test'"!="none" {
|
||||
tempname AndersenZv8
|
||||
matrix `AndersenZv8'=r(AndersenZ)
|
||||
ereturn matrix AndersenZ=`AndersenZv8'
|
||||
}
|
||||
if "`dif'"!="" {
|
||||
tempname DIFv8
|
||||
matrix `DIFv8'=r(DIF)
|
||||
ereturn matrix DIF=`DIFv8'
|
||||
}
|
||||
tempname cllv8
|
||||
scalar `cllv8'=r(cll)
|
||||
ereturn scalar cll=`cllv8'
|
||||
|
||||
}
|
||||
if "`test'"!="NONE" {
|
||||
tempname itemFitv8 globalFitv8
|
||||
matrix `itemFitv8'=r(itemFit)
|
||||
matrix `globalFitv8'=r(globalFit)
|
||||
ereturn matrix itemFit=`itemFitv8'
|
||||
ereturn matrix globalFit=`globalFitv8'
|
||||
}
|
||||
}
|
||||
|
||||
if "`method'"!="cml" {
|
||||
tempname sigmav8 sesigmav8
|
||||
local `sigmav8'=`r(sigma)'
|
||||
local `sesigmav8'=`r(sesigma)'
|
||||
ereturn scalar sigma=``sigmav8''
|
||||
ereturn scalar sesigma=``sesigmav8''
|
||||
}
|
||||
|
||||
tempname betav8 Varbetav8 thetav8 Varthetav8 llv8 AICv8
|
||||
matrix `betav8'=r(beta)
|
||||
matrix `Varbetav8'=r(Varbeta)
|
||||
ereturn matrix beta=`betav8'
|
||||
ereturn matrix Varbeta=`Varbetav8'
|
||||
matrix `thetav8'=r(theta)
|
||||
matrix `Varthetav8'=r(Vartheta)
|
||||
ereturn matrix theta=`thetav8'
|
||||
ereturn matrix Vartheta=`Varthetav8'
|
||||
scalar `llv8'=`r(ll)'
|
||||
scalar `AICv8'=`r(AIC)'
|
||||
ereturn scalar ll=`llv8'
|
||||
ereturn scalar AIC=`AICv8'
|
||||
ereturn scalar Zcomp=r(Zcomp)
|
||||
ereturn scalar pZcomp=r(pZcomp)
|
||||
|
||||
|
||||
if "`method'"=="mml" {
|
||||
local psi=r(PSI)
|
||||
local psiadj=r(PSIadj)
|
||||
ereturn scalar PSI=`psi'
|
||||
ereturn scalar PSIadj=`psiadj'
|
||||
}
|
||||
if "`covariates'"!="" {
|
||||
tempname betacovariates Vbetacovariates zcovariates pcovariates
|
||||
matrix `betacovariates'=r(betacovariates)
|
||||
matrix `Vbetacovariates'=r(Vbetacovariates)
|
||||
matrix `zcovariates'=r(zcovariates)
|
||||
matrix `pcovariates'=r(pcovariates)
|
||||
|
||||
ereturn matrix betacovariates=`betacovariates'
|
||||
ereturn matrix Vbetacovariates=`Vbetacovariates'
|
||||
ereturn matrix zcovariates=`zcovariates'
|
||||
ereturn matrix pcovariates=`pcovariates'
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return clear
|
||||
|
||||
end
|
204
Modules/ado/personal/r/old/raschtest83.ado
Normal file
204
Modules/ado/personal/r/old/raschtest83.ado
Normal file
@ -0,0 +1,204 @@
|
||||
*! version 8.3 15june2010
|
||||
*! Jean-Benoit Hardouin
|
||||
************************************************************************************************************
|
||||
* Raschtest: Rasch model, fit tests and graphical validation
|
||||
*
|
||||
* Historic:
|
||||
* Version 1 (2003-06-30): Jean-Benoit Hardouin
|
||||
* Version 2 (2003-07-07): Jean-Benoit Hardouin
|
||||
* Version 3 (2004-01-02): Jean-Benoit Hardouin
|
||||
* Version 4 (2004-01-21): Jean-Benoit Hardouin
|
||||
* Version 5 (2004-01-24): Jean-Benoit Hardouin
|
||||
* Version 6 (2004-02-05): Jean-Benoit Hardouin
|
||||
* Version 6.1 (2004-03-29): Jean-Benoit Hardouin
|
||||
* Version 6.2 (2004-04-06): Jean-Benoit Hardouin
|
||||
* Version 6.3 (2004-07-08) : Jean-Benoit Hardouin
|
||||
* Version 7 (2005-04-02) : Jean-Benoit Hardouin
|
||||
* Version 7.2 (2005-05-20) : Jean-Benoit Hardouin
|
||||
* Version 7.3 (2005-07-02) : Jean-Benoit Hardouin
|
||||
* Version 7.4 (2006-01-15) : Jean-Benoit Hardouin
|
||||
* Version 7.5 (2006-04-20) : Jean-Benoit Hardouin
|
||||
* Version 7.6 (2008-06-20) : Jean-Benoit Hardouin /*nold option*/
|
||||
* Version 8 (2009-06-20) : Jean-Benoit Hardouin /*DIFFICULTIES and COVARIATES options*/
|
||||
* Version 8.3 (2009-06-20) : Jean-Benoit Hardouin /*GENRES option*/
|
||||
*
|
||||
* Needed modules :
|
||||
* raschtestv7 version 8.1 (http://freeirt.free.fr)
|
||||
* gammasym version 2.2 (http://www.freeirt.org)
|
||||
* gausshermite version 1 (http://www.freeirt.org)
|
||||
* geekel2d version 4.3 (http://www.freeirt.org)
|
||||
* genscore version 1.4 (http://www.freeirt.org)
|
||||
* ghquadm (findit ghquadm)
|
||||
* gllamm version 2.3.14 (ssc describe gllamm)
|
||||
* gllapred version 2.3.7 (ssc describe gllapred)
|
||||
* elapse (ssc describe elapse)
|
||||
*
|
||||
* 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
|
||||
* FreeIRT Project : http://www.freeirt.org
|
||||
*
|
||||
* Copyright 2003-2009 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
|
||||
************************************************************************************************************/
|
||||
|
||||
|
||||
/***********************************************************************************************************
|
||||
INTRODUCTION
|
||||
***********************************************************************************************************/
|
||||
|
||||
|
||||
program define raschtest,eclass
|
||||
syntax varlist(min=1 numeric) [if] [in] , ID(varname) [ MEANdiff DIRsave(string) FILESsave nodraw PAUse REPlace ICC INFormation SPLITtests FITgraph Method(string) group(numlist >0 ascen) AUTOGroup Test(string) q2 GENLT(string) GENSCOre(string) GENFIT(string) GRAph COMp(varname) dif(varlist) time TRace Details nold iterate(int 200) DIFFiculties(string) COVariates(string) GENRes(string)]
|
||||
|
||||
local nbitems:word count `varlist'
|
||||
if "`method'"=="" {
|
||||
local method "cml"
|
||||
}
|
||||
else {
|
||||
local method=lower("`method'")
|
||||
}
|
||||
if "`test'"=="" {
|
||||
local test "R"
|
||||
}
|
||||
else {
|
||||
local test=upper("`test'")
|
||||
}
|
||||
if "`dirsave'"!="" {
|
||||
local dirsavev8 "dirsave(`dirsave')"
|
||||
}
|
||||
if "`method'"!="" {
|
||||
local methodv8 "method(`method')"
|
||||
}
|
||||
if "`test'"!="" {
|
||||
local testv8 "test(`test')"
|
||||
}
|
||||
if "`group'"!="" {
|
||||
local groupv8 "group(`group')"
|
||||
}
|
||||
if "`genlt'"!="" {
|
||||
local genltv8 "genlt(`genlt')"
|
||||
}
|
||||
if "`genscore'"!="" {
|
||||
local genscorev8 "genscore(`genscore')"
|
||||
}
|
||||
if "`genres'"!="" {
|
||||
local gensresv8 "genres(`genres')"
|
||||
}
|
||||
if "`genfit'"!="" {
|
||||
local genfitv8 "genfit(`genfit')"
|
||||
}
|
||||
if "`comp'"!="" {
|
||||
local compv8 "comp(`comp')"
|
||||
}
|
||||
if "`dif'"!="" {
|
||||
local difv8 "dif(`dif')"
|
||||
}
|
||||
if "`iterate'"!="" {
|
||||
local iteratev8 "iterate(`iterate')"
|
||||
}
|
||||
if "`difficulties'"!="" {
|
||||
local difficultiesv8 "difficulties(`difficulties')"
|
||||
}
|
||||
if "`covariates'"!="" {
|
||||
local covariatesv8 "covariates(`covariates')"
|
||||
}
|
||||
|
||||
raschtestv7 `varlist' `if' `in' , id(`id') `meandiff' `dirsavev8' `filessave' `nodraw' `pause' `replace' `icc' `information' `splittests' `fitgraph' `methodv8' `groupv8' `autogroup' `testv8' `q2' `genltv8' `genscorev8' `genresv8' `genfitv8' `graph' v8 `compv8' `difv8' `time' `trace' `details' `ld' `iteratev8' `difficultiesv8' `covariatesv8'
|
||||
|
||||
/***********************************************************************************************************
|
||||
RETURN
|
||||
************************************************************************************************************/
|
||||
|
||||
ereturn clear
|
||||
if `nbitems'>=3 {
|
||||
if "`method'"=="cml" {
|
||||
if "`test'"!="none" {
|
||||
tempname AndersenZv8
|
||||
matrix `AndersenZv8'=r(AndersenZ)
|
||||
ereturn matrix AndersenZ=`AndersenZv8'
|
||||
}
|
||||
if "`dif'"!="" {
|
||||
tempname DIFv8
|
||||
matrix `DIFv8'=r(DIF)
|
||||
ereturn matrix DIF=`DIFv8'
|
||||
}
|
||||
tempname cllv8
|
||||
scalar `cllv8'=r(cll)
|
||||
ereturn scalar cll=`cllv8'
|
||||
|
||||
}
|
||||
if "`test'"!="NONE" {
|
||||
tempname itemFitv8 globalFitv8
|
||||
matrix `itemFitv8'=r(itemFit)
|
||||
matrix `globalFitv8'=r(globalFit)
|
||||
ereturn matrix itemFit=`itemFitv8'
|
||||
ereturn matrix globalFit=`globalFitv8'
|
||||
}
|
||||
}
|
||||
|
||||
if "`method'"!="cml" {
|
||||
tempname sigmav8 sesigmav8
|
||||
local `sigmav8'=`r(sigma)'
|
||||
local `sesigmav8'=`r(sesigma)'
|
||||
ereturn scalar sigma=``sigmav8''
|
||||
ereturn scalar sesigma=``sesigmav8''
|
||||
}
|
||||
|
||||
tempname betav8 Varbetav8 thetav8 Varthetav8 llv8 AICv8
|
||||
matrix `betav8'=r(beta)
|
||||
matrix `Varbetav8'=r(Varbeta)
|
||||
ereturn matrix beta=`betav8'
|
||||
ereturn matrix Varbeta=`Varbetav8'
|
||||
matrix `thetav8'=r(theta)
|
||||
matrix `Varthetav8'=r(Vartheta)
|
||||
ereturn matrix theta=`thetav8'
|
||||
ereturn matrix Vartheta=`Varthetav8'
|
||||
scalar `llv8'=`r(ll)'
|
||||
scalar `AICv8'=`r(AIC)'
|
||||
ereturn scalar ll=`llv8'
|
||||
ereturn scalar AIC=`AICv8'
|
||||
ereturn scalar Zcomp=r(Zcomp)
|
||||
ereturn scalar pZcomp=r(pZcomp)
|
||||
|
||||
|
||||
if "`method'"=="mml" {
|
||||
local psi=r(PSI)
|
||||
local psiadj=r(PSIadj)
|
||||
ereturn scalar PSI=`psi'
|
||||
ereturn scalar PSIadj=`psiadj'
|
||||
}
|
||||
if "`covariates'"!="" {
|
||||
tempname betacovariates Vbetacovariates zcovariates pcovariates
|
||||
matrix `betacovariates'=r(betacovariates)
|
||||
matrix `Vbetacovariates'=r(Vbetacovariates)
|
||||
matrix `zcovariates'=r(zcovariates)
|
||||
matrix `pcovariates'=r(pcovariates)
|
||||
|
||||
ereturn matrix betacovariates=`betacovariates'
|
||||
ereturn matrix Vbetacovariates=`Vbetacovariates'
|
||||
ereturn matrix zcovariates=`zcovariates'
|
||||
ereturn matrix pcovariates=`pcovariates'
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return clear
|
||||
|
||||
end
|
1743
Modules/ado/personal/r/old/raschtestv7732.ado
Normal file
1743
Modules/ado/personal/r/old/raschtestv7732.ado
Normal file
File diff suppressed because it is too large
Load Diff
1809
Modules/ado/personal/r/old/raschtestv7761.ado
Normal file
1809
Modules/ado/personal/r/old/raschtestv7761.ado
Normal file
File diff suppressed because it is too large
Load Diff
1829
Modules/ado/personal/r/old/raschtestv7762.ado
Normal file
1829
Modules/ado/personal/r/old/raschtestv7762.ado
Normal file
File diff suppressed because it is too large
Load Diff
1890
Modules/ado/personal/r/old/raschtestv78 avant COVARIABLES.ado
Normal file
1890
Modules/ado/personal/r/old/raschtestv78 avant COVARIABLES.ado
Normal file
File diff suppressed because it is too large
Load Diff
2157
Modules/ado/personal/r/old/raschtestv782.ado
Normal file
2157
Modules/ado/personal/r/old/raschtestv782.ado
Normal file
File diff suppressed because it is too large
Load Diff
2146
Modules/ado/personal/r/old/raschtestv785.ado
Normal file
2146
Modules/ado/personal/r/old/raschtestv785.ado
Normal file
File diff suppressed because it is too large
Load Diff
2239
Modules/ado/personal/r/old/raschtestv7jf.ado
Normal file
2239
Modules/ado/personal/r/old/raschtestv7jf.ado
Normal file
File diff suppressed because it is too large
Load Diff
584
Modules/ado/personal/r/old/rsoort.do
Normal file
584
Modules/ado/personal/r/old/rsoort.do
Normal file
@ -0,0 +1,584 @@
|
||||
*! version 1 25februar2013
|
||||
*! Jean-Benoit Hardouin
|
||||
************************************************************************************************************
|
||||
* rsoort: Response Shift detection with the Oort procedure
|
||||
*
|
||||
* Historic:
|
||||
* Version 1 (2013-02-25): Jean-Benoit Hardouin
|
||||
*
|
||||
*
|
||||
* Jean-benoit Hardouin - Department of Biomathematics and Biostatistics - University of Nantes - France
|
||||
* EA 4275-SPHERE "bioStatistics, Pharmacoepidemiology and Human sciEnces Research tEam"
|
||||
* jean-benoit.hardouin@univ-nantes.fr
|
||||
*
|
||||
* Copyright 2013 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
|
||||
************************************************************************************************************/
|
||||
|
||||
|
||||
/***********************************************************************************************************
|
||||
INTRODUCTION
|
||||
***********************************************************************************************************/
|
||||
|
||||
|
||||
program define rsoort,eclass
|
||||
syntax varlist(min=1 numeric) [if] [in] [,METHod(string) UNIFormrecalibration(varlist) NONUNIFormrecalibration(varlist) REPriorisation(varlist) noSearch]
|
||||
|
||||
tokenize `varlist'
|
||||
local nbitems:word count `varlist'
|
||||
local mod=mod(`nbitems',2)
|
||||
if `mod'!=0 {
|
||||
di in red "You must enter an even number of items : the first half of the items represents the items in time 1 and the second half the items in time 2"
|
||||
error
|
||||
}
|
||||
|
||||
if "`method'"=="" {
|
||||
local method "ml"
|
||||
}
|
||||
local nbitems=`nbitems'/2
|
||||
|
||||
di _col(20) "{hline 30}"
|
||||
di _col(20) in gr "Time 1" _col(40) "Time 2"
|
||||
di _col(20) "{hline 30}"
|
||||
forvalues i=1/`nbitems' {
|
||||
di in ye _col(20) "``i''" _col(40) "``=`i'+`nbitems'''"
|
||||
}
|
||||
di _col(20) "{hline 30}"
|
||||
|
||||
|
||||
/**************************************************************************************************************
|
||||
Model 1
|
||||
***************************************************************************************************************/
|
||||
|
||||
qui sem (T1->`1'-``nbitems'')(T2->``=`nbitems'+1''-``=`nbitems'*2''),var(T1@1) var(T2@1) means(T1@0) means(T2@0) method(`method')
|
||||
qui estat gof, stat(all)
|
||||
local tli1=r(tli)
|
||||
local cfi1=r(cfi)
|
||||
local srmr1=r(srmr)
|
||||
local rmsea1=r(rmsea)
|
||||
local ubrmsea1=r(ub90_rmsea)
|
||||
local lbrmsea1=r(lb90_rmsea)
|
||||
local chi21=r(chi2_ms)
|
||||
local df1=r(df_ms)
|
||||
local dfc1=6*`nbitems'+1
|
||||
local p1=r(p_ms)
|
||||
*di
|
||||
*di in green " ***********************************Model 1********************************************"
|
||||
*di in gr _col(14) "chi2" _col(22) "df" _col(35) "p" _col(41) "rmsea" _col(51) "IC90%(RMSEA)" _col(72) "SRMR" _col(83) "CFI" _col(93) "TLI"
|
||||
*di in ye _col(10) %8.2f `chi21' _col(20) %4.0f `dfc1' _col(30) %6.4f `p1' _col(40) %6.4f `rmsea1' _col(50) %6.4f `lbrmsea1' "-" %6.4f `ubrmsea1' _col(70) %6.4f `srmr1' _col(80) %6.2f `cfi1' _col(90) %6.2f `tli1'
|
||||
|
||||
/**************************************************************************************************************
|
||||
Model 2
|
||||
***************************************************************************************************************/
|
||||
|
||||
local sem
|
||||
local var
|
||||
forvalues i=1/`nbitems' {
|
||||
local sem`i' "(T1@load`i' _cons@int`i'->``i'') (T2@load`i' _cons@int`i'->``=`i'+`nbitems''')"
|
||||
local var`i' "var(e.``i''@var`i') var(e.``=`i'+`nbitems'''@var`i')"
|
||||
local sem `sem' `sem`i''
|
||||
local var `var' `var`i''
|
||||
}
|
||||
|
||||
qui sem `sem',var(T1@1) var(T2) means(T1@0) means(T2) `var' iterate(100) method(`method')
|
||||
tempname b V
|
||||
matrix `b'=e(b)
|
||||
matrix `V'=e(V)
|
||||
local truechange2=`b'[1,`=`nbitems'*4+1']
|
||||
local Vtruechange2=`V'[`=`nbitems'*4+1',`=`nbitems'*4+1']
|
||||
qui estat gof, stat(all)
|
||||
local tli2=r(tli)
|
||||
local cfi2=r(cfi)
|
||||
local srmr2=r(srmr)
|
||||
local rmsea2=r(rmsea)
|
||||
local ubrmsea2=r(ub90_rmsea)
|
||||
local lbrmsea2=r(lb90_rmsea)
|
||||
local chi22=r(chi2_ms)
|
||||
local df2=r(df_ms)
|
||||
local dfc2=3*`nbitems'+3
|
||||
local p2=r(p_ms)
|
||||
|
||||
local chi221=abs(`chi21'-`chi22')
|
||||
local df21=`df2'-`df1'
|
||||
local p21=1-chi2(`df21',`chi221')
|
||||
|
||||
|
||||
di "{hline 105}"
|
||||
di in gr _col(39) "Test of global Response-Shift " _col(79) "Comparison with model 1"
|
||||
di in gr "Models" _col(18) "Chi-square" _col(39) "Chi-square" _col(54) "df" _col(59) "p-value" _col(79) "Chi-square" _col(94) "df" _col(99) "p-value"
|
||||
di "{hline 105}"
|
||||
di in gr "Model 1" _col(20) %8.2f in ye `chi21'
|
||||
di in gr "Model 2" _col(20) %8.2f in ye `chi22' _col(40) %8.2f `=abs(`chi22'-`chi21')' _col(50) %6.0f `df21' %6.4f _col(60) `=1-chi2(`df21',abs(`chi22'-`chi21'))' _col(82) %8.2f `=`=abs(`chi22'-`chi21')'' _col(90) %6.0f `df21' _col(100) %6.4f `=1-chi2(`df21',abs(`chi22'-`chi21'))'
|
||||
di "{hline 105}"
|
||||
|
||||
|
||||
/**************************************************************************************************************
|
||||
Model 3
|
||||
***************************************************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************************************************
|
||||
Model 3 / Non uniform recalibration
|
||||
***************************************************************************************************************/
|
||||
|
||||
tempname RS RSprec
|
||||
qui matrix `RS'=J(`nbitems',3,0)
|
||||
qui matrix `RSprec'=J(`nbitems',3,0)
|
||||
local df3=`dfc2'
|
||||
|
||||
*set trace on
|
||||
|
||||
|
||||
forvalues i=1/`nbitems' {
|
||||
local nbUR:word count `uniformrecalibration'
|
||||
forvalues j=1/`nbUR' {
|
||||
local itemj: word `j' of `uniformrecalibration'
|
||||
if "``i''"=="`itemj'" {
|
||||
matrix `RS'[`i',2]=1
|
||||
}
|
||||
}
|
||||
local nbNUR:word count `nonuniformrecalibration'
|
||||
forvalues j=1/`nbNUR' {
|
||||
local itemj: word `j' of `nonuniformrecalibration'
|
||||
if "``i''"=="`itemj'" {
|
||||
matrix `RS'[`i',1]=1
|
||||
}
|
||||
}
|
||||
local nbR:word count `repriorisation'
|
||||
forvalues j=1/`nbR' {
|
||||
local itemj: word `j' of `repriorisation'
|
||||
if "``i''"=="`itemj'" {
|
||||
matrix `RS'[`i',3]=1
|
||||
}
|
||||
}
|
||||
}
|
||||
matrix list `RS'
|
||||
|
||||
if "`search'"=="" {
|
||||
|
||||
di
|
||||
di "{hline 105}"
|
||||
di in green _col(50) "Model 3"
|
||||
di "{hline 105}"
|
||||
di
|
||||
di in white _col(10) "Non uniform Recalibration"
|
||||
|
||||
local continue=1
|
||||
forvalues i=1/`nbitems' {
|
||||
local sem`i' "(T1@load`i' _cons@int`i'->``i'') (T2@load`i' _cons@int`i'->``=`i'+`nbitems''')"
|
||||
local var`i' "var(e.``i''@var`i') var(e.``=`i'+`nbitems'''@var`i')"
|
||||
local semrecU`i' "(T1@load`i' _cons->``i'') (T2@load`i' _cons->``=`i'+`nbitems''')"
|
||||
local semrep`i' "(T1 _cons@int`i'->``i'') (T2 _cons@int`i'->``=`i'+`nbitems''')"
|
||||
local varrecNU`i' "var(e.``i'') var(e.``=`i'+`nbitems''')"
|
||||
}
|
||||
local prec_chi2=`chi22'
|
||||
local testNU_varchi2=0
|
||||
local testNU_p=1
|
||||
di "{hline 105}"
|
||||
di in gr _col(39) "Comparison with previous model" _col(79) "Comparison with model 1"
|
||||
di in gr "Items" _col(18) "Chi-square" _col(39) "Chi-square" _col(54) "df" _col(59) "p-value" _col(79) "Chi-square" _col(94) "df" _col(99) "p-value"
|
||||
di "{hline 105}"
|
||||
|
||||
|
||||
while (`continue') {
|
||||
local cpt=0
|
||||
local testNU_varchi2_temp=0
|
||||
local testNU_p_temp=0
|
||||
local testNU_item_temp=0
|
||||
local chi2encours_temp=-1
|
||||
local continue=0
|
||||
local sem
|
||||
local var
|
||||
forvalues j=1/`nbitems' {
|
||||
local sem
|
||||
local var
|
||||
local already=0
|
||||
forvalues i=1/`nbitems' {
|
||||
if `RS'[`i',1]==0&`i'!=`j' {
|
||||
local sem `sem' `sem`i''
|
||||
local var `var' `var`i''
|
||||
}
|
||||
if `RS'[`i',1]==1&`i'!=`j' {
|
||||
local sem `sem' `sem`i''
|
||||
local var `var' `varrecNU`i''
|
||||
}
|
||||
else if `i'==`j'&`RS'[`j',1]==0 {
|
||||
local sem `sem' `sem`i''
|
||||
local var `var' `varrecNU`i''
|
||||
}
|
||||
else if `i'==`j'&`RS'[`j',1]==1 {
|
||||
local sem `sem' `sem`i''
|
||||
local var `var' `varrecNU`i''
|
||||
local already=1
|
||||
}
|
||||
}
|
||||
if (`already'!=1) {
|
||||
qui sem `sem',var(T1@1) var(T2) means(T1@0) means(T2) `var' iterate(100) method(`method')
|
||||
qui estat gof
|
||||
local chi2encours=r(chi2_ms)
|
||||
if (abs(`chi2encours'-`prec_chi2')>invchi2(1,0.95)&abs(`chi2encours'-`prec_chi2')>`testNU_varchi2_temp') {
|
||||
local continue=1
|
||||
local testNU_varchi2_temp =abs(`chi2encours'-`prec_chi2' )
|
||||
local testNU_p_temp =1-chi2(1,`testNU_varchi2_temp')
|
||||
local testNU_item_temp=`j'
|
||||
local chi2encours_tmp=`chi2encours'
|
||||
local tmp=`chi2encours'
|
||||
}
|
||||
di in gr "``j''" _col(20) %8.2f in ye `chi2encours' _col(40) %8.2f `=abs(`chi2encours'-`prec_chi2' )' _col(55) "1" %6.4f _col(60) `=1-chi2(1,abs(`chi2encours'-`prec_chi2' ))' _col(82) %8.2f `=abs(`chi2encours'-`chi21')' _col(90) %6.0f `=abs(`df3'+1-`dfc1')' _col(100) %6.4f `=1-chi2(abs(`df3'+1-`dfc1'),abs(`chi2encours'-`chi21'))'
|
||||
local ++cpt
|
||||
}
|
||||
}
|
||||
if (`testNU_item_temp'!=0) {
|
||||
matrix `RS'[`testNU_item_temp',1]=1
|
||||
local ++df3
|
||||
local testNU_varchi2=`testNU_varchi2_temp'
|
||||
local testNU_p=`testNU_p_temp'
|
||||
local testNU_item_temp=0
|
||||
local prec_chi2=`tmp'
|
||||
}
|
||||
if (`cpt'!=0) {
|
||||
di "{hline 105}"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**************************************************************************************************************
|
||||
Model 3 / Uniform recalibration
|
||||
***************************************************************************************************************/
|
||||
|
||||
di
|
||||
di in white _col(10) "Uniform Recalibration"
|
||||
|
||||
local continue=1
|
||||
local var
|
||||
forvalues i=1/`nbitems' {
|
||||
local sem`i' "(T1@load`i' _cons@int`i'->``i'') (T2@load`i' _cons@int`i'->``=`i'+`nbitems''')"
|
||||
local semrecU`i' "(T1@load`i' _cons->``i'') (T2@load`i' _cons->``=`i'+`nbitems''')"
|
||||
local semrep`i' "(T1 _cons@int`i'->``i'') (T2 _cons@int`i'->``=`i'+`nbitems''')"
|
||||
local var`i' "var(e.``i''@var`i') var(e.``=`i'+`nbitems'''@var`i')"
|
||||
local varrecNU`i' "var(e.``i'') var(e.``=`i'+`nbitems''')"
|
||||
if `RS'[`i',1]==1 {
|
||||
local var "`var' `varrecNU`i''"
|
||||
}
|
||||
if `RS'[`i',1]==0 {
|
||||
local var "`var' `var`i''"
|
||||
}
|
||||
}
|
||||
local testU_varchi2=0
|
||||
local testU_p=1
|
||||
di "{hline 105}"
|
||||
di in gr _col(39) "Comparison with previous model" _col(79) "Comparison with model 1"
|
||||
di in gr "Items" _col(18) "Chi-square" _col(39) "Chi-square" _col(54) "df" _col(59) "p-value" _col(79) "Chi-square" _col(94) "df" _col(99) "p-value"
|
||||
di "{hline 105}"
|
||||
|
||||
while (`continue') {
|
||||
local cpt=0
|
||||
local testU_varchi2_temp=0
|
||||
local testU_p_temp=0
|
||||
local testU_item_temp=0
|
||||
local chi2encours_temp=-1
|
||||
local continue=0
|
||||
local sem
|
||||
forvalues j=1/`nbitems' {
|
||||
local sem
|
||||
local already=0
|
||||
forvalues i=1/`nbitems' {
|
||||
if `RS'[`i',2]==0&`i'!=`j' {
|
||||
local sem `sem' `sem`i''
|
||||
}
|
||||
if `RS'[`i',2]==1&`i'!=`j' {
|
||||
local sem `sem' `semrecU`i''
|
||||
}
|
||||
else if `i'==`j'&`RS'[`j',2]==0 {
|
||||
local sem `sem' `semrecU`i''
|
||||
}
|
||||
else if `i'==`j'&`RS'[`j',2]==1 {
|
||||
local sem `sem' `semrecU`i''
|
||||
local already=1
|
||||
}
|
||||
}
|
||||
if (`already'!=1) {
|
||||
qui sem `sem',var(T1@1) var(T2) means(T1@0) means(T2) `var' iterate(100) method(`method')
|
||||
qui estat gof
|
||||
local chi2encours=r(chi2_ms)
|
||||
if (abs(`chi2encours'-`prec_chi2')>invchi2(1,0.95)&abs(`chi2encours'-`prec_chi2')>`testU_varchi2_temp') {
|
||||
local continue=1
|
||||
local testU_varchi2_temp =abs(`chi2encours'-`prec_chi2' )
|
||||
local testU_p_temp =1-chi2(1,`testU_varchi2_temp')
|
||||
local testU_item_temp=`j'
|
||||
local chi2encours_tmp=`chi2encours'
|
||||
local tmp=`chi2encours'
|
||||
}
|
||||
di in gr "``j''" _col(20) %8.2f in ye `chi2encours' _col(40) %8.2f `=abs(`chi2encours'-`prec_chi2' )' _col(55) "1" %6.4f _col(60) `=1-chi2(1,abs(`chi2encours'-`prec_chi2' ))' _col(82) %8.2f `=abs(`chi2encours'-`chi21')' _col(90) %6.0f `=abs(`df3'+1-`dfc1')' _col(100) %6.4f `=1-chi2(abs(`df3'+1-`dfc1'),abs(`chi2encours'-`chi21'))'
|
||||
local ++cpt
|
||||
}
|
||||
}
|
||||
if (`testU_item_temp'!=0) {
|
||||
matrix `RS'[`testU_item_temp',2]=1
|
||||
local ++df3
|
||||
local testU_varchi2=`testU_varchi2_temp'
|
||||
local testU_p=`testU_p_temp'
|
||||
local testU_item_temp=0
|
||||
local prec_chi2=`tmp'
|
||||
}
|
||||
if (`cpt'!=0) {
|
||||
di "{hline 105}"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**************************************************************************************************************
|
||||
Model 3 / Repriorisation
|
||||
***************************************************************************************************************/
|
||||
|
||||
di
|
||||
di in white _col(10) "Repriorisation"
|
||||
|
||||
local continue=1
|
||||
local var
|
||||
local sem
|
||||
forvalues i=1/`nbitems' {
|
||||
local sem`i' "(T1@load`i' _cons@int`i'->``i'') (T2@load`i' _cons@int`i'->``=`i'+`nbitems''')"
|
||||
local semrecU`i' "(T1@load`i' _cons->``i'') (T2@load`i' _cons->``=`i'+`nbitems''')"
|
||||
local semrecUrep`i' "(T1 _cons->``i'') (T2 _cons->``=`i'+`nbitems''')"
|
||||
local semrep`i' "(T1 _cons@int`i'->``i'') (T2 _cons@int`i'->``=`i'+`nbitems''')"
|
||||
local var`i' "var(e.``i''@var`i') var(e.``=`i'+`nbitems'''@var`i')"
|
||||
local varrecNU`i' "var(e.``i'') var(e.``=`i'+`nbitems''')"
|
||||
if `RS'[`i',1]==1 {
|
||||
local var "`var' `varrecNU`i''"
|
||||
}
|
||||
if `RS'[`i',1]==0 {
|
||||
local var "`var' `var`i''"
|
||||
}
|
||||
}
|
||||
local testU_varchi2=0
|
||||
local testU_p=1
|
||||
di "{hline 105}"
|
||||
di in gr _col(39) "Comparison with previous model" _col(79) "Comparison with model 1"
|
||||
di in gr "Items" _col(18) "Chi-square" _col(39) "Chi-square" _col(54) "df" _col(59) "p-value" _col(79) "Chi-square" _col(94) "df" _col(99) "p-value"
|
||||
di "{hline 105}"
|
||||
|
||||
while (`continue') {
|
||||
local cpt=0
|
||||
local testR_varchi2_temp=0
|
||||
local testR_p_temp=0
|
||||
local testR_item_temp=0
|
||||
local chi2encours_temp=-1
|
||||
local continue=0
|
||||
local sem
|
||||
forvalues j=1/`nbitems' {
|
||||
local sem
|
||||
local already=0
|
||||
forvalues i=1/`nbitems' {
|
||||
if `RS'[`i',3]==0&`RS'[`i',2]==0&`i'!=`j' {
|
||||
local sem `sem' `sem`i''
|
||||
}
|
||||
else if `RS'[`i',3]==0&`RS'[`i',2]==1&`i'!=`j' {
|
||||
local sem `sem' `semrecU`i''
|
||||
}
|
||||
else if `RS'[`i',3]==1&`RS'[`i',2]==0&`i'!=`j' {
|
||||
local sem `sem' `semrep`i''
|
||||
}
|
||||
else if `RS'[`i',3]==1&`RS'[`i',2]==1&`i'!=`j' {
|
||||
local sem `sem' `semrecUrep`i''
|
||||
}
|
||||
else if `i'==`j'&`RS'[`j',3]==0&`RS'[`i',2]==0 {
|
||||
local sem `sem' `semrep`i''
|
||||
}
|
||||
else if `i'==`j'&`RS'[`j',3]==0&`RS'[`i',2]==1&`RS'[`i',1]==0 {
|
||||
local sem `sem' `semrecUrep`i''
|
||||
}
|
||||
else if `i'==`j'&`RS'[`j',3]==0&`RS'[`i',2]==1&`RS'[`i',1]==1 {
|
||||
local already=1
|
||||
}
|
||||
else if `i'==`j'&`RS'[`j',3]==1&`RS'[`i',2]==0 {
|
||||
local sem `sem' `semrep`i''
|
||||
local already=1
|
||||
}
|
||||
else if `i'==`j'&`RS'[`j',3]==1&`RS'[`i',2]==1 {
|
||||
local sem `sem' `semrecUrep`i''
|
||||
local already=1
|
||||
}
|
||||
}
|
||||
if (`already'!=1) {
|
||||
qui sem `sem',var(T1@1) var(T2) means(T1@0) means(T2) `var' iterate(100) method(`method')
|
||||
qui estat gof
|
||||
local chi2encours=r(chi2_ms)
|
||||
if (abs(`chi2encours'-`prec_chi2')>invchi2(1,0.95)&abs(`chi2encours'-`prec_chi2')>`testR_varchi2_temp'&`chi2encours'<`prec_chi2') {
|
||||
local continue=1
|
||||
local testR_varchi2_temp =abs(`chi2encours'-`prec_chi2' )
|
||||
local testR_p_temp =1-chi2(1,`testR_varchi2_temp')
|
||||
local testR_item_temp=`j'
|
||||
local chi2encours_tmp=`chi2encours'
|
||||
local tmp=`chi2encours'
|
||||
}
|
||||
if ( `chi2encours'<`prec_chi2') {
|
||||
di in gr "``j''" _col(20) %8.2f in ye `chi2encours' _col(40) %8.2f `=abs(`chi2encours'-`prec_chi2' )' _col(55) "1" %6.4f _col(60) `=1-chi2(1,abs(`chi2encours'-`prec_chi2' ))' _col(82) %8.2f `=abs(`chi2encours'-`chi21')' _col(90) %6.0f `=abs(`df3'+1-`dfc1')' _col(100) %6.4f `=1-chi2(abs(`df3'+1-`dfc1'),abs(`chi2encours'-`chi21'))'
|
||||
}
|
||||
else {
|
||||
di in gr "``j''" _col(20) %8.2f in ye `chi2encours' _col(40) "Anavailable"
|
||||
}
|
||||
local ++cpt
|
||||
}
|
||||
}
|
||||
if (`testR_item_temp'!=0) {
|
||||
matrix `RS'[`testR_item_temp',3]=1
|
||||
local ++df3
|
||||
local testR_varchi2=`testR_varchi2_temp'
|
||||
local testR_p=`testR_p_temp'
|
||||
local testR_item_temp=0
|
||||
local prec_chi2=`tmp'
|
||||
}
|
||||
if (`cpt'!=0) {
|
||||
di "{hline 105}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************************************************
|
||||
Model 3 Final
|
||||
***************************************************************************************************************/
|
||||
|
||||
di
|
||||
local continue=1
|
||||
local var
|
||||
local sem
|
||||
forvalues i=1/`nbitems' {
|
||||
local sem`i' "(T1@load`i' _cons@int`i'->``i'') (T2@load`i' _cons@int`i'->``=`i'+`nbitems''')"
|
||||
local semrecU`i' "(T1@load`i' _cons->``i'') (T2@load`i' _cons->``=`i'+`nbitems''')"
|
||||
local semrecUrep`i' "(T1 _cons->``i'') (T2 _cons->``=`i'+`nbitems''')"
|
||||
local semrep`i' "(T1 _cons@int`i'->``i'') (T2 _cons@int`i'->``=`i'+`nbitems''')"
|
||||
local var`i' "var(e.``i''@var`i') var(e.``=`i'+`nbitems'''@var`i')"
|
||||
local varrecNU`i' "var(e.``i'') var(e.``=`i'+`nbitems''')"
|
||||
if `RS'[`i',1]==1 {
|
||||
local var "`var' `varrecNU`i''"
|
||||
}
|
||||
if `RS'[`i',1]==0 {
|
||||
local var "`var' `var`i''"
|
||||
}
|
||||
if `RS'[`i',2]==0&`RS'[`i',3]==0 {
|
||||
local sem "`sem' `sem`i''"
|
||||
}
|
||||
if `RS'[`i',2]==0&`RS'[`i',3]==1 {
|
||||
local sem "`sem' `semrep`i''"
|
||||
}
|
||||
if `RS'[`i',2]==1&`RS'[`i',3]==0 {
|
||||
local sem "`sem' `semrecU`i''"
|
||||
}
|
||||
if `RS'[`i',2]==1&`RS'[`i',3]==1 {
|
||||
local sem "`sem' `semrecUrep`i''"
|
||||
}
|
||||
}
|
||||
qui sem `sem',var(T1@1) var(T2) means(T1@0) means(T2) `var' iterate(100) method(`method')
|
||||
tempname b V
|
||||
matrix `b'=e(b)
|
||||
matrix `V'=e(V)
|
||||
local truechange=`b'[1,`=`nbitems'*4+1']
|
||||
local Vtruechange=`V'[`=`nbitems'*4+1',`=`nbitems'*4+1']
|
||||
qui estat gof
|
||||
local tli3=r(tli)
|
||||
local cfi3=r(cfi)
|
||||
local srmr3=r(srmr)
|
||||
local rmsea3=r(rmsea)
|
||||
local ubrmsea3=r(ub90_rmsea)
|
||||
local lbrmsea3=r(lb90_rmsea)
|
||||
local chi23=r(chi2_ms)
|
||||
local dfc3=`df3'
|
||||
local p3=r(p_ms)
|
||||
|
||||
|
||||
|
||||
/**************************************************************************************************************
|
||||
Bilan
|
||||
***************************************************************************************************************/
|
||||
|
||||
di
|
||||
di "{hline 74}"
|
||||
di in gr _col(22) "Non uniform" _col(46) "Uniform"
|
||||
di in gr "Items" _col(20) "Recalibration" _col(40) "Recalibration" _col(60) "Repriorisation"
|
||||
di "{hline 74}"
|
||||
forvalues i=1/`nbitems' {
|
||||
local recNU
|
||||
local recU
|
||||
local rep
|
||||
if (`RS'[`i',1]==1) {
|
||||
local recNU "*"
|
||||
}
|
||||
if (`RS'[`i',2]==1) {
|
||||
local recU "*"
|
||||
}
|
||||
if (`RS'[`i',3]==1) {
|
||||
local rep "*"
|
||||
}
|
||||
di in gr "``i''" in ye _col(32) "`recNU'" _col(52) "`recU'" _col(73) "`rep'"
|
||||
}
|
||||
di "{hline 74}"
|
||||
|
||||
|
||||
/**************************************************************************************************************
|
||||
Model 4
|
||||
***************************************************************************************************************/
|
||||
|
||||
qui sem `sem',var(T1@1) var(T2) means(T1@0) means(T2) `var' iterate(100)
|
||||
tempname b V
|
||||
matrix `b'=e(b)
|
||||
matrix `V'=e(V)
|
||||
local truechange=`b'[1,`=`nbitems'*4+1']
|
||||
local Vtruechange=`V'[`=`nbitems'*4+1',`=`nbitems'*4+1']
|
||||
qui estat gof,stat(all)
|
||||
local tli4=r(tli)
|
||||
local cfi4=r(cfi)
|
||||
local srmr4=r(srmr)
|
||||
local rmsea4=r(rmsea)
|
||||
local ubrmsea4=r(ub90_rmsea)
|
||||
local lbrmsea4=r(lb90_rmsea)
|
||||
local chi24=r(chi2_ms)
|
||||
local dfc4=`df3'+1
|
||||
local p4=r(p_ms)
|
||||
local chi2encours=r(chi2_ms)
|
||||
|
||||
local z=`truechange'/sqrt(`Vtruechange')
|
||||
|
||||
|
||||
di
|
||||
di "{hline 95}"
|
||||
di in gr "Models" _col(14) "chi2" _col(22) "df" _col(35) "p" _col(41) "rmsea" _col(51) "IC90%(RMSEA)" _col(72) "SRMR" _col(83) "CFI" _col(93) "TLI"
|
||||
di "{hline 95}"
|
||||
di in green "Model 1" in ye _col(10) %8.2f `chi21' _col(20) %4.0f `dfc1' _col(30) %6.4f `p1' _col(40) %6.4f `rmsea1' _col(50) %6.4f `lbrmsea1' "-" %6.4f `ubrmsea1' _col(70) %6.4f `srmr1' _col(80) %6.2f `cfi1' _col(90) %6.2f `tli1'
|
||||
di in green "Model 2" in ye _col(10) %8.2f `chi22' _col(20) %4.0f `dfc2' _col(30) %6.4f `p2' _col(40) %6.4f `rmsea2' _col(50) %6.4f `lbrmsea2' "-" %6.4f `ubrmsea2' _col(70) %6.4f `srmr2' _col(80) %6.2f `cfi2' _col(90) %6.2f `tli2'
|
||||
*di in green "Model 3" in ye _col(10) %8.2f `chi23' _col(20) %4.0f `dfc3' _col(30) %6.4f `p3' _col(40) %6.4f `rmsea3' _col(50) %6.4f `lbrmsea3' "-" %6.4f `ubrmsea3' _col(70) %6.4f `srmr3' _col(80) %6.2f `cfi3' _col(90) %6.2f `tli3'
|
||||
di in green "Model 4" in ye _col(10) %8.2f `chi24' _col(20) %4.0f `dfc4' _col(30) %6.4f `p4' _col(40) %6.4f `rmsea4' _col(50) %6.4f `lbrmsea4' "-" %6.4f `ubrmsea4' _col(70) %6.4f `srmr4' _col(80) %6.2f `cfi4' _col(90) %6.2f `tli4'
|
||||
di "{hline 95}"
|
||||
|
||||
|
||||
|
||||
di
|
||||
di "{hline 77}"
|
||||
di _col(23) in gr "Estimation" _col(44) "s.e." _col(60) "z" _col(71) "p-value"
|
||||
di "{hline 77}"
|
||||
di in gr "True change (Model 2)" in ye _col(25) %8.4f `truechange2' _col(40) %8.4f `=sqrt(`Vtruechange2')' _col(56) %6.2f `=`truechange2'/sqrt(`Vtruechange2')' _col(72) %6.4f `=2-2*normal(abs(`truechange2')/sqrt(`Vtruechange2'))'
|
||||
di in gr "True change (Model 4)" in ye _col(25) %8.4f `truechange' _col(40) %8.4f `=sqrt(`Vtruechange')' _col(56) %6.2f `=`truechange'/sqrt(`Vtruechange')' _col(72) %6.4f `=2-2*normal(abs(`truechange')/sqrt(`Vtruechange'))'
|
||||
di "{hline 77}"
|
||||
|
||||
di
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
584
Modules/ado/personal/r/old/rsoort1 (2).ado
Normal file
584
Modules/ado/personal/r/old/rsoort1 (2).ado
Normal file
@ -0,0 +1,584 @@
|
||||
*! version 1 25februar2013
|
||||
*! Jean-Benoit Hardouin
|
||||
************************************************************************************************************
|
||||
* rsoort: Response Shift detection with the Oort procedure
|
||||
*
|
||||
* Historic:
|
||||
* Version 1 (2013-02-25): Jean-Benoit Hardouin
|
||||
*
|
||||
*
|
||||
* Jean-benoit Hardouin - Department of Biomathematics and Biostatistics - University of Nantes - France
|
||||
* EA 4275-SPHERE "bioStatistics, Pharmacoepidemiology and Human sciEnces Research tEam"
|
||||
* jean-benoit.hardouin@univ-nantes.fr
|
||||
*
|
||||
* Copyright 2013 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
|
||||
************************************************************************************************************/
|
||||
|
||||
|
||||
/***********************************************************************************************************
|
||||
INTRODUCTION
|
||||
***********************************************************************************************************/
|
||||
|
||||
|
||||
program define rsoort,eclass
|
||||
syntax varlist(min=1 numeric) [if] [in] [,METHod(string) UNIFormrecalibration(varlist) NONUNIFormrecalibration(varlist) REPriorisation(varlist) noSearch]
|
||||
|
||||
tokenize `varlist'
|
||||
local nbitems:word count `varlist'
|
||||
local mod=mod(`nbitems',2)
|
||||
if `mod'!=0 {
|
||||
di in red "You must enter an even number of items : the first half of the items represents the items in time 1 and the second half the items in time 2"
|
||||
error
|
||||
}
|
||||
|
||||
if "`method'"=="" {
|
||||
local method "ml"
|
||||
}
|
||||
local nbitems=`nbitems'/2
|
||||
|
||||
di _col(20) "{hline 30}"
|
||||
di _col(20) in gr "Time 1" _col(40) "Time 2"
|
||||
di _col(20) "{hline 30}"
|
||||
forvalues i=1/`nbitems' {
|
||||
di in ye _col(20) "``i''" _col(40) "``=`i'+`nbitems'''"
|
||||
}
|
||||
di _col(20) "{hline 30}"
|
||||
|
||||
|
||||
/**************************************************************************************************************
|
||||
Model 1
|
||||
***************************************************************************************************************/
|
||||
|
||||
qui sem (T1->`1'-``nbitems'')(T2->``=`nbitems'+1''-``=`nbitems'*2''),var(T1@1) var(T2@1) means(T1@0) means(T2@0) method(`method')
|
||||
qui estat gof, stat(all)
|
||||
local tli1=r(tli)
|
||||
local cfi1=r(cfi)
|
||||
local srmr1=r(srmr)
|
||||
local rmsea1=r(rmsea)
|
||||
local ubrmsea1=r(ub90_rmsea)
|
||||
local lbrmsea1=r(lb90_rmsea)
|
||||
local chi21=r(chi2_ms)
|
||||
local df1=r(df_ms)
|
||||
local dfc1=6*`nbitems'+1
|
||||
local p1=r(p_ms)
|
||||
*di
|
||||
*di in green " ***********************************Model 1********************************************"
|
||||
*di in gr _col(14) "chi2" _col(22) "df" _col(35) "p" _col(41) "rmsea" _col(51) "IC90%(RMSEA)" _col(72) "SRMR" _col(83) "CFI" _col(93) "TLI"
|
||||
*di in ye _col(10) %8.2f `chi21' _col(20) %4.0f `dfc1' _col(30) %6.4f `p1' _col(40) %6.4f `rmsea1' _col(50) %6.4f `lbrmsea1' "-" %6.4f `ubrmsea1' _col(70) %6.4f `srmr1' _col(80) %6.2f `cfi1' _col(90) %6.2f `tli1'
|
||||
|
||||
/**************************************************************************************************************
|
||||
Model 2
|
||||
***************************************************************************************************************/
|
||||
|
||||
local sem
|
||||
local var
|
||||
forvalues i=1/`nbitems' {
|
||||
local sem`i' "(T1@load`i' _cons@int`i'->``i'') (T2@load`i' _cons@int`i'->``=`i'+`nbitems''')"
|
||||
local var`i' "var(e.``i''@var`i') var(e.``=`i'+`nbitems'''@var`i')"
|
||||
local sem `sem' `sem`i''
|
||||
local var `var' `var`i''
|
||||
}
|
||||
|
||||
qui sem `sem',var(T1@1) var(T2) means(T1@0) means(T2) `var' iterate(100) method(`method')
|
||||
tempname b V
|
||||
matrix `b'=e(b)
|
||||
matrix `V'=e(V)
|
||||
local truechange2=`b'[1,`=`nbitems'*4+1']
|
||||
local Vtruechange2=`V'[`=`nbitems'*4+1',`=`nbitems'*4+1']
|
||||
qui estat gof, stat(all)
|
||||
local tli2=r(tli)
|
||||
local cfi2=r(cfi)
|
||||
local srmr2=r(srmr)
|
||||
local rmsea2=r(rmsea)
|
||||
local ubrmsea2=r(ub90_rmsea)
|
||||
local lbrmsea2=r(lb90_rmsea)
|
||||
local chi22=r(chi2_ms)
|
||||
local df2=r(df_ms)
|
||||
local dfc2=3*`nbitems'+3
|
||||
local p2=r(p_ms)
|
||||
|
||||
local chi221=abs(`chi21'-`chi22')
|
||||
local df21=`df2'-`df1'
|
||||
local p21=1-chi2(`df21',`chi221')
|
||||
|
||||
|
||||
di "{hline 105}"
|
||||
di in gr _col(39) "Test of global Response-Shift " _col(79) "Comparison with model 1"
|
||||
di in gr "Models" _col(18) "Chi-square" _col(39) "Chi-square" _col(54) "df" _col(59) "p-value" _col(79) "Chi-square" _col(94) "df" _col(99) "p-value"
|
||||
di "{hline 105}"
|
||||
di in gr "Model 1" _col(20) %8.2f in ye `chi21'
|
||||
di in gr "Model 2" _col(20) %8.2f in ye `chi22' _col(40) %8.2f `=abs(`chi22'-`chi21')' _col(50) %6.0f `df21' %6.4f _col(60) `=1-chi2(`df21',abs(`chi22'-`chi21'))' _col(82) %8.2f `=`=abs(`chi22'-`chi21')'' _col(90) %6.0f `df21' _col(100) %6.4f `=1-chi2(`df21',abs(`chi22'-`chi21'))'
|
||||
di "{hline 105}"
|
||||
|
||||
|
||||
/**************************************************************************************************************
|
||||
Model 3
|
||||
***************************************************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************************************************
|
||||
Model 3 / Non uniform recalibration
|
||||
***************************************************************************************************************/
|
||||
|
||||
tempname RS RSprec
|
||||
qui matrix `RS'=J(`nbitems',3,0)
|
||||
qui matrix `RSprec'=J(`nbitems',3,0)
|
||||
local df3=`dfc2'
|
||||
|
||||
*set trace on
|
||||
|
||||
|
||||
forvalues i=1/`nbitems' {
|
||||
local nbUR:word count `uniformrecalibration'
|
||||
forvalues j=1/`nbUR' {
|
||||
local itemj: word `j' of `uniformrecalibration'
|
||||
if "``i''"=="`itemj'" {
|
||||
matrix `RS'[`i',2]=1
|
||||
}
|
||||
}
|
||||
local nbNUR:word count `nonuniformrecalibration'
|
||||
forvalues j=1/`nbNUR' {
|
||||
local itemj: word `j' of `nonuniformrecalibration'
|
||||
if "``i''"=="`itemj'" {
|
||||
matrix `RS'[`i',1]=1
|
||||
}
|
||||
}
|
||||
local nbR:word count `repriorisation'
|
||||
forvalues j=1/`nbR' {
|
||||
local itemj: word `j' of `repriorisation'
|
||||
if "``i''"=="`itemj'" {
|
||||
matrix `RS'[`i',3]=1
|
||||
}
|
||||
}
|
||||
}
|
||||
matrix list `RS'
|
||||
|
||||
if "`search'"=="" {
|
||||
|
||||
di
|
||||
di "{hline 105}"
|
||||
di in green _col(50) "Model 3"
|
||||
di "{hline 105}"
|
||||
di
|
||||
di in white _col(10) "Non uniform Recalibration"
|
||||
|
||||
local continue=1
|
||||
forvalues i=1/`nbitems' {
|
||||
local sem`i' "(T1@load`i' _cons@int`i'->``i'') (T2@load`i' _cons@int`i'->``=`i'+`nbitems''')"
|
||||
local var`i' "var(e.``i''@var`i') var(e.``=`i'+`nbitems'''@var`i')"
|
||||
local semrecU`i' "(T1@load`i' _cons->``i'') (T2@load`i' _cons->``=`i'+`nbitems''')"
|
||||
local semrep`i' "(T1 _cons@int`i'->``i'') (T2 _cons@int`i'->``=`i'+`nbitems''')"
|
||||
local varrecNU`i' "var(e.``i'') var(e.``=`i'+`nbitems''')"
|
||||
}
|
||||
local prec_chi2=`chi22'
|
||||
local testNU_varchi2=0
|
||||
local testNU_p=1
|
||||
di "{hline 105}"
|
||||
di in gr _col(39) "Comparison with previous model" _col(79) "Comparison with model 1"
|
||||
di in gr "Items" _col(18) "Chi-square" _col(39) "Chi-square" _col(54) "df" _col(59) "p-value" _col(79) "Chi-square" _col(94) "df" _col(99) "p-value"
|
||||
di "{hline 105}"
|
||||
|
||||
|
||||
while (`continue') {
|
||||
local cpt=0
|
||||
local testNU_varchi2_temp=0
|
||||
local testNU_p_temp=0
|
||||
local testNU_item_temp=0
|
||||
local chi2encours_temp=-1
|
||||
local continue=0
|
||||
local sem
|
||||
local var
|
||||
forvalues j=1/`nbitems' {
|
||||
local sem
|
||||
local var
|
||||
local already=0
|
||||
forvalues i=1/`nbitems' {
|
||||
if `RS'[`i',1]==0&`i'!=`j' {
|
||||
local sem `sem' `sem`i''
|
||||
local var `var' `var`i''
|
||||
}
|
||||
if `RS'[`i',1]==1&`i'!=`j' {
|
||||
local sem `sem' `sem`i''
|
||||
local var `var' `varrecNU`i''
|
||||
}
|
||||
else if `i'==`j'&`RS'[`j',1]==0 {
|
||||
local sem `sem' `sem`i''
|
||||
local var `var' `varrecNU`i''
|
||||
}
|
||||
else if `i'==`j'&`RS'[`j',1]==1 {
|
||||
local sem `sem' `sem`i''
|
||||
local var `var' `varrecNU`i''
|
||||
local already=1
|
||||
}
|
||||
}
|
||||
if (`already'!=1) {
|
||||
qui sem `sem',var(T1@1) var(T2) means(T1@0) means(T2) `var' iterate(100) method(`method')
|
||||
qui estat gof
|
||||
local chi2encours=r(chi2_ms)
|
||||
if (abs(`chi2encours'-`prec_chi2')>invchi2(1,0.95)&abs(`chi2encours'-`prec_chi2')>`testNU_varchi2_temp') {
|
||||
local continue=1
|
||||
local testNU_varchi2_temp =abs(`chi2encours'-`prec_chi2' )
|
||||
local testNU_p_temp =1-chi2(1,`testNU_varchi2_temp')
|
||||
local testNU_item_temp=`j'
|
||||
local chi2encours_tmp=`chi2encours'
|
||||
local tmp=`chi2encours'
|
||||
}
|
||||
di in gr "``j''" _col(20) %8.2f in ye `chi2encours' _col(40) %8.2f `=abs(`chi2encours'-`prec_chi2' )' _col(55) "1" %6.4f _col(60) `=1-chi2(1,abs(`chi2encours'-`prec_chi2' ))' _col(82) %8.2f `=abs(`chi2encours'-`chi21')' _col(90) %6.0f `=abs(`df3'+1-`dfc1')' _col(100) %6.4f `=1-chi2(abs(`df3'+1-`dfc1'),abs(`chi2encours'-`chi21'))'
|
||||
local ++cpt
|
||||
}
|
||||
}
|
||||
if (`testNU_item_temp'!=0) {
|
||||
matrix `RS'[`testNU_item_temp',1]=1
|
||||
local ++df3
|
||||
local testNU_varchi2=`testNU_varchi2_temp'
|
||||
local testNU_p=`testNU_p_temp'
|
||||
local testNU_item_temp=0
|
||||
local prec_chi2=`tmp'
|
||||
}
|
||||
if (`cpt'!=0) {
|
||||
di "{hline 105}"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**************************************************************************************************************
|
||||
Model 3 / Uniform recalibration
|
||||
***************************************************************************************************************/
|
||||
|
||||
di
|
||||
di in white _col(10) "Uniform Recalibration"
|
||||
|
||||
local continue=1
|
||||
local var
|
||||
forvalues i=1/`nbitems' {
|
||||
local sem`i' "(T1@load`i' _cons@int`i'->``i'') (T2@load`i' _cons@int`i'->``=`i'+`nbitems''')"
|
||||
local semrecU`i' "(T1@load`i' _cons->``i'') (T2@load`i' _cons->``=`i'+`nbitems''')"
|
||||
local semrep`i' "(T1 _cons@int`i'->``i'') (T2 _cons@int`i'->``=`i'+`nbitems''')"
|
||||
local var`i' "var(e.``i''@var`i') var(e.``=`i'+`nbitems'''@var`i')"
|
||||
local varrecNU`i' "var(e.``i'') var(e.``=`i'+`nbitems''')"
|
||||
if `RS'[`i',1]==1 {
|
||||
local var "`var' `varrecNU`i''"
|
||||
}
|
||||
if `RS'[`i',1]==0 {
|
||||
local var "`var' `var`i''"
|
||||
}
|
||||
}
|
||||
local testU_varchi2=0
|
||||
local testU_p=1
|
||||
di "{hline 105}"
|
||||
di in gr _col(39) "Comparison with previous model" _col(79) "Comparison with model 1"
|
||||
di in gr "Items" _col(18) "Chi-square" _col(39) "Chi-square" _col(54) "df" _col(59) "p-value" _col(79) "Chi-square" _col(94) "df" _col(99) "p-value"
|
||||
di "{hline 105}"
|
||||
|
||||
while (`continue') {
|
||||
local cpt=0
|
||||
local testU_varchi2_temp=0
|
||||
local testU_p_temp=0
|
||||
local testU_item_temp=0
|
||||
local chi2encours_temp=-1
|
||||
local continue=0
|
||||
local sem
|
||||
forvalues j=1/`nbitems' {
|
||||
local sem
|
||||
local already=0
|
||||
forvalues i=1/`nbitems' {
|
||||
if `RS'[`i',2]==0&`i'!=`j' {
|
||||
local sem `sem' `sem`i''
|
||||
}
|
||||
if `RS'[`i',2]==1&`i'!=`j' {
|
||||
local sem `sem' `semrecU`i''
|
||||
}
|
||||
else if `i'==`j'&`RS'[`j',2]==0 {
|
||||
local sem `sem' `semrecU`i''
|
||||
}
|
||||
else if `i'==`j'&`RS'[`j',2]==1 {
|
||||
local sem `sem' `semrecU`i''
|
||||
local already=1
|
||||
}
|
||||
}
|
||||
if (`already'!=1) {
|
||||
qui sem `sem',var(T1@1) var(T2) means(T1@0) means(T2) `var' iterate(100) method(`method')
|
||||
qui estat gof
|
||||
local chi2encours=r(chi2_ms)
|
||||
if (abs(`chi2encours'-`prec_chi2')>invchi2(1,0.95)&abs(`chi2encours'-`prec_chi2')>`testU_varchi2_temp') {
|
||||
local continue=1
|
||||
local testU_varchi2_temp =abs(`chi2encours'-`prec_chi2' )
|
||||
local testU_p_temp =1-chi2(1,`testU_varchi2_temp')
|
||||
local testU_item_temp=`j'
|
||||
local chi2encours_tmp=`chi2encours'
|
||||
local tmp=`chi2encours'
|
||||
}
|
||||
di in gr "``j''" _col(20) %8.2f in ye `chi2encours' _col(40) %8.2f `=abs(`chi2encours'-`prec_chi2' )' _col(55) "1" %6.4f _col(60) `=1-chi2(1,abs(`chi2encours'-`prec_chi2' ))' _col(82) %8.2f `=abs(`chi2encours'-`chi21')' _col(90) %6.0f `=abs(`df3'+1-`dfc1')' _col(100) %6.4f `=1-chi2(abs(`df3'+1-`dfc1'),abs(`chi2encours'-`chi21'))'
|
||||
local ++cpt
|
||||
}
|
||||
}
|
||||
if (`testU_item_temp'!=0) {
|
||||
matrix `RS'[`testU_item_temp',2]=1
|
||||
local ++df3
|
||||
local testU_varchi2=`testU_varchi2_temp'
|
||||
local testU_p=`testU_p_temp'
|
||||
local testU_item_temp=0
|
||||
local prec_chi2=`tmp'
|
||||
}
|
||||
if (`cpt'!=0) {
|
||||
di "{hline 105}"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**************************************************************************************************************
|
||||
Model 3 / Repriorisation
|
||||
***************************************************************************************************************/
|
||||
|
||||
di
|
||||
di in white _col(10) "Repriorisation"
|
||||
|
||||
local continue=1
|
||||
local var
|
||||
local sem
|
||||
forvalues i=1/`nbitems' {
|
||||
local sem`i' "(T1@load`i' _cons@int`i'->``i'') (T2@load`i' _cons@int`i'->``=`i'+`nbitems''')"
|
||||
local semrecU`i' "(T1@load`i' _cons->``i'') (T2@load`i' _cons->``=`i'+`nbitems''')"
|
||||
local semrecUrep`i' "(T1 _cons->``i'') (T2 _cons->``=`i'+`nbitems''')"
|
||||
local semrep`i' "(T1 _cons@int`i'->``i'') (T2 _cons@int`i'->``=`i'+`nbitems''')"
|
||||
local var`i' "var(e.``i''@var`i') var(e.``=`i'+`nbitems'''@var`i')"
|
||||
local varrecNU`i' "var(e.``i'') var(e.``=`i'+`nbitems''')"
|
||||
if `RS'[`i',1]==1 {
|
||||
local var "`var' `varrecNU`i''"
|
||||
}
|
||||
if `RS'[`i',1]==0 {
|
||||
local var "`var' `var`i''"
|
||||
}
|
||||
}
|
||||
local testU_varchi2=0
|
||||
local testU_p=1
|
||||
di "{hline 105}"
|
||||
di in gr _col(39) "Comparison with previous model" _col(79) "Comparison with model 1"
|
||||
di in gr "Items" _col(18) "Chi-square" _col(39) "Chi-square" _col(54) "df" _col(59) "p-value" _col(79) "Chi-square" _col(94) "df" _col(99) "p-value"
|
||||
di "{hline 105}"
|
||||
|
||||
while (`continue') {
|
||||
local cpt=0
|
||||
local testR_varchi2_temp=0
|
||||
local testR_p_temp=0
|
||||
local testR_item_temp=0
|
||||
local chi2encours_temp=-1
|
||||
local continue=0
|
||||
local sem
|
||||
forvalues j=1/`nbitems' {
|
||||
local sem
|
||||
local already=0
|
||||
forvalues i=1/`nbitems' {
|
||||
if `RS'[`i',3]==0&`RS'[`i',2]==0&`i'!=`j' {
|
||||
local sem `sem' `sem`i''
|
||||
}
|
||||
else if `RS'[`i',3]==0&`RS'[`i',2]==1&`i'!=`j' {
|
||||
local sem `sem' `semrecU`i''
|
||||
}
|
||||
else if `RS'[`i',3]==1&`RS'[`i',2]==0&`i'!=`j' {
|
||||
local sem `sem' `semrep`i''
|
||||
}
|
||||
else if `RS'[`i',3]==1&`RS'[`i',2]==1&`i'!=`j' {
|
||||
local sem `sem' `semrecUrep`i''
|
||||
}
|
||||
else if `i'==`j'&`RS'[`j',3]==0&`RS'[`i',2]==0 {
|
||||
local sem `sem' `semrep`i''
|
||||
}
|
||||
else if `i'==`j'&`RS'[`j',3]==0&`RS'[`i',2]==1&`RS'[`i',1]==0 {
|
||||
local sem `sem' `semrecUrep`i''
|
||||
}
|
||||
else if `i'==`j'&`RS'[`j',3]==0&`RS'[`i',2]==1&`RS'[`i',1]==1 {
|
||||
local already=1
|
||||
}
|
||||
else if `i'==`j'&`RS'[`j',3]==1&`RS'[`i',2]==0 {
|
||||
local sem `sem' `semrep`i''
|
||||
local already=1
|
||||
}
|
||||
else if `i'==`j'&`RS'[`j',3]==1&`RS'[`i',2]==1 {
|
||||
local sem `sem' `semrecUrep`i''
|
||||
local already=1
|
||||
}
|
||||
}
|
||||
if (`already'!=1) {
|
||||
qui sem `sem',var(T1@1) var(T2) means(T1@0) means(T2) `var' iterate(100) method(`method')
|
||||
qui estat gof
|
||||
local chi2encours=r(chi2_ms)
|
||||
if (abs(`chi2encours'-`prec_chi2')>invchi2(1,0.95)&abs(`chi2encours'-`prec_chi2')>`testR_varchi2_temp'&`chi2encours'<`prec_chi2') {
|
||||
local continue=1
|
||||
local testR_varchi2_temp =abs(`chi2encours'-`prec_chi2' )
|
||||
local testR_p_temp =1-chi2(1,`testR_varchi2_temp')
|
||||
local testR_item_temp=`j'
|
||||
local chi2encours_tmp=`chi2encours'
|
||||
local tmp=`chi2encours'
|
||||
}
|
||||
if ( `chi2encours'<`prec_chi2') {
|
||||
di in gr "``j''" _col(20) %8.2f in ye `chi2encours' _col(40) %8.2f `=abs(`chi2encours'-`prec_chi2' )' _col(55) "1" %6.4f _col(60) `=1-chi2(1,abs(`chi2encours'-`prec_chi2' ))' _col(82) %8.2f `=abs(`chi2encours'-`chi21')' _col(90) %6.0f `=abs(`df3'+1-`dfc1')' _col(100) %6.4f `=1-chi2(abs(`df3'+1-`dfc1'),abs(`chi2encours'-`chi21'))'
|
||||
}
|
||||
else {
|
||||
di in gr "``j''" _col(20) %8.2f in ye `chi2encours' _col(40) "Anavailable"
|
||||
}
|
||||
local ++cpt
|
||||
}
|
||||
}
|
||||
if (`testR_item_temp'!=0) {
|
||||
matrix `RS'[`testR_item_temp',3]=1
|
||||
local ++df3
|
||||
local testR_varchi2=`testR_varchi2_temp'
|
||||
local testR_p=`testR_p_temp'
|
||||
local testR_item_temp=0
|
||||
local prec_chi2=`tmp'
|
||||
}
|
||||
if (`cpt'!=0) {
|
||||
di "{hline 105}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************************************************
|
||||
Model 3 Final
|
||||
***************************************************************************************************************/
|
||||
|
||||
di
|
||||
local continue=1
|
||||
local var
|
||||
local sem
|
||||
forvalues i=1/`nbitems' {
|
||||
local sem`i' "(T1@load`i' _cons@int`i'->``i'') (T2@load`i' _cons@int`i'->``=`i'+`nbitems''')"
|
||||
local semrecU`i' "(T1@load`i' _cons->``i'') (T2@load`i' _cons->``=`i'+`nbitems''')"
|
||||
local semrecUrep`i' "(T1 _cons->``i'') (T2 _cons->``=`i'+`nbitems''')"
|
||||
local semrep`i' "(T1 _cons@int`i'->``i'') (T2 _cons@int`i'->``=`i'+`nbitems''')"
|
||||
local var`i' "var(e.``i''@var`i') var(e.``=`i'+`nbitems'''@var`i')"
|
||||
local varrecNU`i' "var(e.``i'') var(e.``=`i'+`nbitems''')"
|
||||
if `RS'[`i',1]==1 {
|
||||
local var "`var' `varrecNU`i''"
|
||||
}
|
||||
if `RS'[`i',1]==0 {
|
||||
local var "`var' `var`i''"
|
||||
}
|
||||
if `RS'[`i',2]==0&`RS'[`i',3]==0 {
|
||||
local sem "`sem' `sem`i''"
|
||||
}
|
||||
if `RS'[`i',2]==0&`RS'[`i',3]==1 {
|
||||
local sem "`sem' `semrep`i''"
|
||||
}
|
||||
if `RS'[`i',2]==1&`RS'[`i',3]==0 {
|
||||
local sem "`sem' `semrecU`i''"
|
||||
}
|
||||
if `RS'[`i',2]==1&`RS'[`i',3]==1 {
|
||||
local sem "`sem' `semrecUrep`i''"
|
||||
}
|
||||
}
|
||||
qui sem `sem',var(T1@1) var(T2) means(T1@0) means(T2) `var' iterate(100) method(`method')
|
||||
tempname b V
|
||||
matrix `b'=e(b)
|
||||
matrix `V'=e(V)
|
||||
local truechange=`b'[1,`=`nbitems'*4+1']
|
||||
local Vtruechange=`V'[`=`nbitems'*4+1',`=`nbitems'*4+1']
|
||||
qui estat gof
|
||||
local tli3=r(tli)
|
||||
local cfi3=r(cfi)
|
||||
local srmr3=r(srmr)
|
||||
local rmsea3=r(rmsea)
|
||||
local ubrmsea3=r(ub90_rmsea)
|
||||
local lbrmsea3=r(lb90_rmsea)
|
||||
local chi23=r(chi2_ms)
|
||||
local dfc3=`df3'
|
||||
local p3=r(p_ms)
|
||||
|
||||
|
||||
|
||||
/**************************************************************************************************************
|
||||
Bilan
|
||||
***************************************************************************************************************/
|
||||
|
||||
di
|
||||
di "{hline 74}"
|
||||
di in gr _col(22) "Non uniform" _col(46) "Uniform"
|
||||
di in gr "Items" _col(20) "Recalibration" _col(40) "Recalibration" _col(60) "Repriorisation"
|
||||
di "{hline 74}"
|
||||
forvalues i=1/`nbitems' {
|
||||
local recNU
|
||||
local recU
|
||||
local rep
|
||||
if (`RS'[`i',1]==1) {
|
||||
local recNU "*"
|
||||
}
|
||||
if (`RS'[`i',2]==1) {
|
||||
local recU "*"
|
||||
}
|
||||
if (`RS'[`i',3]==1) {
|
||||
local rep "*"
|
||||
}
|
||||
di in gr "``i''" in ye _col(32) "`recNU'" _col(52) "`recU'" _col(73) "`rep'"
|
||||
}
|
||||
di "{hline 74}"
|
||||
|
||||
|
||||
/**************************************************************************************************************
|
||||
Model 4
|
||||
***************************************************************************************************************/
|
||||
|
||||
qui sem `sem',var(T1@1) var(T2) means(T1@0) means(T2) `var' iterate(100)
|
||||
tempname b V
|
||||
matrix `b'=e(b)
|
||||
matrix `V'=e(V)
|
||||
local truechange=`b'[1,`=`nbitems'*4+1']
|
||||
local Vtruechange=`V'[`=`nbitems'*4+1',`=`nbitems'*4+1']
|
||||
qui estat gof,stat(all)
|
||||
local tli4=r(tli)
|
||||
local cfi4=r(cfi)
|
||||
local srmr4=r(srmr)
|
||||
local rmsea4=r(rmsea)
|
||||
local ubrmsea4=r(ub90_rmsea)
|
||||
local lbrmsea4=r(lb90_rmsea)
|
||||
local chi24=r(chi2_ms)
|
||||
local dfc4=`df3'+1
|
||||
local p4=r(p_ms)
|
||||
local chi2encours=r(chi2_ms)
|
||||
|
||||
local z=`truechange'/sqrt(`Vtruechange')
|
||||
|
||||
|
||||
di
|
||||
di "{hline 95}"
|
||||
di in gr "Models" _col(14) "chi2" _col(22) "df" _col(35) "p" _col(41) "rmsea" _col(51) "IC90%(RMSEA)" _col(72) "SRMR" _col(83) "CFI" _col(93) "TLI"
|
||||
di "{hline 95}"
|
||||
di in green "Model 1" in ye _col(10) %8.2f `chi21' _col(20) %4.0f `dfc1' _col(30) %6.4f `p1' _col(40) %6.4f `rmsea1' _col(50) %6.4f `lbrmsea1' "-" %6.4f `ubrmsea1' _col(70) %6.4f `srmr1' _col(80) %6.2f `cfi1' _col(90) %6.2f `tli1'
|
||||
di in green "Model 2" in ye _col(10) %8.2f `chi22' _col(20) %4.0f `dfc2' _col(30) %6.4f `p2' _col(40) %6.4f `rmsea2' _col(50) %6.4f `lbrmsea2' "-" %6.4f `ubrmsea2' _col(70) %6.4f `srmr2' _col(80) %6.2f `cfi2' _col(90) %6.2f `tli2'
|
||||
*di in green "Model 3" in ye _col(10) %8.2f `chi23' _col(20) %4.0f `dfc3' _col(30) %6.4f `p3' _col(40) %6.4f `rmsea3' _col(50) %6.4f `lbrmsea3' "-" %6.4f `ubrmsea3' _col(70) %6.4f `srmr3' _col(80) %6.2f `cfi3' _col(90) %6.2f `tli3'
|
||||
di in green "Model 4" in ye _col(10) %8.2f `chi24' _col(20) %4.0f `dfc4' _col(30) %6.4f `p4' _col(40) %6.4f `rmsea4' _col(50) %6.4f `lbrmsea4' "-" %6.4f `ubrmsea4' _col(70) %6.4f `srmr4' _col(80) %6.2f `cfi4' _col(90) %6.2f `tli4'
|
||||
di "{hline 95}"
|
||||
|
||||
|
||||
|
||||
di
|
||||
di "{hline 77}"
|
||||
di _col(23) in gr "Estimation" _col(44) "s.e." _col(60) "z" _col(71) "p-value"
|
||||
di "{hline 77}"
|
||||
di in gr "True change (Model 2)" in ye _col(25) %8.4f `truechange2' _col(40) %8.4f `=sqrt(`Vtruechange2')' _col(56) %6.2f `=`truechange2'/sqrt(`Vtruechange2')' _col(72) %6.4f `=2-2*normal(abs(`truechange2')/sqrt(`Vtruechange2'))'
|
||||
di in gr "True change (Model 4)" in ye _col(25) %8.4f `truechange' _col(40) %8.4f `=sqrt(`Vtruechange')' _col(56) %6.2f `=`truechange'/sqrt(`Vtruechange')' _col(72) %6.4f `=2-2*normal(abs(`truechange')/sqrt(`Vtruechange'))'
|
||||
di "{hline 77}"
|
||||
|
||||
di
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
584
Modules/ado/personal/r/old/rsoort1.ado
Normal file
584
Modules/ado/personal/r/old/rsoort1.ado
Normal file
@ -0,0 +1,584 @@
|
||||
*! version 1 25februar2013
|
||||
*! Jean-Benoit Hardouin
|
||||
************************************************************************************************************
|
||||
* rsoort: Response Shift detection with the Oort procedure
|
||||
*
|
||||
* Historic:
|
||||
* Version 1 (2013-02-25): Jean-Benoit Hardouin
|
||||
*
|
||||
*
|
||||
* Jean-benoit Hardouin - Department of Biomathematics and Biostatistics - University of Nantes - France
|
||||
* EA 4275-SPHERE "bioStatistics, Pharmacoepidemiology and Human sciEnces Research tEam"
|
||||
* jean-benoit.hardouin@univ-nantes.fr
|
||||
*
|
||||
* Copyright 2013 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
|
||||
************************************************************************************************************/
|
||||
|
||||
|
||||
/***********************************************************************************************************
|
||||
INTRODUCTION
|
||||
***********************************************************************************************************/
|
||||
|
||||
|
||||
program define rsoort,eclass
|
||||
syntax varlist(min=1 numeric) [if] [in] [,METHod(string) UNIFormrecalibration(varlist) NONUNIFormrecalibration(varlist) REPriorisation(varlist) noSearch]
|
||||
|
||||
tokenize `varlist'
|
||||
local nbitems:word count `varlist'
|
||||
local mod=mod(`nbitems',2)
|
||||
if `mod'!=0 {
|
||||
di in red "You must enter an even number of items : the first half of the items represents the items in time 1 and the second half the items in time 2"
|
||||
error
|
||||
}
|
||||
|
||||
if "`method'"=="" {
|
||||
local method "ml"
|
||||
}
|
||||
local nbitems=`nbitems'/2
|
||||
|
||||
di _col(20) "{hline 30}"
|
||||
di _col(20) in gr "Time 1" _col(40) "Time 2"
|
||||
di _col(20) "{hline 30}"
|
||||
forvalues i=1/`nbitems' {
|
||||
di in ye _col(20) "``i''" _col(40) "``=`i'+`nbitems'''"
|
||||
}
|
||||
di _col(20) "{hline 30}"
|
||||
|
||||
|
||||
/**************************************************************************************************************
|
||||
Model 1
|
||||
***************************************************************************************************************/
|
||||
|
||||
qui sem (T1->`1'-``nbitems'')(T2->``=`nbitems'+1''-``=`nbitems'*2''),var(T1@1) var(T2@1) means(T1@0) means(T2@0) method(`method')
|
||||
qui estat gof, stat(all)
|
||||
local tli1=r(tli)
|
||||
local cfi1=r(cfi)
|
||||
local srmr1=r(srmr)
|
||||
local rmsea1=r(rmsea)
|
||||
local ubrmsea1=r(ub90_rmsea)
|
||||
local lbrmsea1=r(lb90_rmsea)
|
||||
local chi21=r(chi2_ms)
|
||||
local df1=r(df_ms)
|
||||
local dfc1=6*`nbitems'+1
|
||||
local p1=r(p_ms)
|
||||
*di
|
||||
*di in green " ***********************************Model 1********************************************"
|
||||
*di in gr _col(14) "chi2" _col(22) "df" _col(35) "p" _col(41) "rmsea" _col(51) "IC90%(RMSEA)" _col(72) "SRMR" _col(83) "CFI" _col(93) "TLI"
|
||||
*di in ye _col(10) %8.2f `chi21' _col(20) %4.0f `dfc1' _col(30) %6.4f `p1' _col(40) %6.4f `rmsea1' _col(50) %6.4f `lbrmsea1' "-" %6.4f `ubrmsea1' _col(70) %6.4f `srmr1' _col(80) %6.2f `cfi1' _col(90) %6.2f `tli1'
|
||||
|
||||
/**************************************************************************************************************
|
||||
Model 2
|
||||
***************************************************************************************************************/
|
||||
|
||||
local sem
|
||||
local var
|
||||
forvalues i=1/`nbitems' {
|
||||
local sem`i' "(T1@load`i' _cons@int`i'->``i'') (T2@load`i' _cons@int`i'->``=`i'+`nbitems''')"
|
||||
local var`i' "var(e.``i''@var`i') var(e.``=`i'+`nbitems'''@var`i')"
|
||||
local sem `sem' `sem`i''
|
||||
local var `var' `var`i''
|
||||
}
|
||||
|
||||
qui sem `sem',var(T1@1) var(T2) means(T1@0) means(T2) `var' iterate(100) method(`method')
|
||||
tempname b V
|
||||
matrix `b'=e(b)
|
||||
matrix `V'=e(V)
|
||||
local truechange2=`b'[1,`=`nbitems'*4+1']
|
||||
local Vtruechange2=`V'[`=`nbitems'*4+1',`=`nbitems'*4+1']
|
||||
qui estat gof, stat(all)
|
||||
local tli2=r(tli)
|
||||
local cfi2=r(cfi)
|
||||
local srmr2=r(srmr)
|
||||
local rmsea2=r(rmsea)
|
||||
local ubrmsea2=r(ub90_rmsea)
|
||||
local lbrmsea2=r(lb90_rmsea)
|
||||
local chi22=r(chi2_ms)
|
||||
local df2=r(df_ms)
|
||||
local dfc2=3*`nbitems'+3
|
||||
local p2=r(p_ms)
|
||||
|
||||
local chi221=abs(`chi21'-`chi22')
|
||||
local df21=`df2'-`df1'
|
||||
local p21=1-chi2(`df21',`chi221')
|
||||
|
||||
|
||||
di "{hline 105}"
|
||||
di in gr _col(39) "Test of global Response-Shift " _col(79) "Comparison with model 1"
|
||||
di in gr "Models" _col(18) "Chi-square" _col(39) "Chi-square" _col(54) "df" _col(59) "p-value" _col(79) "Chi-square" _col(94) "df" _col(99) "p-value"
|
||||
di "{hline 105}"
|
||||
di in gr "Model 1" _col(20) %8.2f in ye `chi21'
|
||||
di in gr "Model 2" _col(20) %8.2f in ye `chi22' _col(40) %8.2f `=abs(`chi22'-`chi21')' _col(50) %6.0f `df21' %6.4f _col(60) `=1-chi2(`df21',abs(`chi22'-`chi21'))' _col(82) %8.2f `=`=abs(`chi22'-`chi21')'' _col(90) %6.0f `df21' _col(100) %6.4f `=1-chi2(`df21',abs(`chi22'-`chi21'))'
|
||||
di "{hline 105}"
|
||||
|
||||
|
||||
/**************************************************************************************************************
|
||||
Model 3
|
||||
***************************************************************************************************************/
|
||||
|
||||
|
||||
/**************************************************************************************************************
|
||||
Model 3 / Non uniform recalibration
|
||||
***************************************************************************************************************/
|
||||
|
||||
tempname RS RSprec
|
||||
qui matrix `RS'=J(`nbitems',3,0)
|
||||
qui matrix `RSprec'=J(`nbitems',3,0)
|
||||
local df3=`dfc2'
|
||||
|
||||
*set trace on
|
||||
|
||||
|
||||
forvalues i=1/`nbitems' {
|
||||
local nbUR:word count `uniformrecalibration'
|
||||
forvalues j=1/`nbUR' {
|
||||
local itemj: word `j' of `uniformrecalibration'
|
||||
if "``i''"=="`itemj'" {
|
||||
matrix `RS'[`i',2]=1
|
||||
}
|
||||
}
|
||||
local nbNUR:word count `nonuniformrecalibration'
|
||||
forvalues j=1/`nbNUR' {
|
||||
local itemj: word `j' of `nonuniformrecalibration'
|
||||
if "``i''"=="`itemj'" {
|
||||
matrix `RS'[`i',1]=1
|
||||
}
|
||||
}
|
||||
local nbR:word count `repriorisation'
|
||||
forvalues j=1/`nbR' {
|
||||
local itemj: word `j' of `repriorisation'
|
||||
if "``i''"=="`itemj'" {
|
||||
matrix `RS'[`i',3]=1
|
||||
}
|
||||
}
|
||||
}
|
||||
matrix list `RS'
|
||||
|
||||
if "`search'"=="" {
|
||||
|
||||
di
|
||||
di "{hline 105}"
|
||||
di in green _col(50) "Model 3"
|
||||
di "{hline 105}"
|
||||
di
|
||||
di in white _col(10) "Non uniform Recalibration"
|
||||
|
||||
local continue=1
|
||||
forvalues i=1/`nbitems' {
|
||||
local sem`i' "(T1@load`i' _cons@int`i'->``i'') (T2@load`i' _cons@int`i'->``=`i'+`nbitems''')"
|
||||
local var`i' "var(e.``i''@var`i') var(e.``=`i'+`nbitems'''@var`i')"
|
||||
local semrecU`i' "(T1@load`i' _cons->``i'') (T2@load`i' _cons->``=`i'+`nbitems''')"
|
||||
local semrep`i' "(T1 _cons@int`i'->``i'') (T2 _cons@int`i'->``=`i'+`nbitems''')"
|
||||
local varrecNU`i' "var(e.``i'') var(e.``=`i'+`nbitems''')"
|
||||
}
|
||||
local prec_chi2=`chi22'
|
||||
local testNU_varchi2=0
|
||||
local testNU_p=1
|
||||
di "{hline 105}"
|
||||
di in gr _col(39) "Comparison with previous model" _col(79) "Comparison with model 1"
|
||||
di in gr "Items" _col(18) "Chi-square" _col(39) "Chi-square" _col(54) "df" _col(59) "p-value" _col(79) "Chi-square" _col(94) "df" _col(99) "p-value"
|
||||
di "{hline 105}"
|
||||
|
||||
|
||||
while (`continue') {
|
||||
local cpt=0
|
||||
local testNU_varchi2_temp=0
|
||||
local testNU_p_temp=0
|
||||
local testNU_item_temp=0
|
||||
local chi2encours_temp=-1
|
||||
local continue=0
|
||||
local sem
|
||||
local var
|
||||
forvalues j=1/`nbitems' {
|
||||
local sem
|
||||
local var
|
||||
local already=0
|
||||
forvalues i=1/`nbitems' {
|
||||
if `RS'[`i',1]==0&`i'!=`j' {
|
||||
local sem `sem' `sem`i''
|
||||
local var `var' `var`i''
|
||||
}
|
||||
if `RS'[`i',1]==1&`i'!=`j' {
|
||||
local sem `sem' `sem`i''
|
||||
local var `var' `varrecNU`i''
|
||||
}
|
||||
else if `i'==`j'&`RS'[`j',1]==0 {
|
||||
local sem `sem' `sem`i''
|
||||
local var `var' `varrecNU`i''
|
||||
}
|
||||
else if `i'==`j'&`RS'[`j',1]==1 {
|
||||
local sem `sem' `sem`i''
|
||||
local var `var' `varrecNU`i''
|
||||
local already=1
|
||||
}
|
||||
}
|
||||
if (`already'!=1) {
|
||||
qui sem `sem',var(T1@1) var(T2) means(T1@0) means(T2) `var' iterate(100) method(`method')
|
||||
qui estat gof
|
||||
local chi2encours=r(chi2_ms)
|
||||
if (abs(`chi2encours'-`prec_chi2')>invchi2(1,0.95)&abs(`chi2encours'-`prec_chi2')>`testNU_varchi2_temp') {
|
||||
local continue=1
|
||||
local testNU_varchi2_temp =abs(`chi2encours'-`prec_chi2' )
|
||||
local testNU_p_temp =1-chi2(1,`testNU_varchi2_temp')
|
||||
local testNU_item_temp=`j'
|
||||
local chi2encours_tmp=`chi2encours'
|
||||
local tmp=`chi2encours'
|
||||
}
|
||||
di in gr "``j''" _col(20) %8.2f in ye `chi2encours' _col(40) %8.2f `=abs(`chi2encours'-`prec_chi2' )' _col(55) "1" %6.4f _col(60) `=1-chi2(1,abs(`chi2encours'-`prec_chi2' ))' _col(82) %8.2f `=abs(`chi2encours'-`chi21')' _col(90) %6.0f `=abs(`df3'+1-`dfc1')' _col(100) %6.4f `=1-chi2(abs(`df3'+1-`dfc1'),abs(`chi2encours'-`chi21'))'
|
||||
local ++cpt
|
||||
}
|
||||
}
|
||||
if (`testNU_item_temp'!=0) {
|
||||
matrix `RS'[`testNU_item_temp',1]=1
|
||||
local ++df3
|
||||
local testNU_varchi2=`testNU_varchi2_temp'
|
||||
local testNU_p=`testNU_p_temp'
|
||||
local testNU_item_temp=0
|
||||
local prec_chi2=`tmp'
|
||||
}
|
||||
if (`cpt'!=0) {
|
||||
di "{hline 105}"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**************************************************************************************************************
|
||||
Model 3 / Uniform recalibration
|
||||
***************************************************************************************************************/
|
||||
|
||||
di
|
||||
di in white _col(10) "Uniform Recalibration"
|
||||
|
||||
local continue=1
|
||||
local var
|
||||
forvalues i=1/`nbitems' {
|
||||
local sem`i' "(T1@load`i' _cons@int`i'->``i'') (T2@load`i' _cons@int`i'->``=`i'+`nbitems''')"
|
||||
local semrecU`i' "(T1@load`i' _cons->``i'') (T2@load`i' _cons->``=`i'+`nbitems''')"
|
||||
local semrep`i' "(T1 _cons@int`i'->``i'') (T2 _cons@int`i'->``=`i'+`nbitems''')"
|
||||
local var`i' "var(e.``i''@var`i') var(e.``=`i'+`nbitems'''@var`i')"
|
||||
local varrecNU`i' "var(e.``i'') var(e.``=`i'+`nbitems''')"
|
||||
if `RS'[`i',1]==1 {
|
||||
local var "`var' `varrecNU`i''"
|
||||
}
|
||||
if `RS'[`i',1]==0 {
|
||||
local var "`var' `var`i''"
|
||||
}
|
||||
}
|
||||
local testU_varchi2=0
|
||||
local testU_p=1
|
||||
di "{hline 105}"
|
||||
di in gr _col(39) "Comparison with previous model" _col(79) "Comparison with model 1"
|
||||
di in gr "Items" _col(18) "Chi-square" _col(39) "Chi-square" _col(54) "df" _col(59) "p-value" _col(79) "Chi-square" _col(94) "df" _col(99) "p-value"
|
||||
di "{hline 105}"
|
||||
|
||||
while (`continue') {
|
||||
local cpt=0
|
||||
local testU_varchi2_temp=0
|
||||
local testU_p_temp=0
|
||||
local testU_item_temp=0
|
||||
local chi2encours_temp=-1
|
||||
local continue=0
|
||||
local sem
|
||||
forvalues j=1/`nbitems' {
|
||||
local sem
|
||||
local already=0
|
||||
forvalues i=1/`nbitems' {
|
||||
if `RS'[`i',2]==0&`i'!=`j' {
|
||||
local sem `sem' `sem`i''
|
||||
}
|
||||
if `RS'[`i',2]==1&`i'!=`j' {
|
||||
local sem `sem' `semrecU`i''
|
||||
}
|
||||
else if `i'==`j'&`RS'[`j',2]==0 {
|
||||
local sem `sem' `semrecU`i''
|
||||
}
|
||||
else if `i'==`j'&`RS'[`j',2]==1 {
|
||||
local sem `sem' `semrecU`i''
|
||||
local already=1
|
||||
}
|
||||
}
|
||||
if (`already'!=1) {
|
||||
qui sem `sem',var(T1@1) var(T2) means(T1@0) means(T2) `var' iterate(100) method(`method')
|
||||
qui estat gof
|
||||
local chi2encours=r(chi2_ms)
|
||||
if (abs(`chi2encours'-`prec_chi2')>invchi2(1,0.95)&abs(`chi2encours'-`prec_chi2')>`testU_varchi2_temp') {
|
||||
local continue=1
|
||||
local testU_varchi2_temp =abs(`chi2encours'-`prec_chi2' )
|
||||
local testU_p_temp =1-chi2(1,`testU_varchi2_temp')
|
||||
local testU_item_temp=`j'
|
||||
local chi2encours_tmp=`chi2encours'
|
||||
local tmp=`chi2encours'
|
||||
}
|
||||
di in gr "``j''" _col(20) %8.2f in ye `chi2encours' _col(40) %8.2f `=abs(`chi2encours'-`prec_chi2' )' _col(55) "1" %6.4f _col(60) `=1-chi2(1,abs(`chi2encours'-`prec_chi2' ))' _col(82) %8.2f `=abs(`chi2encours'-`chi21')' _col(90) %6.0f `=abs(`df3'+1-`dfc1')' _col(100) %6.4f `=1-chi2(abs(`df3'+1-`dfc1'),abs(`chi2encours'-`chi21'))'
|
||||
local ++cpt
|
||||
}
|
||||
}
|
||||
if (`testU_item_temp'!=0) {
|
||||
matrix `RS'[`testU_item_temp',2]=1
|
||||
local ++df3
|
||||
local testU_varchi2=`testU_varchi2_temp'
|
||||
local testU_p=`testU_p_temp'
|
||||
local testU_item_temp=0
|
||||
local prec_chi2=`tmp'
|
||||
}
|
||||
if (`cpt'!=0) {
|
||||
di "{hline 105}"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**************************************************************************************************************
|
||||
Model 3 / Repriorisation
|
||||
***************************************************************************************************************/
|
||||
|
||||
di
|
||||
di in white _col(10) "Repriorisation"
|
||||
|
||||
local continue=1
|
||||
local var
|
||||
local sem
|
||||
forvalues i=1/`nbitems' {
|
||||
local sem`i' "(T1@load`i' _cons@int`i'->``i'') (T2@load`i' _cons@int`i'->``=`i'+`nbitems''')"
|
||||
local semrecU`i' "(T1@load`i' _cons->``i'') (T2@load`i' _cons->``=`i'+`nbitems''')"
|
||||
local semrecUrep`i' "(T1 _cons->``i'') (T2 _cons->``=`i'+`nbitems''')"
|
||||
local semrep`i' "(T1 _cons@int`i'->``i'') (T2 _cons@int`i'->``=`i'+`nbitems''')"
|
||||
local var`i' "var(e.``i''@var`i') var(e.``=`i'+`nbitems'''@var`i')"
|
||||
local varrecNU`i' "var(e.``i'') var(e.``=`i'+`nbitems''')"
|
||||
if `RS'[`i',1]==1 {
|
||||
local var "`var' `varrecNU`i''"
|
||||
}
|
||||
if `RS'[`i',1]==0 {
|
||||
local var "`var' `var`i''"
|
||||
}
|
||||
}
|
||||
local testU_varchi2=0
|
||||
local testU_p=1
|
||||
di "{hline 105}"
|
||||
di in gr _col(39) "Comparison with previous model" _col(79) "Comparison with model 1"
|
||||
di in gr "Items" _col(18) "Chi-square" _col(39) "Chi-square" _col(54) "df" _col(59) "p-value" _col(79) "Chi-square" _col(94) "df" _col(99) "p-value"
|
||||
di "{hline 105}"
|
||||
|
||||
while (`continue') {
|
||||
local cpt=0
|
||||
local testR_varchi2_temp=0
|
||||
local testR_p_temp=0
|
||||
local testR_item_temp=0
|
||||
local chi2encours_temp=-1
|
||||
local continue=0
|
||||
local sem
|
||||
forvalues j=1/`nbitems' {
|
||||
local sem
|
||||
local already=0
|
||||
forvalues i=1/`nbitems' {
|
||||
if `RS'[`i',3]==0&`RS'[`i',2]==0&`i'!=`j' {
|
||||
local sem `sem' `sem`i''
|
||||
}
|
||||
else if `RS'[`i',3]==0&`RS'[`i',2]==1&`i'!=`j' {
|
||||
local sem `sem' `semrecU`i''
|
||||
}
|
||||
else if `RS'[`i',3]==1&`RS'[`i',2]==0&`i'!=`j' {
|
||||
local sem `sem' `semrep`i''
|
||||
}
|
||||
else if `RS'[`i',3]==1&`RS'[`i',2]==1&`i'!=`j' {
|
||||
local sem `sem' `semrecUrep`i''
|
||||
}
|
||||
else if `i'==`j'&`RS'[`j',3]==0&`RS'[`i',2]==0 {
|
||||
local sem `sem' `semrep`i''
|
||||
}
|
||||
else if `i'==`j'&`RS'[`j',3]==0&`RS'[`i',2]==1&`RS'[`i',1]==0 {
|
||||
local sem `sem' `semrecUrep`i''
|
||||
}
|
||||
else if `i'==`j'&`RS'[`j',3]==0&`RS'[`i',2]==1&`RS'[`i',1]==1 {
|
||||
local already=1
|
||||
}
|
||||
else if `i'==`j'&`RS'[`j',3]==1&`RS'[`i',2]==0 {
|
||||
local sem `sem' `semrep`i''
|
||||
local already=1
|
||||
}
|
||||
else if `i'==`j'&`RS'[`j',3]==1&`RS'[`i',2]==1 {
|
||||
local sem `sem' `semrecUrep`i''
|
||||
local already=1
|
||||
}
|
||||
}
|
||||
if (`already'!=1) {
|
||||
qui sem `sem',var(T1@1) var(T2) means(T1@0) means(T2) `var' iterate(100) method(`method')
|
||||
qui estat gof
|
||||
local chi2encours=r(chi2_ms)
|
||||
if (abs(`chi2encours'-`prec_chi2')>invchi2(1,0.95)&abs(`chi2encours'-`prec_chi2')>`testR_varchi2_temp'&`chi2encours'<`prec_chi2') {
|
||||
local continue=1
|
||||
local testR_varchi2_temp =abs(`chi2encours'-`prec_chi2' )
|
||||
local testR_p_temp =1-chi2(1,`testR_varchi2_temp')
|
||||
local testR_item_temp=`j'
|
||||
local chi2encours_tmp=`chi2encours'
|
||||
local tmp=`chi2encours'
|
||||
}
|
||||
if ( `chi2encours'<`prec_chi2') {
|
||||
di in gr "``j''" _col(20) %8.2f in ye `chi2encours' _col(40) %8.2f `=abs(`chi2encours'-`prec_chi2' )' _col(55) "1" %6.4f _col(60) `=1-chi2(1,abs(`chi2encours'-`prec_chi2' ))' _col(82) %8.2f `=abs(`chi2encours'-`chi21')' _col(90) %6.0f `=abs(`df3'+1-`dfc1')' _col(100) %6.4f `=1-chi2(abs(`df3'+1-`dfc1'),abs(`chi2encours'-`chi21'))'
|
||||
}
|
||||
else {
|
||||
di in gr "``j''" _col(20) %8.2f in ye `chi2encours' _col(40) "Anavailable"
|
||||
}
|
||||
local ++cpt
|
||||
}
|
||||
}
|
||||
if (`testR_item_temp'!=0) {
|
||||
matrix `RS'[`testR_item_temp',3]=1
|
||||
local ++df3
|
||||
local testR_varchi2=`testR_varchi2_temp'
|
||||
local testR_p=`testR_p_temp'
|
||||
local testR_item_temp=0
|
||||
local prec_chi2=`tmp'
|
||||
}
|
||||
if (`cpt'!=0) {
|
||||
di "{hline 105}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************************************************
|
||||
Model 3 Final
|
||||
***************************************************************************************************************/
|
||||
|
||||
di
|
||||
local continue=1
|
||||
local var
|
||||
local sem
|
||||
forvalues i=1/`nbitems' {
|
||||
local sem`i' "(T1@load`i' _cons@int`i'->``i'') (T2@load`i' _cons@int`i'->``=`i'+`nbitems''')"
|
||||
local semrecU`i' "(T1@load`i' _cons->``i'') (T2@load`i' _cons->``=`i'+`nbitems''')"
|
||||
local semrecUrep`i' "(T1 _cons->``i'') (T2 _cons->``=`i'+`nbitems''')"
|
||||
local semrep`i' "(T1 _cons@int`i'->``i'') (T2 _cons@int`i'->``=`i'+`nbitems''')"
|
||||
local var`i' "var(e.``i''@var`i') var(e.``=`i'+`nbitems'''@var`i')"
|
||||
local varrecNU`i' "var(e.``i'') var(e.``=`i'+`nbitems''')"
|
||||
if `RS'[`i',1]==1 {
|
||||
local var "`var' `varrecNU`i''"
|
||||
}
|
||||
if `RS'[`i',1]==0 {
|
||||
local var "`var' `var`i''"
|
||||
}
|
||||
if `RS'[`i',2]==0&`RS'[`i',3]==0 {
|
||||
local sem "`sem' `sem`i''"
|
||||
}
|
||||
if `RS'[`i',2]==0&`RS'[`i',3]==1 {
|
||||
local sem "`sem' `semrep`i''"
|
||||
}
|
||||
if `RS'[`i',2]==1&`RS'[`i',3]==0 {
|
||||
local sem "`sem' `semrecU`i''"
|
||||
}
|
||||
if `RS'[`i',2]==1&`RS'[`i',3]==1 {
|
||||
local sem "`sem' `semrecUrep`i''"
|
||||
}
|
||||
}
|
||||
qui sem `sem',var(T1@1) var(T2) means(T1@0) means(T2) `var' iterate(100) method(`method')
|
||||
tempname b V
|
||||
matrix `b'=e(b)
|
||||
matrix `V'=e(V)
|
||||
local truechange=`b'[1,`=`nbitems'*4+1']
|
||||
local Vtruechange=`V'[`=`nbitems'*4+1',`=`nbitems'*4+1']
|
||||
qui estat gof
|
||||
local tli3=r(tli)
|
||||
local cfi3=r(cfi)
|
||||
local srmr3=r(srmr)
|
||||
local rmsea3=r(rmsea)
|
||||
local ubrmsea3=r(ub90_rmsea)
|
||||
local lbrmsea3=r(lb90_rmsea)
|
||||
local chi23=r(chi2_ms)
|
||||
local dfc3=`df3'
|
||||
local p3=r(p_ms)
|
||||
|
||||
|
||||
|
||||
/**************************************************************************************************************
|
||||
Bilan
|
||||
***************************************************************************************************************/
|
||||
|
||||
di
|
||||
di "{hline 74}"
|
||||
di in gr _col(22) "Non uniform" _col(46) "Uniform"
|
||||
di in gr "Items" _col(20) "Recalibration" _col(40) "Recalibration" _col(60) "Repriorisation"
|
||||
di "{hline 74}"
|
||||
forvalues i=1/`nbitems' {
|
||||
local recNU
|
||||
local recU
|
||||
local rep
|
||||
if (`RS'[`i',1]==1) {
|
||||
local recNU "*"
|
||||
}
|
||||
if (`RS'[`i',2]==1) {
|
||||
local recU "*"
|
||||
}
|
||||
if (`RS'[`i',3]==1) {
|
||||
local rep "*"
|
||||
}
|
||||
di in gr "``i''" in ye _col(32) "`recNU'" _col(52) "`recU'" _col(73) "`rep'"
|
||||
}
|
||||
di "{hline 74}"
|
||||
|
||||
|
||||
/**************************************************************************************************************
|
||||
Model 4
|
||||
***************************************************************************************************************/
|
||||
|
||||
qui sem `sem',var(T1@1) var(T2) means(T1@0) means(T2) `var' iterate(100)
|
||||
tempname b V
|
||||
matrix `b'=e(b)
|
||||
matrix `V'=e(V)
|
||||
local truechange=`b'[1,`=`nbitems'*4+1']
|
||||
local Vtruechange=`V'[`=`nbitems'*4+1',`=`nbitems'*4+1']
|
||||
qui estat gof,stat(all)
|
||||
local tli4=r(tli)
|
||||
local cfi4=r(cfi)
|
||||
local srmr4=r(srmr)
|
||||
local rmsea4=r(rmsea)
|
||||
local ubrmsea4=r(ub90_rmsea)
|
||||
local lbrmsea4=r(lb90_rmsea)
|
||||
local chi24=r(chi2_ms)
|
||||
local dfc4=`df3'+1
|
||||
local p4=r(p_ms)
|
||||
local chi2encours=r(chi2_ms)
|
||||
|
||||
local z=`truechange'/sqrt(`Vtruechange')
|
||||
|
||||
|
||||
di
|
||||
di "{hline 95}"
|
||||
di in gr "Models" _col(14) "chi2" _col(22) "df" _col(35) "p" _col(41) "rmsea" _col(51) "IC90%(RMSEA)" _col(72) "SRMR" _col(83) "CFI" _col(93) "TLI"
|
||||
di "{hline 95}"
|
||||
di in green "Model 1" in ye _col(10) %8.2f `chi21' _col(20) %4.0f `dfc1' _col(30) %6.4f `p1' _col(40) %6.4f `rmsea1' _col(50) %6.4f `lbrmsea1' "-" %6.4f `ubrmsea1' _col(70) %6.4f `srmr1' _col(80) %6.2f `cfi1' _col(90) %6.2f `tli1'
|
||||
di in green "Model 2" in ye _col(10) %8.2f `chi22' _col(20) %4.0f `dfc2' _col(30) %6.4f `p2' _col(40) %6.4f `rmsea2' _col(50) %6.4f `lbrmsea2' "-" %6.4f `ubrmsea2' _col(70) %6.4f `srmr2' _col(80) %6.2f `cfi2' _col(90) %6.2f `tli2'
|
||||
*di in green "Model 3" in ye _col(10) %8.2f `chi23' _col(20) %4.0f `dfc3' _col(30) %6.4f `p3' _col(40) %6.4f `rmsea3' _col(50) %6.4f `lbrmsea3' "-" %6.4f `ubrmsea3' _col(70) %6.4f `srmr3' _col(80) %6.2f `cfi3' _col(90) %6.2f `tli3'
|
||||
di in green "Model 4" in ye _col(10) %8.2f `chi24' _col(20) %4.0f `dfc4' _col(30) %6.4f `p4' _col(40) %6.4f `rmsea4' _col(50) %6.4f `lbrmsea4' "-" %6.4f `ubrmsea4' _col(70) %6.4f `srmr4' _col(80) %6.2f `cfi4' _col(90) %6.2f `tli4'
|
||||
di "{hline 95}"
|
||||
|
||||
|
||||
|
||||
di
|
||||
di "{hline 77}"
|
||||
di _col(23) in gr "Estimation" _col(44) "s.e." _col(60) "z" _col(71) "p-value"
|
||||
di "{hline 77}"
|
||||
di in gr "True change (Model 2)" in ye _col(25) %8.4f `truechange2' _col(40) %8.4f `=sqrt(`Vtruechange2')' _col(56) %6.2f `=`truechange2'/sqrt(`Vtruechange2')' _col(72) %6.4f `=2-2*normal(abs(`truechange2')/sqrt(`Vtruechange2'))'
|
||||
di in gr "True change (Model 4)" in ye _col(25) %8.4f `truechange' _col(40) %8.4f `=sqrt(`Vtruechange')' _col(56) %6.2f `=`truechange'/sqrt(`Vtruechange')' _col(72) %6.4f `=2-2*normal(abs(`truechange')/sqrt(`Vtruechange'))'
|
||||
di "{hline 77}"
|
||||
|
||||
di
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
Reference in New Issue
Block a user