Computed theoretical power for N=100 and N=200 scenarios
This commit is contained in:
193
Modules/ado/personal/i/imputeitems - Copie.ado
Normal file
193
Modules/ado/personal/i/imputeitems - Copie.ado
Normal file
@ -0,0 +1,193 @@
|
||||
*! version 2.4 3 May 2013
|
||||
*! Jean-Benoit Hardouin
|
||||
************************************************************************************************************
|
||||
* imputeitems: Imputation of missing data of binary items
|
||||
*
|
||||
* Version 1 : November 25, 2006 (Jean-Benoit Hardouin) /*Dichotomous data*/
|
||||
* Version 1.1 : January 26, 2007 (Jean-Benoit Hardouin) /*Correction of a bug with the BIL method*/
|
||||
* Version 1.2 : March 9, 2007 (Jean-Benoit Hardouin) /*IF*/
|
||||
* Version 2 : June 30, 2008 (Jean-Benoit Hardouin) /*new names of the methods, MAX option*/
|
||||
* Version 2.1 : December 3, 2008 (Jean-Benoit Hardouin) /*correction of a bug with the MAX option*/
|
||||
* Version 2.2 : January 28, 2013 (Jean-Benoit Hardouin) /*noround option*/
|
||||
* Version 2.3 : February 19, 2013 (Jean-Benoit Hardouin) /*polytomous items with PMS method*/
|
||||
* Version 2.4 : May 3, 2013 (Jean-Benoit Hardouin) /*minor correction*/
|
||||
*
|
||||
* Jean-benoit Hardouin, phD, Assistant Professor
|
||||
* Team of Biostatistics, Pharmacoepidemiology and Subjective Measures in Health Sciences (UPRES EA 4275 SPHERE)
|
||||
* University of Nantes - Faculty of Pharmaceutical Sciences
|
||||
* France
|
||||
* jean-benoit.hardouin@anaqol.org
|
||||
*
|
||||
* News about this program :http://www.anaqol.org
|
||||
*
|
||||
* Copyright 2006-2008,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
|
||||
************************************************************************************************************/
|
||||
|
||||
|
||||
program define imputeitems
|
||||
version 9
|
||||
syntax varlist(min=2 numeric) [if/] [, PREFix(string) METHod(string) RANDom max(int -1) noround]
|
||||
|
||||
if "`if'"=="" {
|
||||
local if=1
|
||||
local ifif
|
||||
}
|
||||
else {
|
||||
local ifif if `if'
|
||||
}
|
||||
|
||||
*di "IF : `if' `ifif'"
|
||||
|
||||
local nbitems : word count `varlist'
|
||||
tokenize `varlist'
|
||||
|
||||
if `max'==-1 {
|
||||
local max=`nbitems'
|
||||
}
|
||||
|
||||
if "`method'"=="" {
|
||||
local method pms
|
||||
}
|
||||
forvalues i=1/`nbitems' {
|
||||
qui su ``i'' `ifif'
|
||||
if `r(min)'!=0&(`r(max)'!=1&"`method'"!="pms") {
|
||||
di in red "The {hi:imputeqol} command runs only with dichotomous items"
|
||||
error
|
||||
}
|
||||
local p`i'=r(mean)
|
||||
}
|
||||
|
||||
if "`method'"!="pms"&"`method'"!="ims"&"`method'"!="cim"&"`method'"!="ics"&"`method'"!="bip"&"`method'"!="bil"&"`method'"!="bic"&"`method'"!="bii"&"`method'"!="log"&"`method'"!="worst" {
|
||||
di in red "The method option is unknow (choose among pms, ims, cim, ics, log and worst)"
|
||||
error
|
||||
}
|
||||
forvalues i=1/`nbitems'{
|
||||
qui su ``i'' `ifif'
|
||||
local mean`i'=r(mean)
|
||||
}
|
||||
|
||||
if "`method'"=="pms"&"`random'"!="" {
|
||||
local method bip
|
||||
}
|
||||
else if "`method'"=="ims"&"`random'"!="" {
|
||||
local method bii
|
||||
}
|
||||
else if "`method'"=="log"&"`random'"!="" {
|
||||
local method bil
|
||||
}
|
||||
else if "`method'"=="cim"&"`random'"!="" {
|
||||
local method bic
|
||||
}
|
||||
else if ("`method'"=="ics"|"`method'"=="worst")&"`random'"!="" {
|
||||
di in green "The random process is not available with the {hi:ics} or {hi:worst} methods. The {hi:random} option is ignored."
|
||||
local random
|
||||
}
|
||||
|
||||
|
||||
forvalues i=1/`nbitems' {
|
||||
tempvar imp`i' tmp`i'
|
||||
if "`method'"=="pms"|"`method'"=="bip"|"`method'"=="cim"|"`method'"=="bic" {
|
||||
qui egen `imp`i''=rowtotal(`varlist') `ifif'
|
||||
qui egen `tmp`i''=rownonmiss(`varlist') `ifif'
|
||||
qui replace `imp`i''=`imp`i''/`tmp`i'' `ifif'
|
||||
qui replace `imp`i''=``i'' if ``i''!=.&`if'
|
||||
if "`method'"=="pms"&"`round'"=="" {
|
||||
qui replace `imp`i''=round(`imp`i'') `ifif'
|
||||
}
|
||||
else if "`method'"=="bip" {
|
||||
qui replace `imp`i''=uniform()<`imp`i'' `ifif'
|
||||
}
|
||||
else if "`method'"=="cim"|"`method'"=="bic"{
|
||||
qui replace `imp`i''=`imp`i''*`tmp`i''*`mean`i'' `ifif'
|
||||
qui replace `tmp`i''=0 `ifif'
|
||||
forvalues j=1/`nbitems' {
|
||||
qui replace `tmp`i''=`tmp`i''+`mean`j'' if ``j''!=.&`if'
|
||||
}
|
||||
qui replace `imp`i''=`imp`i''/`tmp`i'' `ifif'
|
||||
qui replace `imp`i''=1 if `imp`i''>1&`imp`i''!=.&`if'
|
||||
qui replace `imp`i''=0 if `imp`i''<0&`imp`i''!=.&`if'
|
||||
if "`method'"=="cim"&"`round'"=="" {
|
||||
qui replace `imp`i''=round(`imp`i'') `ifif'
|
||||
}
|
||||
else if "`method'"=="bic" {
|
||||
qui replace `imp`i''=uniform()<`imp`i'' `ifif'
|
||||
}
|
||||
}
|
||||
}
|
||||
else if "`method'"=="ims"|"`method'"=="bii" {
|
||||
qui gen `imp`i''=`mean`i'' `ifif'
|
||||
if "`method'"=="ims"&"`round'"=="" {
|
||||
qui replace `imp`i''=round(`imp`i'') `ifif'
|
||||
}
|
||||
else if "`method'"=="bii" {
|
||||
qui replace `imp`i''=uniform()<`imp`i'' `ifif'
|
||||
}
|
||||
}
|
||||
else if "`method'"=="ics" {
|
||||
local item=0
|
||||
local corrmax=-2
|
||||
forvalues j=1/`nbitems' {
|
||||
if `i'!=`j' {
|
||||
qui corr ``i'' ``j'' `ifif'
|
||||
if r(rho)>`corrmax'&r(rho)!=. {
|
||||
local item `j'
|
||||
local corrmax=r(rho)
|
||||
}
|
||||
}
|
||||
}
|
||||
di "A missing value for the item ``i'' is replaced by the value of the item `item'"
|
||||
qui gen `imp`i''=``i'' `ifif'
|
||||
qui replace `imp`i''=``item'' if ``i''==.&`if'
|
||||
}
|
||||
else if "`method'"=="log"|"`method'"=="bil" {
|
||||
local liste`i'
|
||||
forvalues j=1/`nbitems' {
|
||||
if `i'!=`j' {
|
||||
local liste`i' `liste`i'' ``j''
|
||||
}
|
||||
}
|
||||
qui sw ,pr(0.05): logit ``i'' `liste`i'' `ifif'
|
||||
*local select :colnames e(b)
|
||||
local select=substr("`:colnames e(b)'",1,length("`:colnames e(b)'")-5)
|
||||
qui logit ``i'' `select' `ifif'
|
||||
qui predict `imp`i'' `ifif'
|
||||
if "`method'"=="log"&"`round'"=="" {
|
||||
qui replace `imp`i''=round(`imp`i'') if `imp`i''!=.&`if'
|
||||
}
|
||||
else if "`method'"=="bil" {
|
||||
qui replace `imp`i''=uniform()<`imp`i'' if `imp`i''!=.&`if'
|
||||
}
|
||||
}
|
||||
else if "`method'"=="worst" {
|
||||
qui gen `imp`i''=0 `ifif'
|
||||
}
|
||||
}
|
||||
forvalues i=1/`nbitems' {
|
||||
qui replace `imp`i''=``i'' if ``i''!=.&`if'
|
||||
if "`prefix'"=="" {
|
||||
local prefix imp
|
||||
}
|
||||
qui gen `prefix'``i''=`imp`i'' `ifif'
|
||||
}
|
||||
|
||||
tempvar miss
|
||||
qui egen `miss'=rowmiss(`varlist')
|
||||
forvalues i=1/`nbitems' {
|
||||
qui replace `prefix'``i''=. if ``i''==.&`miss'>`max'
|
||||
}
|
||||
|
||||
end
|
193
Modules/ado/personal/i/imputeitems v2.4.ado
Normal file
193
Modules/ado/personal/i/imputeitems v2.4.ado
Normal file
@ -0,0 +1,193 @@
|
||||
*! version 2.4 3 May 2013
|
||||
*! Jean-Benoit Hardouin
|
||||
************************************************************************************************************
|
||||
* imputeitems: Imputation of missing data of binary items
|
||||
*
|
||||
* Version 1 : November 25, 2006 (Jean-Benoit Hardouin) /*Dichotomous data*/
|
||||
* Version 1.1 : January 26, 2007 (Jean-Benoit Hardouin) /*Correction of a bug with the BIL method*/
|
||||
* Version 1.2 : March 9, 2007 (Jean-Benoit Hardouin) /*IF*/
|
||||
* Version 2 : June 30, 2008 (Jean-Benoit Hardouin) /*new names of the methods, MAX option*/
|
||||
* Version 2.1 : December 3, 2008 (Jean-Benoit Hardouin) /*correction of a bug with the MAX option*/
|
||||
* Version 2.2 : January 28, 2013 (Jean-Benoit Hardouin) /*noround option*/
|
||||
* Version 2.3 : February 19, 2013 (Jean-Benoit Hardouin) /*polytomous items with PMS method*/
|
||||
* Version 2.4 : May 3, 2013 (Jean-Benoit Hardouin) /*minor correction*/
|
||||
*
|
||||
* Jean-benoit Hardouin, phD, Assistant Professor
|
||||
* Team of Biostatistics, Pharmacoepidemiology and Subjective Measures in Health Sciences (UPRES EA 4275 SPHERE)
|
||||
* University of Nantes - Faculty of Pharmaceutical Sciences
|
||||
* France
|
||||
* jean-benoit.hardouin@anaqol.org
|
||||
*
|
||||
* News about this program :http://www.anaqol.org
|
||||
*
|
||||
* Copyright 2006-2008,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
|
||||
************************************************************************************************************/
|
||||
|
||||
|
||||
program define imputeitems
|
||||
version 9
|
||||
syntax varlist(min=2 numeric) [if/] [, PREFix(string) METHod(string) RANDom max(int -1) noround]
|
||||
|
||||
if "`if'"=="" {
|
||||
local if=1
|
||||
local ifif
|
||||
}
|
||||
else {
|
||||
local ifif if `if'
|
||||
}
|
||||
|
||||
*di "IF : `if' `ifif'"
|
||||
|
||||
local nbitems : word count `varlist'
|
||||
tokenize `varlist'
|
||||
|
||||
if `max'==-1 {
|
||||
local max=`nbitems'
|
||||
}
|
||||
|
||||
if "`method'"=="" {
|
||||
local method pms
|
||||
}
|
||||
forvalues i=1/`nbitems' {
|
||||
qui su ``i'' `ifif'
|
||||
if `r(min)'!=0&(`r(max)'!=1&"`method'"!="pms") {
|
||||
di in red "The {hi:imputeqol} command runs only with dichotomous items"
|
||||
error
|
||||
}
|
||||
local p`i'=r(mean)
|
||||
}
|
||||
|
||||
if "`method'"!="pms"&"`method'"!="ims"&"`method'"!="cim"&"`method'"!="ics"&"`method'"!="bip"&"`method'"!="bil"&"`method'"!="bic"&"`method'"!="bii"&"`method'"!="log"&"`method'"!="worst" {
|
||||
di in red "The method option is unknow (choose among pms, ims, cim, ics, log and worst)"
|
||||
error
|
||||
}
|
||||
forvalues i=1/`nbitems'{
|
||||
qui su ``i'' `ifif'
|
||||
local mean`i'=r(mean)
|
||||
}
|
||||
|
||||
if "`method'"=="pms"&"`random'"!="" {
|
||||
local method bip
|
||||
}
|
||||
else if "`method'"=="ims"&"`random'"!="" {
|
||||
local method bii
|
||||
}
|
||||
else if "`method'"=="log"&"`random'"!="" {
|
||||
local method bil
|
||||
}
|
||||
else if "`method'"=="cim"&"`random'"!="" {
|
||||
local method bic
|
||||
}
|
||||
else if ("`method'"=="ics"|"`method'"=="worst")&"`random'"!="" {
|
||||
di in green "The random process is not available with the {hi:ics} or {hi:worst} methods. The {hi:random} option is ignored."
|
||||
local random
|
||||
}
|
||||
|
||||
|
||||
forvalues i=1/`nbitems' {
|
||||
tempvar imp`i' tmp`i'
|
||||
if "`method'"=="pms"|"`method'"=="bip"|"`method'"=="cim"|"`method'"=="bic" {
|
||||
qui egen `imp`i''=rowtotal(`varlist') `ifif'
|
||||
qui egen `tmp`i''=rownonmiss(`varlist') `ifif'
|
||||
qui replace `imp`i''=`imp`i''/`tmp`i'' `ifif'
|
||||
qui replace `imp`i''=``i'' if ``i''!=.&`if'
|
||||
if "`method'"=="pms"&"`round'"=="" {
|
||||
qui replace `imp`i''=round(`imp`i'') `ifif'
|
||||
}
|
||||
else if "`method'"=="bip" {
|
||||
qui replace `imp`i''=uniform()<`imp`i'' `ifif'
|
||||
}
|
||||
else if "`method'"=="cim"|"`method'"=="bic"{
|
||||
qui replace `imp`i''=`imp`i''*`tmp`i''*`mean`i'' `ifif'
|
||||
qui replace `tmp`i''=0 `ifif'
|
||||
forvalues j=1/`nbitems' {
|
||||
qui replace `tmp`i''=`tmp`i''+`mean`j'' if ``j''!=.&`if'
|
||||
}
|
||||
qui replace `imp`i''=`imp`i''/`tmp`i'' `ifif'
|
||||
qui replace `imp`i''=1 if `imp`i''>1&`imp`i''!=.&`if'
|
||||
qui replace `imp`i''=0 if `imp`i''<0&`imp`i''!=.&`if'
|
||||
if "`method'"=="cim"&"`round'"=="" {
|
||||
qui replace `imp`i''=round(`imp`i'') `ifif'
|
||||
}
|
||||
else if "`method'"=="bic" {
|
||||
qui replace `imp`i''=uniform()<`imp`i'' `ifif'
|
||||
}
|
||||
}
|
||||
}
|
||||
else if "`method'"=="ims"|"`method'"=="bii" {
|
||||
qui gen `imp`i''=`mean`i'' `ifif'
|
||||
if "`method'"=="ims"&"`round'"=="" {
|
||||
qui replace `imp`i''=round(`imp`i'') `ifif'
|
||||
}
|
||||
else if "`method'"=="bii" {
|
||||
qui replace `imp`i''=uniform()<`imp`i'' `ifif'
|
||||
}
|
||||
}
|
||||
else if "`method'"=="ics" {
|
||||
local item=0
|
||||
local corrmax=-2
|
||||
forvalues j=1/`nbitems' {
|
||||
if `i'!=`j' {
|
||||
qui corr ``i'' ``j'' `ifif'
|
||||
if r(rho)>`corrmax'&r(rho)!=. {
|
||||
local item `j'
|
||||
local corrmax=r(rho)
|
||||
}
|
||||
}
|
||||
}
|
||||
di "A missing value for the item ``i'' is replaced by the value of the item `item'"
|
||||
qui gen `imp`i''=``i'' `ifif'
|
||||
qui replace `imp`i''=``item'' if ``i''==.&`if'
|
||||
}
|
||||
else if "`method'"=="log"|"`method'"=="bil" {
|
||||
local liste`i'
|
||||
forvalues j=1/`nbitems' {
|
||||
if `i'!=`j' {
|
||||
local liste`i' `liste`i'' ``j''
|
||||
}
|
||||
}
|
||||
qui sw ,pr(0.05): logit ``i'' `liste`i'' `ifif'
|
||||
*local select :colnames e(b)
|
||||
local select=substr("`:colnames e(b)'",1,length("`:colnames e(b)'")-5)
|
||||
qui logit ``i'' `select' `ifif'
|
||||
qui predict `imp`i'' `ifif'
|
||||
if "`method'"=="log"&"`round'"=="" {
|
||||
qui replace `imp`i''=round(`imp`i'') if `imp`i''!=.&`if'
|
||||
}
|
||||
else if "`method'"=="bil" {
|
||||
qui replace `imp`i''=uniform()<`imp`i'' if `imp`i''!=.&`if'
|
||||
}
|
||||
}
|
||||
else if "`method'"=="worst" {
|
||||
qui gen `imp`i''=0 `ifif'
|
||||
}
|
||||
}
|
||||
forvalues i=1/`nbitems' {
|
||||
qui replace `imp`i''=``i'' if ``i''!=.&`if'
|
||||
if "`prefix'"=="" {
|
||||
local prefix imp
|
||||
}
|
||||
qui gen `prefix'``i''=`imp`i'' `ifif'
|
||||
}
|
||||
|
||||
tempvar miss
|
||||
qui egen `miss'=rowmiss(`varlist')
|
||||
forvalues i=1/`nbitems' {
|
||||
qui replace `prefix'``i''=. if ``i''==.&`miss'>`max'
|
||||
}
|
||||
|
||||
end
|
193
Modules/ado/personal/i/imputeitems.ado
Normal file
193
Modules/ado/personal/i/imputeitems.ado
Normal file
@ -0,0 +1,193 @@
|
||||
*! version 2.5 17 December 2021
|
||||
*! Jean-Benoit Hardouin
|
||||
************************************************************************************************************
|
||||
* imputeitems: Imputation of missing data of binary items
|
||||
*
|
||||
* Version 1 : November 25, 2006 (Jean-Benoit Hardouin) /*Dichotomous data*/
|
||||
* Version 1.1 : January 26, 2007 (Jean-Benoit Hardouin) /*Correction of a bug with the BIL method*/
|
||||
* Version 1.2 : March 9, 2007 (Jean-Benoit Hardouin) /*IF*/
|
||||
* Version 2 : June 30, 2008 (Jean-Benoit Hardouin) /*new names of the methods, MAX option*/
|
||||
* Version 2.1 : December 3, 2008 (Jean-Benoit Hardouin) /*correction of a bug with the MAX option*/
|
||||
* Version 2.2 : January 28, 2013 (Jean-Benoit Hardouin) /*noround option*/
|
||||
* Version 2.3 : February 19, 2013 (Jean-Benoit Hardouin) /*polytomous items with PMS method*/
|
||||
* Version 2.4 : May 3, 2013 (Jean-Benoit Hardouin) /*minor correction*/
|
||||
*
|
||||
* Jean-benoit Hardouin, phD, Assistant Professor
|
||||
* Team of Biostatistics, Pharmacoepidemiology and Subjective Measures in Health Sciences (UPRES EA 4275 SPHERE)
|
||||
* University of Nantes - Faculty of Pharmaceutical Sciences
|
||||
* France
|
||||
* jean-benoit.hardouin@anaqol.org
|
||||
*
|
||||
* News about this program :http://www.anaqol.org
|
||||
*
|
||||
* Copyright 2006-2008,2013 2021 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 imputeitems
|
||||
version 9
|
||||
syntax varlist(min=2 numeric) [if/] [, PREFix(string) METHod(string) RANDom max(int -1) noround]
|
||||
|
||||
if "`if'"=="" {
|
||||
local if=1
|
||||
local ifif
|
||||
}
|
||||
else {
|
||||
local ifif if `if'
|
||||
}
|
||||
|
||||
*di "IF : `if' `ifif'"
|
||||
|
||||
local nbitems : word count `varlist'
|
||||
tokenize `varlist'
|
||||
|
||||
if `max'==-1 {
|
||||
local max=`nbitems'
|
||||
}
|
||||
|
||||
if "`method'"=="" {
|
||||
local method pms
|
||||
}
|
||||
forvalues i=1/`nbitems' {
|
||||
qui su ``i'' `ifif'
|
||||
if "`r(min)'"!="0"&("`r(max)'"!="1"&"`method'"!="pms") {
|
||||
di in red "The {hi:imputeqol} command runs only with dichotomous items"
|
||||
error
|
||||
}
|
||||
local p`i'=r(mean)
|
||||
}
|
||||
|
||||
if "`method'"!="pms"&"`method'"!="ims"&"`method'"!="cim"&"`method'"!="ics"&"`method'"!="bip"&"`method'"!="bil"&"`method'"!="bic"&"`method'"!="bii"&"`method'"!="log"&"`method'"!="worst" {
|
||||
di in red "The method option is unknow (choose among pms, ims, cim, ics, log and worst)"
|
||||
error
|
||||
}
|
||||
forvalues i=1/`nbitems'{
|
||||
qui su ``i'' `ifif'
|
||||
local mean`i'=r(mean)
|
||||
}
|
||||
|
||||
if "`method'"=="pms"&"`random'"!="" {
|
||||
local method bip
|
||||
}
|
||||
else if "`method'"=="ims"&"`random'"!="" {
|
||||
local method bii
|
||||
}
|
||||
else if "`method'"=="log"&"`random'"!="" {
|
||||
local method bil
|
||||
}
|
||||
else if "`method'"=="cim"&"`random'"!="" {
|
||||
local method bic
|
||||
}
|
||||
else if ("`method'"=="ics"|"`method'"=="worst")&"`random'"!="" {
|
||||
di in green "The random process is not available with the {hi:ics} or {hi:worst} methods. The {hi:random} option is ignored."
|
||||
local random
|
||||
}
|
||||
|
||||
|
||||
forvalues i=1/`nbitems' {
|
||||
tempvar imp`i' tmp`i'
|
||||
if "`method'"=="pms"|"`method'"=="bip"|"`method'"=="cim"|"`method'"=="bic" {
|
||||
qui egen `imp`i''=rowtotal(`varlist') `ifif'
|
||||
qui egen `tmp`i''=rownonmiss(`varlist') `ifif'
|
||||
qui replace `imp`i''=`imp`i''/`tmp`i'' `ifif'
|
||||
qui replace `imp`i''=``i'' if ``i''!=.&`if'
|
||||
if "`method'"=="pms"&"`round'"=="" {
|
||||
qui replace `imp`i''=round(`imp`i'') `ifif'
|
||||
}
|
||||
else if "`method'"=="bip" {
|
||||
qui replace `imp`i''=uniform()<`imp`i'' `ifif'
|
||||
}
|
||||
else if "`method'"=="cim"|"`method'"=="bic"{
|
||||
qui replace `imp`i''=`imp`i''*`tmp`i''*`mean`i'' `ifif'
|
||||
qui replace `tmp`i''=0 `ifif'
|
||||
forvalues j=1/`nbitems' {
|
||||
qui replace `tmp`i''=`tmp`i''+`mean`j'' if ``j''!=.&`if'
|
||||
}
|
||||
qui replace `imp`i''=`imp`i''/`tmp`i'' `ifif'
|
||||
qui replace `imp`i''=1 if `imp`i''>1&`imp`i''!=.&`if'
|
||||
qui replace `imp`i''=0 if `imp`i''<0&`imp`i''!=.&`if'
|
||||
if "`method'"=="cim"&"`round'"=="" {
|
||||
qui replace `imp`i''=round(`imp`i'') `ifif'
|
||||
}
|
||||
else if "`method'"=="bic" {
|
||||
qui replace `imp`i''=uniform()<`imp`i'' `ifif'
|
||||
}
|
||||
}
|
||||
}
|
||||
else if "`method'"=="ims"|"`method'"=="bii" {
|
||||
qui gen `imp`i''=`mean`i'' `ifif'
|
||||
if "`method'"=="ims"&"`round'"=="" {
|
||||
qui replace `imp`i''=round(`imp`i'') `ifif'
|
||||
}
|
||||
else if "`method'"=="bii" {
|
||||
qui replace `imp`i''=uniform()<`imp`i'' `ifif'
|
||||
}
|
||||
}
|
||||
else if "`method'"=="ics" {
|
||||
local item=0
|
||||
local corrmax=-2
|
||||
forvalues j=1/`nbitems' {
|
||||
if `i'!=`j' {
|
||||
qui corr ``i'' ``j'' `ifif'
|
||||
if r(rho)>`corrmax'&r(rho)!=. {
|
||||
local item `j'
|
||||
local corrmax=r(rho)
|
||||
}
|
||||
}
|
||||
}
|
||||
di "A missing value for the item ``i'' is replaced by the value of the item `item'"
|
||||
qui gen `imp`i''=``i'' `ifif'
|
||||
qui replace `imp`i''=``item'' if ``i''==.&`if'
|
||||
}
|
||||
else if "`method'"=="log"|"`method'"=="bil" {
|
||||
local liste`i'
|
||||
forvalues j=1/`nbitems' {
|
||||
if `i'!=`j' {
|
||||
local liste`i' `liste`i'' ``j''
|
||||
}
|
||||
}
|
||||
qui sw ,pr(0.05): logit ``i'' `liste`i'' `ifif'
|
||||
*local select :colnames e(b)
|
||||
local select=substr("`:colnames e(b)'",1,length("`:colnames e(b)'")-5)
|
||||
qui logit ``i'' `select' `ifif'
|
||||
qui predict `imp`i'' `ifif'
|
||||
if "`method'"=="log"&"`round'"=="" {
|
||||
qui replace `imp`i''=round(`imp`i'') if `imp`i''!=.&`if'
|
||||
}
|
||||
else if "`method'"=="bil" {
|
||||
qui replace `imp`i''=uniform()<`imp`i'' if `imp`i''!=.&`if'
|
||||
}
|
||||
}
|
||||
else if "`method'"=="worst" {
|
||||
qui gen `imp`i''=0 `ifif'
|
||||
}
|
||||
}
|
||||
forvalues i=1/`nbitems' {
|
||||
qui replace `imp`i''=``i'' if ``i''!=.&`if'
|
||||
if "`prefix'"=="" {
|
||||
local prefix imp
|
||||
}
|
||||
qui gen `prefix'``i''=`imp`i'' `ifif'
|
||||
}
|
||||
|
||||
tempvar miss
|
||||
qui egen `miss'=rowmiss(`varlist')
|
||||
forvalues i=1/`nbitems' {
|
||||
qui replace `prefix'``i''=. if ``i''==.&`miss'>`max'
|
||||
}
|
||||
|
||||
end
|
70
Modules/ado/personal/i/imputeitems.hlp
Normal file
70
Modules/ado/personal/i/imputeitems.hlp
Normal file
@ -0,0 +1,70 @@
|
||||
{smcl}
|
||||
{* 6May2013}{...}
|
||||
{hline}
|
||||
help for {hi:imputeitems}{right:Jean-Benoit Hardouin}
|
||||
{hline}
|
||||
|
||||
{title:Imputation of missing item responses}
|
||||
|
||||
{p 8 14 2}{cmd:imputeitems} {it:varlist} [{it:if}] [,{cmdab:pref:ix}({it:string}) {cmdab:meth:od}({it:string}) {cmdab:rand:om} {cmdab:max}({it:#})]
|
||||
|
||||
|
||||
{title:Description}
|
||||
|
||||
{p 4 4 2}{cmd:imputeitems} imputes missing item responses by different ways : Item Mean Substitution (IMS), Person Mean Substitution (PMS), Corrected Item Mean Substiutution (CIM), Interitem Correlation Substitution (ICS), logistic model (LOG) and Worst Case (WORST). A random process can be added to several methods.
|
||||
|
||||
{title:Options}
|
||||
|
||||
{p 4 8 2}{cmd:prefix} defines the prefix to use to name the imputted variables (this prefix is followed by the name of the initial variable). By default, this prefix is "imp".
|
||||
|
||||
{p 4 8 2}{cmd:method} defines the method to impute missing data :
|
||||
|
||||
{p 8 8 2}{it:pms} computes the proportion of positive response of each individual on non missing items, and impute a deterministic result (if p<.5 then 0, else 1),
|
||||
|
||||
{p 8 8 2}{it:ims} computes the proportion of positive response to each items, and impute a deterministic result (if p<.5 then 0, else 1),
|
||||
|
||||
{p 8 8 2}{it:cim} computes the proportion of positive response to each items, corrected by the ability of the individual and impute a deterministic result (if p<.5 then 0, else 1),
|
||||
|
||||
{p 8 8 2}{it:ics} searchs for each item the more correlated item and replaces a missing data by the data of this more correlated item (if the other response is missing too, there is no imputation),
|
||||
|
||||
{p 8 8 2}{it:log} explains the responses of each item by a logistic model where the independent variables are the responses to the others items. Only significant variables are rettained (5%). These methods impute a deterministic result (if p<.5 then 0, else 1) [{it:log}] to missing responses (if the response to an independant variable is missing, there is no imputation),
|
||||
|
||||
{p 8 8 2}{it:worst} replaces the missing data by a 0.
|
||||
|
||||
{p 4 8 2}{cmd:random} adds a random effect to the imputation process (available only with {it:pms}, {it:ims}, {it:cim} or {it:log}). In these cases, the imputed value is randomly drawed from a binomial distribution using the parameter p.
|
||||
|
||||
{p 4 8 2}{cmd:noround} avoids to round the imputed values to the nearest integer.
|
||||
|
||||
{p 4 8 2}{cmd:max} allows imputing missing values only for individuals with a maximal number of missing values defined with this option.
|
||||
|
||||
{p 4 8 2}By default, {it:pms} method is working.
|
||||
|
||||
{p 4 8 2}Old names of methods ({it:bip}, {bii}, {it:bic} and {it:bil} continues to run. They actually correspond to the add of the {cmd:random} option to the {it:pms}, {it:ims}, {it:cim} and {it:log} methods.
|
||||
|
||||
|
||||
{title:Example}
|
||||
|
||||
{cmd:. imputeitems itemA*} /*PMS method, IMP prefix*/
|
||||
|
||||
{cmd:. imputeitems itemA*, prefix(cim) method(cim)}
|
||||
|
||||
{cmd:. imputeitems itemA*, method(log) random}
|
||||
|
||||
|
||||
{title:Reference}
|
||||
|
||||
{p 4 8 2}{cmd:Huisman M.} (2000), Imputation of missing item responses: some simple techniques. {it: Quality & Quantity}, {cmd:34}, 331-351.
|
||||
|
||||
|
||||
{title:Author}
|
||||
|
||||
{p 4 8 2}Jean-Benoit Hardouin, PhD, assistant professor{p_end}
|
||||
{p 4 8 2}EA 4275 "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}
|
||||
|
190
Modules/ado/personal/i/imputeitems.txt
Normal file
190
Modules/ado/personal/i/imputeitems.txt
Normal file
@ -0,0 +1,190 @@
|
||||
*! version 2.3 19 February 2013
|
||||
*! Jean-Benoit Hardouin
|
||||
************************************************************************************************************
|
||||
* imputeitems: Imputation of missing data of binary items
|
||||
*
|
||||
* Version 1 : November 25, 2006 (Jean-Benoit Hardouin) /*Dichotomous data*/
|
||||
* Version 1.1 : January 26, 2007 (Jean-Benoit Hardouin) /*Correction of a bug with the BIL method*/
|
||||
* Version 1.2 : March 9, 2007 (Jean-Benoit Hardouin) /*IF*/
|
||||
* Version 2 : June 30, 2008 (Jean-Benoit Hardouin) /*new names of the methods, MAX option*/
|
||||
* Version 2.1 : December 3, 2008 (Jean-Benoit Hardouin) /*correction of a bug with the MAX option*/
|
||||
* Version 2.2 : January 28, 2013 (Jean-Benoit Hardouin) /*noround option*/
|
||||
* Version 2.3 : February 19, 2013 (Jean-Benoit Hardouin) /*polytomous items with PMS method*/
|
||||
*
|
||||
* 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 2006-2008,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
|
||||
************************************************************************************************************/
|
||||
|
||||
|
||||
program define imputeitems
|
||||
version 9
|
||||
syntax varlist(min=2 numeric) [if/] [, PREFix(string) METHod(string) RANDom max(int 0) noround]
|
||||
|
||||
if "`if'"=="" {
|
||||
local if=1
|
||||
local ifif
|
||||
}
|
||||
else {
|
||||
local ifif if `if'
|
||||
}
|
||||
|
||||
*di "IF : `if' `ifif'"
|
||||
|
||||
local nbitems : word count `varlist'
|
||||
tokenize `varlist'
|
||||
|
||||
if `max'==0 {
|
||||
local max=`nbitems'
|
||||
}
|
||||
|
||||
if "`method'"=="" {
|
||||
local method pms
|
||||
}
|
||||
forvalues i=1/`nbitems' {
|
||||
qui su ``i'' `ifif'
|
||||
if `r(min)'!=0&(`r(max)'!=1&"`method"!="pms") {
|
||||
di in red "The {hi:imputeqol} command runs only with dichotomous items"
|
||||
error
|
||||
}
|
||||
local p`i'=r(mean)
|
||||
}
|
||||
|
||||
if "`method'"!="pms"&"`method'"!="ims"&"`method'"!="cim"&"`method'"!="ics"&"`method'"!="bip"&"`method'"!="bil"&"`method'"!="bic"&"`method'"!="bii"&"`method'"!="log"&"`method'"!="worst" {
|
||||
di in red "The method option is unknow (choose among pms, ims, cim, ics, log and worst)"
|
||||
error
|
||||
}
|
||||
forvalues i=1/`nbitems'{
|
||||
qui su ``i'' `ifif'
|
||||
local mean`i'=r(mean)
|
||||
}
|
||||
|
||||
if "`method'"=="pms"&"`random'"!="" {
|
||||
local method bip
|
||||
}
|
||||
else if "`method'"=="ims"&"`random'"!="" {
|
||||
local method bii
|
||||
}
|
||||
else if "`method'"=="log"&"`random'"!="" {
|
||||
local method bil
|
||||
}
|
||||
else if "`method'"=="cim"&"`random'"!="" {
|
||||
local method bic
|
||||
}
|
||||
else if ("`method'"=="ics"|"`method'"=="worst")&"`random'"!="" {
|
||||
di in green "The random process is not available with the {hi:ics} or {hi:worst} methods. The {hi:random} option is ignored."
|
||||
local random
|
||||
}
|
||||
|
||||
|
||||
forvalues i=1/`nbitems' {
|
||||
tempvar imp`i' tmp`i'
|
||||
if "`method'"=="pms"|"`method'"=="bip"|"`method'"=="cim"|"`method'"=="bic" {
|
||||
qui egen `imp`i''=rowtotal(`varlist') `ifif'
|
||||
qui egen `tmp`i''=rownonmiss(`varlist') `ifif'
|
||||
qui replace `imp`i''=`imp`i''/`tmp`i'' `ifif'
|
||||
qui replace `imp`i''=``i'' if ``i''!=.&`if'
|
||||
if "`method'"=="pms"&"`round'"=="" {
|
||||
qui replace `imp`i''=round(`imp`i'') `ifif'
|
||||
}
|
||||
else if "`method'"=="bip" {
|
||||
qui replace `imp`i''=uniform()<`imp`i'' `ifif'
|
||||
}
|
||||
else if "`method'"=="cim"|"`method'"=="bic"{
|
||||
qui replace `imp`i''=`imp`i''*`tmp`i''*`mean`i'' `ifif'
|
||||
qui replace `tmp`i''=0 `ifif'
|
||||
forvalues j=1/`nbitems' {
|
||||
qui replace `tmp`i''=`tmp`i''+`mean`j'' if ``j''!=.&`if'
|
||||
}
|
||||
qui replace `imp`i''=`imp`i''/`tmp`i'' `ifif'
|
||||
qui replace `imp`i''=1 if `imp`i''>1&`imp`i''!=.&`if'
|
||||
qui replace `imp`i''=0 if `imp`i''<0&`imp`i''!=.&`if'
|
||||
if "`method'"=="cim"&"`round'"=="" {
|
||||
qui replace `imp`i''=round(`imp`i'') `ifif'
|
||||
}
|
||||
else if "`method'"=="bic" {
|
||||
qui replace `imp`i''=uniform()<`imp`i'' `ifif'
|
||||
}
|
||||
}
|
||||
}
|
||||
else if "`method'"=="ims"|"`method'"=="bii" {
|
||||
qui gen `imp`i''=`mean`i'' `ifif'
|
||||
if "`method'"=="ims"&"`round'"=="" {
|
||||
qui replace `imp`i''=round(`imp`i'') `ifif'
|
||||
}
|
||||
else if "`method'"=="bii" {
|
||||
qui replace `imp`i''=uniform()<`imp`i'' `ifif'
|
||||
}
|
||||
}
|
||||
else if "`method'"=="ics" {
|
||||
local item=0
|
||||
local corrmax=-2
|
||||
forvalues j=1/`nbitems' {
|
||||
if `i'!=`j' {
|
||||
qui corr ``i'' ``j'' `ifif'
|
||||
if r(rho)>`corrmax'&r(rho)!=. {
|
||||
local item `j'
|
||||
local corrmax=r(rho)
|
||||
}
|
||||
}
|
||||
}
|
||||
di "A missing value for the item ``i'' is replaced by the value of the item `item'"
|
||||
qui gen `imp`i''=``i'' `ifif'
|
||||
qui replace `imp`i''=``item'' if ``i''==.&`if'
|
||||
}
|
||||
else if "`method'"=="log"|"`method'"=="bil" {
|
||||
local liste`i'
|
||||
forvalues j=1/`nbitems' {
|
||||
if `i'!=`j' {
|
||||
local liste`i' `liste`i'' ``j''
|
||||
}
|
||||
}
|
||||
qui sw ,pr(0.05): logit ``i'' `liste`i'' `ifif'
|
||||
*local select :colnames e(b)
|
||||
local select=substr("`:colnames e(b)'",1,length("`:colnames e(b)'")-5)
|
||||
qui logit ``i'' `select' `ifif'
|
||||
qui predict `imp`i'' `ifif'
|
||||
if "`method'"=="log"&"`round'"=="" {
|
||||
qui replace `imp`i''=round(`imp`i'') if `imp`i''!=.&`if'
|
||||
}
|
||||
else if "`method'"=="bil" {
|
||||
qui replace `imp`i''=uniform()<`imp`i'' if `imp`i''!=.&`if'
|
||||
}
|
||||
}
|
||||
else if "`method'"=="worst" {
|
||||
qui gen `imp`i''=0 `ifif'
|
||||
}
|
||||
}
|
||||
forvalues i=1/`nbitems' {
|
||||
qui replace `imp`i''=``i'' if ``i''!=.&`if'
|
||||
if "`prefix'"=="" {
|
||||
local prefix imp
|
||||
}
|
||||
qui gen `prefix'``i''=`imp`i'' `ifif'
|
||||
}
|
||||
|
||||
tempvar miss
|
||||
qui egen `miss'=rowmiss(`varlist')
|
||||
forvalues i=1/`nbitems' {
|
||||
qui replace `prefix'``i''=. if ``i''==.&`miss'>`max'
|
||||
}
|
||||
|
||||
end
|
201
Modules/ado/personal/i/imputeitems2.ado
Normal file
201
Modules/ado/personal/i/imputeitems2.ado
Normal file
@ -0,0 +1,201 @@
|
||||
*! version 2.3 19 February 2013
|
||||
*! Jean-Benoit Hardouin
|
||||
************************************************************************************************************
|
||||
* imputeitems: Imputation of missing data of binary items
|
||||
*
|
||||
* Version 1 : November 25, 2006 (Jean-Benoit Hardouin) /*Dichotomous data*/
|
||||
* Version 1.1 : January 26, 2007 (Jean-Benoit Hardouin) /*Correction of a bug with the BIL method*/
|
||||
* Version 1.2 : March 9, 2007 (Jean-Benoit Hardouin) /*IF*/
|
||||
* Version 2 : June 30, 2008 (Jean-Benoit Hardouin) /*new names of the methods, MAX option*/
|
||||
* Version 2.1 : December 3, 2008 (Jean-Benoit Hardouin) /*correction of a bug with the MAX option*/
|
||||
* Version 2.2 : January 28, 2013 (Jean-Benoit Hardouin) /*noround option*/
|
||||
* Version 2.3 : February 19, 2013 (Jean-Benoit Hardouin) /*polytomous items with PMS method*/
|
||||
*
|
||||
* 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 2006-2008,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
|
||||
************************************************************************************************************/
|
||||
|
||||
|
||||
program define imputeitems2
|
||||
version 9
|
||||
syntax varlist(min=2 numeric) [if/] [, PREFix(string) METHod(string) RANDom max(int 0) noround replace]
|
||||
|
||||
|
||||
|
||||
if "`noround'" != "" di "noround"
|
||||
if "`round'" != "" di "round"
|
||||
|
||||
|
||||
|
||||
if "`if'"=="" {
|
||||
local if=1
|
||||
local ifif
|
||||
}
|
||||
else {
|
||||
local ifif if `if'
|
||||
}
|
||||
|
||||
*di "IF : `if' `ifif'"
|
||||
|
||||
local nbitems : word count `varlist'
|
||||
tokenize `varlist'
|
||||
|
||||
if `max'==0 {
|
||||
local max=`nbitems'
|
||||
}
|
||||
|
||||
if "`method'"=="" {
|
||||
local method pms
|
||||
}
|
||||
forvalues i=1/`nbitems' {
|
||||
qui su ``i'' `ifif'
|
||||
if `r(min)'!=0&(`r(max)'!=1&"`method'"!="pms") {
|
||||
di in red "The {hi:imputeqol} command runs only with dichotomous items"
|
||||
error
|
||||
}
|
||||
local p`i'=r(mean)
|
||||
}
|
||||
|
||||
if "`method'"!="pms"&"`method'"!="ims"&"`method'"!="cim"&"`method'"!="ics"&"`method'"!="bip"&"`method'"!="bil"&"`method'"!="bic"&"`method'"!="bii"&"`method'"!="log"&"`method'"!="worst" {
|
||||
di in red "The method option is unknow (choose among pms, ims, cim, ics, log and worst)"
|
||||
error
|
||||
}
|
||||
forvalues i=1/`nbitems'{
|
||||
qui su ``i'' `ifif'
|
||||
local mean`i'=r(mean)
|
||||
}
|
||||
|
||||
if "`method'"=="pms"&"`random'"!="" {
|
||||
local method bip
|
||||
}
|
||||
else if "`method'"=="ims"&"`random'"!="" {
|
||||
local method bii
|
||||
}
|
||||
else if "`method'"=="log"&"`random'"!="" {
|
||||
local method bil
|
||||
}
|
||||
else if "`method'"=="cim"&"`random'"!="" {
|
||||
local method bic
|
||||
}
|
||||
else if ("`method'"=="ics"|"`method'"=="worst")&"`random'"!="" {
|
||||
di in green "The random process is not available with the {hi:ics} or {hi:worst} methods. The {hi:random} option is ignored."
|
||||
local random
|
||||
}
|
||||
|
||||
|
||||
forvalues i=1/`nbitems' {
|
||||
tempvar imp`i' tmp`i'
|
||||
if "`method'"=="pms"|"`method'"=="bip"|"`method'"=="cim"|"`method'"=="bic" {
|
||||
qui egen `imp`i''=rowtotal(`varlist') `ifif'
|
||||
qui egen `tmp`i''=rownonmiss(`varlist') `ifif'
|
||||
qui replace `imp`i''=`imp`i''/`tmp`i'' `ifif'
|
||||
qui replace `imp`i''=``i'' if ``i''!=.&`if'
|
||||
if "`method'"=="pms"&"`round'"=="" {
|
||||
qui replace `imp`i''=round(`imp`i'') `ifif'
|
||||
}
|
||||
else if "`method'"=="bip" {
|
||||
qui replace `imp`i''=uniform()<`imp`i'' `ifif'
|
||||
}
|
||||
else if "`method'"=="cim"|"`method'"=="bic"{
|
||||
qui replace `imp`i''=`imp`i''*`tmp`i''*`mean`i'' `ifif'
|
||||
qui replace `tmp`i''=0 `ifif'
|
||||
forvalues j=1/`nbitems' {
|
||||
qui replace `tmp`i''=`tmp`i''+`mean`j'' if ``j''!=.&`if'
|
||||
}
|
||||
qui replace `imp`i''=`imp`i''/`tmp`i'' `ifif'
|
||||
qui replace `imp`i''=1 if `imp`i''>1&`imp`i''!=.&`if'
|
||||
qui replace `imp`i''=0 if `imp`i''<0&`imp`i''!=.&`if'
|
||||
if "`method'"=="cim"&"`round'"=="" {
|
||||
qui replace `imp`i''=round(`imp`i'') `ifif'
|
||||
}
|
||||
else if "`method'"=="bic" {
|
||||
qui replace `imp`i''=uniform()<`imp`i'' `ifif'
|
||||
}
|
||||
}
|
||||
}
|
||||
else if "`method'"=="ims"|"`method'"=="bii" {
|
||||
qui gen `imp`i''=`mean`i'' `ifif'
|
||||
if "`method'"=="ims"&"`round'"=="" {
|
||||
qui replace `imp`i''=round(`imp`i'') `ifif'
|
||||
}
|
||||
else if "`method'"=="bii" {
|
||||
qui replace `imp`i''=uniform()<`imp`i'' `ifif'
|
||||
}
|
||||
}
|
||||
else if "`method'"=="ics" {
|
||||
local item=0
|
||||
local corrmax=-2
|
||||
forvalues j=1/`nbitems' {
|
||||
if `i'!=`j' {
|
||||
qui corr ``i'' ``j'' `ifif'
|
||||
if r(rho)>`corrmax'&r(rho)!=. {
|
||||
local item `j'
|
||||
local corrmax=r(rho)
|
||||
}
|
||||
}
|
||||
}
|
||||
di "A missing value for the item ``i'' is replaced by the value of the item `item'"
|
||||
qui gen `imp`i''=``i'' `ifif'
|
||||
qui replace `imp`i''=``item'' if ``i''==.&`if'
|
||||
}
|
||||
else if "`method'"=="log"|"`method'"=="bil" {
|
||||
local liste`i'
|
||||
forvalues j=1/`nbitems' {
|
||||
if `i'!=`j' {
|
||||
local liste`i' `liste`i'' ``j''
|
||||
}
|
||||
}
|
||||
qui sw ,pr(0.05): logit ``i'' `liste`i'' `ifif'
|
||||
*local select :colnames e(b)
|
||||
local select=substr("`:colnames e(b)'",1,length("`:colnames e(b)'")-5)
|
||||
qui logit ``i'' `select' `ifif'
|
||||
qui predict `imp`i'' `ifif'
|
||||
if "`method'"=="log"&"`round'"=="" {
|
||||
qui replace `imp`i''=round(`imp`i'') if `imp`i''!=.&`if'
|
||||
}
|
||||
else if "`method'"=="bil" {
|
||||
qui replace `imp`i''=uniform()<`imp`i'' if `imp`i''!=.&`if'
|
||||
}
|
||||
}
|
||||
else if "`method'"=="worst" {
|
||||
qui gen `imp`i''=0 `ifif'
|
||||
}
|
||||
}
|
||||
forvalues i=1/`nbitems' {
|
||||
qui replace `imp`i''=``i'' if ``i''!=.&`if'
|
||||
if "`prefix'"=="" {
|
||||
local prefix imp
|
||||
}
|
||||
tempvar `prefix'``i''
|
||||
|
||||
*di "`prefix'``i''"
|
||||
qui gen ``prefix'``i'''=`imp`i'' `ifif'
|
||||
replace ``i'' = ``prefix'``i'''
|
||||
}
|
||||
|
||||
tempvar miss
|
||||
qui egen `miss'=rowmiss(`varlist')
|
||||
forvalues i=1/`nbitems' {
|
||||
qui replace ``prefix'``i'''=. if ``i''==.&`miss'>`max'
|
||||
}
|
||||
|
||||
end
|
193
Modules/ado/personal/i/imputeitems_1.ado
Normal file
193
Modules/ado/personal/i/imputeitems_1.ado
Normal file
@ -0,0 +1,193 @@
|
||||
*! version 2.4 3 May 2013
|
||||
*! Jean-Benoit Hardouin
|
||||
************************************************************************************************************
|
||||
* imputeitems: Imputation of missing data of binary items
|
||||
*
|
||||
* Version 1 : November 25, 2006 (Jean-Benoit Hardouin) /*Dichotomous data*/
|
||||
* Version 1.1 : January 26, 2007 (Jean-Benoit Hardouin) /*Correction of a bug with the BIL method*/
|
||||
* Version 1.2 : March 9, 2007 (Jean-Benoit Hardouin) /*IF*/
|
||||
* Version 2 : June 30, 2008 (Jean-Benoit Hardouin) /*new names of the methods, MAX option*/
|
||||
* Version 2.1 : December 3, 2008 (Jean-Benoit Hardouin) /*correction of a bug with the MAX option*/
|
||||
* Version 2.2 : January 28, 2013 (Jean-Benoit Hardouin) /*noround option*/
|
||||
* Version 2.3 : February 19, 2013 (Jean-Benoit Hardouin) /*polytomous items with PMS method*/
|
||||
* Version 2.4 : May 3, 2013 (Jean-Benoit Hardouin) /*minor correction*/
|
||||
*
|
||||
* Jean-benoit Hardouin, phD, Assistant Professor
|
||||
* Team of Biostatistics, Pharmacoepidemiology and Subjective Measures in Health Sciences (UPRES EA 4275 SPHERE)
|
||||
* University of Nantes - Faculty of Pharmaceutical Sciences
|
||||
* France
|
||||
* jean-benoit.hardouin@anaqol.org
|
||||
*
|
||||
* News about this program :http://www.anaqol.org
|
||||
*
|
||||
* Copyright 2006-2008,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
|
||||
************************************************************************************************************/
|
||||
|
||||
|
||||
program define imputeitems
|
||||
version 9
|
||||
syntax varlist(min=2 numeric) [if/] [, PREFix(string) METHod(string) RANDom max(int -1) noround]
|
||||
|
||||
if "`if'"=="" {
|
||||
local if=1
|
||||
local ifif
|
||||
}
|
||||
else {
|
||||
local ifif if `if'
|
||||
}
|
||||
|
||||
*di "IF : `if' `ifif'"
|
||||
|
||||
local nbitems : word count `varlist'
|
||||
tokenize `varlist'
|
||||
|
||||
if `max'==-1 {
|
||||
local max=`nbitems'
|
||||
}
|
||||
|
||||
if "`method'"=="" {
|
||||
local method pms
|
||||
}
|
||||
forvalues i=1/`nbitems' {
|
||||
qui su ``i'' `ifif'
|
||||
if `r(min)'!=0&(`r(max)'!=1&"`method'"!="pms") {
|
||||
di in red "The {hi:imputeqol} command runs only with dichotomous items"
|
||||
error
|
||||
}
|
||||
local p`i'=r(mean)
|
||||
}
|
||||
|
||||
if "`method'"!="pms"&"`method'"!="ims"&"`method'"!="cim"&"`method'"!="ics"&"`method'"!="bip"&"`method'"!="bil"&"`method'"!="bic"&"`method'"!="bii"&"`method'"!="log"&"`method'"!="worst" {
|
||||
di in red "The method option is unknow (choose among pms, ims, cim, ics, log and worst)"
|
||||
error
|
||||
}
|
||||
forvalues i=1/`nbitems'{
|
||||
qui su ``i'' `ifif'
|
||||
local mean`i'=r(mean)
|
||||
}
|
||||
|
||||
if "`method'"=="pms"&"`random'"!="" {
|
||||
local method bip
|
||||
}
|
||||
else if "`method'"=="ims"&"`random'"!="" {
|
||||
local method bii
|
||||
}
|
||||
else if "`method'"=="log"&"`random'"!="" {
|
||||
local method bil
|
||||
}
|
||||
else if "`method'"=="cim"&"`random'"!="" {
|
||||
local method bic
|
||||
}
|
||||
else if ("`method'"=="ics"|"`method'"=="worst")&"`random'"!="" {
|
||||
di in green "The random process is not available with the {hi:ics} or {hi:worst} methods. The {hi:random} option is ignored."
|
||||
local random
|
||||
}
|
||||
|
||||
|
||||
forvalues i=1/`nbitems' {
|
||||
tempvar imp`i' tmp`i'
|
||||
if "`method'"=="pms"|"`method'"=="bip"|"`method'"=="cim"|"`method'"=="bic" {
|
||||
qui egen `imp`i''=rowtotal(`varlist') `ifif'
|
||||
qui egen `tmp`i''=rownonmiss(`varlist') `ifif'
|
||||
qui replace `imp`i''=`imp`i''/`tmp`i'' `ifif'
|
||||
qui replace `imp`i''=``i'' if ``i''!=.&`if'
|
||||
if "`method'"=="pms"&"`round'"=="" {
|
||||
qui replace `imp`i''=round(`imp`i'') `ifif'
|
||||
}
|
||||
else if "`method'"=="bip" {
|
||||
qui replace `imp`i''=uniform()<`imp`i'' `ifif'
|
||||
}
|
||||
else if "`method'"=="cim"|"`method'"=="bic"{
|
||||
qui replace `imp`i''=`imp`i''*`tmp`i''*`mean`i'' `ifif'
|
||||
qui replace `tmp`i''=0 `ifif'
|
||||
forvalues j=1/`nbitems' {
|
||||
qui replace `tmp`i''=`tmp`i''+`mean`j'' if ``j''!=.&`if'
|
||||
}
|
||||
qui replace `imp`i''=`imp`i''/`tmp`i'' `ifif'
|
||||
qui replace `imp`i''=1 if `imp`i''>1&`imp`i''!=.&`if'
|
||||
qui replace `imp`i''=0 if `imp`i''<0&`imp`i''!=.&`if'
|
||||
if "`method'"=="cim"&"`round'"=="" {
|
||||
qui replace `imp`i''=round(`imp`i'') `ifif'
|
||||
}
|
||||
else if "`method'"=="bic" {
|
||||
qui replace `imp`i''=uniform()<`imp`i'' `ifif'
|
||||
}
|
||||
}
|
||||
}
|
||||
else if "`method'"=="ims"|"`method'"=="bii" {
|
||||
qui gen `imp`i''=`mean`i'' `ifif'
|
||||
if "`method'"=="ims"&"`round'"=="" {
|
||||
qui replace `imp`i''=round(`imp`i'') `ifif'
|
||||
}
|
||||
else if "`method'"=="bii" {
|
||||
qui replace `imp`i''=uniform()<`imp`i'' `ifif'
|
||||
}
|
||||
}
|
||||
else if "`method'"=="ics" {
|
||||
local item=0
|
||||
local corrmax=-2
|
||||
forvalues j=1/`nbitems' {
|
||||
if `i'!=`j' {
|
||||
qui corr ``i'' ``j'' `ifif'
|
||||
if r(rho)>`corrmax'&r(rho)!=. {
|
||||
local item `j'
|
||||
local corrmax=r(rho)
|
||||
}
|
||||
}
|
||||
}
|
||||
di "A missing value for the item ``i'' is replaced by the value of the item `item'"
|
||||
qui gen `imp`i''=``i'' `ifif'
|
||||
qui replace `imp`i''=``item'' if ``i''==.&`if'
|
||||
}
|
||||
else if "`method'"=="log"|"`method'"=="bil" {
|
||||
local liste`i'
|
||||
forvalues j=1/`nbitems' {
|
||||
if `i'!=`j' {
|
||||
local liste`i' `liste`i'' ``j''
|
||||
}
|
||||
}
|
||||
qui sw ,pr(0.05): logit ``i'' `liste`i'' `ifif'
|
||||
*local select :colnames e(b)
|
||||
local select=substr("`:colnames e(b)'",1,length("`:colnames e(b)'")-5)
|
||||
qui logit ``i'' `select' `ifif'
|
||||
qui predict `imp`i'' `ifif'
|
||||
if "`method'"=="log"&"`round'"=="" {
|
||||
qui replace `imp`i''=round(`imp`i'') if `imp`i''!=.&`if'
|
||||
}
|
||||
else if "`method'"=="bil" {
|
||||
qui replace `imp`i''=uniform()<`imp`i'' if `imp`i''!=.&`if'
|
||||
}
|
||||
}
|
||||
else if "`method'"=="worst" {
|
||||
qui gen `imp`i''=0 `ifif'
|
||||
}
|
||||
}
|
||||
forvalues i=1/`nbitems' {
|
||||
qui replace `imp`i''=``i'' if ``i''!=.&`if'
|
||||
if "`prefix'"=="" {
|
||||
local prefix imp
|
||||
}
|
||||
qui gen `prefix'``i''=`imp`i'' `ifif'
|
||||
}
|
||||
|
||||
tempvar miss
|
||||
qui egen `miss'=rowmiss(`varlist')
|
||||
forvalues i=1/`nbitems' {
|
||||
qui replace `prefix'``i''=. if ``i''==.&`miss'>`max'
|
||||
}
|
||||
|
||||
end
|
135
Modules/ado/personal/i/imputemok.ado
Normal file
135
Modules/ado/personal/i/imputemok.ado
Normal file
@ -0,0 +1,135 @@
|
||||
*! version 2.1 24 November 2008
|
||||
*! Jean-Benoit Hardouin
|
||||
************************************************************************************************************
|
||||
* impmok: Imputation of missing data by a Mokken model
|
||||
*
|
||||
* Version 1 : November 25, 2006 (Jean-Benoit Hardouin) /*Dichotomous data*/
|
||||
* Version 2 : June 30, 2008 (Jean-Benoit Hardouin) /*MAX option*/
|
||||
* Version 2.1 : November 24, 2008 (Jean-Benoit Hardouin) /*correction of a bug with the MAX option*/
|
||||
*
|
||||
* Jean-benoit Hardouin, Faculty of Pharmaceutical Sciences - University of Nantes - France
|
||||
* jean-benoit.hardouin@univ-nantes.fr
|
||||
*
|
||||
* News about this program : http://anaqol.free.fr
|
||||
* FreeIRT Project : http://freeirt.free.fr
|
||||
*
|
||||
* Copyright 2006, 2008 Jean-Benoit Hardouin
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
************************************************************************************************************/
|
||||
|
||||
|
||||
program define imputemok , rclass
|
||||
version 9
|
||||
syntax varlist(min=2 numeric) [, PREFix(string) max(int 0)]
|
||||
|
||||
local nbitems : word count `varlist'
|
||||
tokenize `varlist'
|
||||
if `max'==0 {
|
||||
local max=`nbitems'
|
||||
}
|
||||
|
||||
|
||||
|
||||
tempname p
|
||||
matrix `p'=J(3,`nbitems',0)
|
||||
forvalues i=1/`nbitems' {
|
||||
qui su ``i''
|
||||
if `r(min)'!=0&`r(max)'!=1 {
|
||||
di in red "The -impmok- command runs only with dichotomous items"
|
||||
error
|
||||
}
|
||||
local p`i'=r(mean)
|
||||
matrix `p'[1,`i']=`i'
|
||||
}
|
||||
|
||||
forvalues place=1/`nbitems' {
|
||||
local pmax=0
|
||||
local itemax=0
|
||||
forvalues i=1/`nbitems' {
|
||||
local t=`p'[1,`i']
|
||||
if `p`i''>`pmax'&`t'!=0 {
|
||||
local pmax=`p`i''
|
||||
local itemax=`i'
|
||||
}
|
||||
}
|
||||
matrix `p'[1,`itemax']=0
|
||||
matrix `p'[2,`place']=`itemax'
|
||||
matrix `p'[3,`place']=`pmax'
|
||||
}
|
||||
local liste
|
||||
forvalues i=1/`nbitems' {
|
||||
local t=`p'[2,`i']
|
||||
local liste "`liste' ``t''"
|
||||
tempname imp`i'
|
||||
qui gen `imp`i''`i'=``i''
|
||||
}
|
||||
forvalues j=`=`nbitems'-1'(-1)1 {
|
||||
local i=`p'[2,`j']
|
||||
local suiv=`p'[2,`=`j'+1']
|
||||
qui replace `imp`i''`i'=1 if `imp`suiv''`suiv'==1&`imp`i''`i'==.
|
||||
}
|
||||
forvalues j=2/`nbitems'{
|
||||
local i=`p'[2,`j']
|
||||
local prec=`p'[2,`=`j'-1']
|
||||
qui replace `imp`i''`i'=0 if `imp`prec''`prec'==0&`imp`i''`i'==.
|
||||
}
|
||||
forvalues j=1/`nbitems' {
|
||||
local i=`p'[2,`j']
|
||||
local suiv=`p'[2,`=`j'+1']
|
||||
local prec=`p'[2,`=`j'-1']
|
||||
tempname prec0`i' prec1`i'
|
||||
qui gen `prec0`i''=0
|
||||
qui gen `prec1`i''=0
|
||||
if `j'!=1 {
|
||||
qui replace `prec0`i''=`prec0`prec''+1 if `imp`prec''`prec'==0
|
||||
qui replace `prec0`i''=`prec0`prec'' if `imp`prec''`prec'!=0
|
||||
qui replace `prec1`i''=`prec1`prec''+1 if `imp`prec''`prec'==1
|
||||
qui replace `prec1`i''=`prec1`prec'' if `imp`prec''`prec'!=1
|
||||
qui replace `imp`i''`i'=0 if `prec0`i''!=0&`prec0`i''>=`prec1`i''&`imp`i''`i'==.
|
||||
}
|
||||
}
|
||||
forvalues j=`nbitems'(-1)1 {
|
||||
local i=`p'[2,`j']
|
||||
local suiv=`p'[2,`=`j'+1']
|
||||
local prec=`p'[2,`=`j'-1']
|
||||
tempname suiv0`i' suiv1`i'
|
||||
qui gen `suiv0`i''=0
|
||||
qui gen `suiv1`i''=0
|
||||
if `j'!=`nbitems' {
|
||||
qui replace `suiv0`i''=`suiv0`suiv''+1 if `imp`suiv''`suiv'==0
|
||||
qui replace `suiv0`i''=`suiv0`suiv'' if `imp`suiv''`suiv'!=0
|
||||
qui replace `suiv1`i''=`suiv1`suiv''+1 if `imp`suiv''`suiv'==1
|
||||
qui replace `suiv1`i''=`suiv1`suiv'' if `imp`suiv''`suiv'!=1
|
||||
qui replace `imp`i''`i'=1 if `suiv0`i''<=`suiv1`i''&`suiv1`i''!=0&`imp`i''`i'==.
|
||||
}
|
||||
}
|
||||
forvalues j=1/`nbitems' {
|
||||
local i=`p'[2,`j']
|
||||
qui replace `imp`i''`i'=uniform()<=`p`i'' if `imp`i''`i'==.
|
||||
if "`prefix'"=="" {
|
||||
local prefix imp
|
||||
}
|
||||
qui gen `prefix'``i''=`imp`i''`i'
|
||||
}
|
||||
|
||||
|
||||
tempvar miss
|
||||
qui egen `miss'=rowmiss(`varlist')
|
||||
forvalues i=1/`nbitems' {
|
||||
qui replace `prefix'``i''=. if ``i''==.&`miss'>`max'
|
||||
}
|
||||
|
||||
end
|
58
Modules/ado/personal/i/imputemok.hlp
Normal file
58
Modules/ado/personal/i/imputemok.hlp
Normal file
@ -0,0 +1,58 @@
|
||||
{smcl}
|
||||
{* 30June2008}{...}
|
||||
{hline}
|
||||
help for {hi:imputemok}{right:Jean-Benoit Hardouin}
|
||||
{hline}
|
||||
|
||||
{title:Imputation of missing item responses with the Mokken scaling}
|
||||
|
||||
{p 8 14 2}{cmd:imputemok} {it:varlist} [,{cmdab:pref:ix}({it:string}) {cmdab:max}({it:#})]
|
||||
|
||||
|
||||
{title:Description}
|
||||
|
||||
{p 4 4 2}{cmd:imputemok} imputes missing item responses with the Mokken scaling as defined in Huisman and Molenaar (2001). This module runs only with dichotomous items.
|
||||
|
||||
{p 4 4 2}The following algorithm is used:
|
||||
|
||||
{p 8 4 2}First, the items are ordered according to the percentage of positive responses (in a decreasing order).
|
||||
|
||||
{p 8 4 2}For each individual, if a positive response follows a missing response, it is imputed to 1.
|
||||
|
||||
{p 8 4 2}Else if a negative response precedes a missing response, it is imputed to 0.
|
||||
|
||||
{p 8 4 2}Else we count the number of positive and negative responses preceding a missing response and if the number of negative response is larger or equal than the number of positive responses, the missing value is imputed to 0.
|
||||
|
||||
{p 8 4 2}Else we count the number of positive and negative responses following a missing response and if the number of positive response is larger or equal than the number of negative responses, the missing value is imputed to 1.
|
||||
|
||||
{p 8 4 2}Else, the missing value is imputed by drawing a random number based on the observed proportion of positive responses to the item.
|
||||
|
||||
{title:Options}
|
||||
|
||||
{p 4 8 2}{cmd:prefix} defines the prefix to use to name the imputted variables (this prefix is followed by the name of the initial variable). By default, this prefix is "imp".
|
||||
|
||||
{p 4 8 2}{cmd:max} allows imputing missing values only for individuals with a maximal number of missing values defined with this option.
|
||||
|
||||
{title:Example}
|
||||
|
||||
{cmd:. imputemok itemA*}
|
||||
|
||||
{cmd:. imputemok itemA*,prefix(new)}
|
||||
|
||||
|
||||
{title:Reference}
|
||||
|
||||
{p 4 8 2}{cmd:Huisman M. and Molenaar I. W.}, {it:Imputation of missing scale data with item response models}. In A. Boomsma, M.A.J. van Duijn, & T.A.B. Snijders (Eds.), {it: Essays on item response theory} (pp. 221-244).
|
||||
New York: Springer-Verlag, 2001.
|
||||
|
||||
{title:Author}
|
||||
|
||||
{p 4 8 2}Jean-Benoit Hardouin, PhD, assistant professor{p_end}
|
||||
{p 4 8 2}EA 4275 "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}
|
146
Modules/ado/personal/i/imputerasch.ado
Normal file
146
Modules/ado/personal/i/imputerasch.ado
Normal file
@ -0,0 +1,146 @@
|
||||
*! version 2 30 June 2008
|
||||
*! Jean-Benoit Hardouin
|
||||
************************************************************************************************************
|
||||
* imputerasch: Imputation of missing data by a Rasch model
|
||||
*
|
||||
* Version 1 : November 25, 2006 (Jean-Benoit Hardouin) /*Dichotomous data*/
|
||||
* Version 1.1 : January 26, 2007 (Jean-Benoit Hardouin) /*Correction of a bug with the Binomial option*/
|
||||
* Version 2 : June 30, 2008 (Jean-Benoit Hardouin) /*norandom option, max option*/
|
||||
*
|
||||
* Jean-benoit Hardouin, Faculty of Pharmaceutical Sciences - University of Nantes - France
|
||||
* jean-benoit.hardouin@univ-nantes.fr
|
||||
*
|
||||
* News about this program : http://www.anaqol.org
|
||||
* FreeIRT Project : http://www.freeirt.org
|
||||
*
|
||||
* Copyright 2006-2008 Jean-Benoit Hardouin
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
************************************************************************************************************/
|
||||
|
||||
|
||||
program define imputerasch
|
||||
version 9
|
||||
syntax varlist(min=2 numeric) [, PREFix(string) noBINomial noRANDom SAVEProba(string) NBITeration(integer 1) DETails MAX(int 0) ]
|
||||
preserve
|
||||
qui ds
|
||||
local order=r(varlist)
|
||||
local nbitems : word count `varlist'
|
||||
tokenize `varlist'
|
||||
|
||||
if `max'==0 {
|
||||
local max=`nbitems'
|
||||
}
|
||||
|
||||
if "`random'"!="" {
|
||||
local binomial nobinomial
|
||||
}
|
||||
|
||||
if "`binomial'"==""&`nbiteration'!=1 {
|
||||
local binomial nobinomial
|
||||
di in green "You must use the {hi:norandom} option when you use iterative process. This option is assumed."
|
||||
}
|
||||
|
||||
if `nbiteration'!=1 {
|
||||
di in ye "Iteration : 1"
|
||||
}
|
||||
|
||||
tempvar lt0 lt1 score id item lt name
|
||||
qui gen `id'=_n
|
||||
qui egen `score'=rowtotal(`varlist')
|
||||
forvalues i=1/`nbitems' {
|
||||
qui rename ``i'' `name'`i'
|
||||
}
|
||||
|
||||
qui reshape long `name' ,i(`id') j(`item')
|
||||
forvalues i=1/`nbitems' {
|
||||
qui gen ``i''=`item'==`i'
|
||||
}
|
||||
qui gllamm `name' `varlist' ,family(bin) nocons link(logit) i(`id') it(1)
|
||||
qui gllapred `lt' ,u
|
||||
qui bysort `id':egen `lt'=min(`lt'm1)
|
||||
drop `lt's1 `lt'm1
|
||||
tempname diff
|
||||
matrix `diff'=e(b)
|
||||
drop `varlist'
|
||||
qui reshape wide `name' ,i(`id') j(`item')
|
||||
forvalues i=1/`nbitems' {
|
||||
qui rename `name'`i' ``i''
|
||||
tempvar imp`i'
|
||||
local diff`i'=`diff'[1,`i']
|
||||
qui gen `imp`i''=exp(`lt'-`diff`i'')/(1+exp(`lt'-`diff`i''))
|
||||
if "`saveproba'"!="" {
|
||||
qui gen `saveproba'``i''=`imp`i''
|
||||
}
|
||||
if "`binomial'"!="" {
|
||||
qui replace `imp`i''=round(`imp`i'')
|
||||
}
|
||||
else {
|
||||
qui replace `imp`i''=uniform()<`imp`i''
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
restore,not
|
||||
forvalues i=1/`nbitems' {
|
||||
qui replace `imp`i''=``i'' if ``i''!=.
|
||||
if "`prefix'"=="" {
|
||||
local prefix imp
|
||||
}
|
||||
qui gen `prefix'``i''=`imp`i''
|
||||
}
|
||||
|
||||
if "`details'"!="" {
|
||||
forvalues i=1/`nbitems' {
|
||||
qui count if ``i''==.
|
||||
local nbmiss`i'=r(N)
|
||||
di in ye "``i'':" in gr " Number of missing data: " in ye "`nbmiss`i''"
|
||||
}
|
||||
}
|
||||
if `nbiteration'>1 {
|
||||
local flag=0
|
||||
local it=2
|
||||
tempname p new
|
||||
while `flag'!=1&`it'<=`nbiteration' {
|
||||
di in ye "Iteration : `it'"
|
||||
imputerasch `prefix'`1'-`prefix'``nbitems'', savep(`p') prefix(`new') nobin
|
||||
local flag=1
|
||||
forvalues i=1/`nbitems' {
|
||||
qui replace `new'`prefix'``i''=round(`p'`prefix'``i'') if ``i''==.
|
||||
qui corr `prefix'``i'' `new'`prefix'``i''
|
||||
local rho=round(r(rho)*1000000)
|
||||
qui count if `prefix'``i''==`new'`prefix'``i''&``i''==.
|
||||
qui count if ``i''==.
|
||||
local nbmiss`i'=r(N)
|
||||
local coher=r(N)
|
||||
local txcoher=`coher'/`nbmiss`i''*100
|
||||
di in ye "``i'':" in gr " Coherence rate between iterations `it' and `=`it'-1': " in ye %6.2f `txcoher' in gr "%"
|
||||
if int(`txcoher')!=100 {
|
||||
local flag=0
|
||||
}
|
||||
qui replace `prefix'``i''=`new'`prefix'``i''
|
||||
}
|
||||
drop `p'`prefix'`1'-`p'`prefix'``nbitems'' `new'`prefix'`1'-`new'`prefix'``nbitems''
|
||||
local ++it
|
||||
}
|
||||
}
|
||||
|
||||
tempvar miss
|
||||
qui egen `miss'=rowmiss(`varlist')
|
||||
forvalues i=1/`nbitems' {
|
||||
qui replace `prefix'``i''=. if ``i''==.&`miss'>`max'
|
||||
}
|
||||
|
||||
end
|
63
Modules/ado/personal/i/imputerasch.hlp
Normal file
63
Modules/ado/personal/i/imputerasch.hlp
Normal file
@ -0,0 +1,63 @@
|
||||
{smcl}
|
||||
{* 30june2008}{...}
|
||||
{hline}
|
||||
help for {hi:imputerasch}{right:Jean-Benoit Hardouin}
|
||||
{hline}
|
||||
|
||||
{title:Imputation of missing binary variables by a Rasch model}
|
||||
|
||||
{p 8 14 2}{cmd:imputerasch} {it:varlist} [{cmd:,} {cmdab:pref:ix}({it:string}) {cmdab:noran:dom} {cmdab:savep:roba}({it:string}) {cmdab:nbit:eration}({it:#}) {cmdab:det:ails} {cmdab:max}({it:#})]
|
||||
|
||||
{p 8 14 2}{it:varlist} is a list of two or more existing dichotomous variables.
|
||||
|
||||
{title:Description}
|
||||
|
||||
{p 4 8 2}{cmd:imputerasch} imputes missing binary data by a Rasch model.
|
||||
The parameters of the Rasch model are estimated on complete data, then the missing data are imputed from the estimated probability
|
||||
for each individual to response to each item.
|
||||
By default, the imputed value is a result of a random draw within a Bernouilli random variable with this probability used like
|
||||
parameter, but it is possible to affect more deterministically the value of the missing data (0 if p<0.5 and 1 if p>=.5) with
|
||||
the {cmd:norandom} option.
|
||||
An iterative procedure can be run in a second time by estimating parameters of the Rasch model on existing and imputing data,
|
||||
and by eventually correcting missing data at each step (see the {cmd:nbiteration} option).
|
||||
This procedure is stopped as soon the allowed maximal number of iterations is attained, or as soon the imputed values are stable.
|
||||
|
||||
{title:Options}
|
||||
|
||||
{p 4 8 2}{cmd:prefix}. The former variables (with missing data) are keeped. New variables are created by imputing new values to missing data.
|
||||
The name of these new variables are the names of the former variables preeceded by the prefix defined in this option. By default, this prefix is "imp".
|
||||
|
||||
{p 4 8 2}{cmd:norandom} avoids to randomly draw the value of imputation (by default). A deterministic process is used : if the expected probability is <0.5, imputed value is 0, else imputed value is 1
|
||||
(the old name of this option, {cmd:nobinomial}, continues to run).
|
||||
|
||||
{p 4 8 2}{cmd:saveproba} allows saving the expected probability in variables whose the names begin by the string defined in this option.
|
||||
|
||||
{p 4 8 2}{cmd:nbiteration} realizes an iterative procedure which is stopped as soon as the maximal number of iterations is attained, or as soon as the imputed data are stable.
|
||||
|
||||
{p 4 8 2}{cmd:details} gives details on the imputation.
|
||||
|
||||
{p 4 8 2}{cmd:max} allows imputing missing values only for individuals with a maximal number of missing values defined with this option.
|
||||
|
||||
|
||||
|
||||
{title:Example}
|
||||
|
||||
{inp:. imputerasch item*}
|
||||
|
||||
{inp:. imputerasch item*, norandom saveproba(p) prefix(dataimputed) max(4)}
|
||||
|
||||
{inp:. imputerasch item1-item5, nbiteration(5) details}
|
||||
|
||||
|
||||
{title:Author}
|
||||
|
||||
{p 4 8 2}Jean-Benoit Hardouin, PhD, assistant professor{p_end}
|
||||
{p 4 8 2}EA 4275 "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}
|
||||
|
414
Modules/ado/personal/i/irtpoly.ado
Normal file
414
Modules/ado/personal/i/irtpoly.ado
Normal file
@ -0,0 +1,414 @@
|
||||
program define irtpoly,eclass
|
||||
version 11.0
|
||||
syntax varlist(min=3 numeric) [if] [in] [,test Graph group(string) latent(string) REPlace Fixed(string) FIXEDVar(real -1) rsm rasch Last SASOUTput long Covariables(varlist) Covariablemean(varname) noCentered Project(string)]
|
||||
preserve
|
||||
|
||||
|
||||
capture mkdir "c:/data/irtpoly//`project'/"
|
||||
if !_rc {
|
||||
di in green "The directory c:/data/irtpoly//`project' has been created"
|
||||
}
|
||||
|
||||
local dir="c:/data/irtpoly//`project'/"
|
||||
local savegroup=1
|
||||
if "`group'"=="" {
|
||||
tempname group
|
||||
local savegroup=0
|
||||
}
|
||||
local savelatent=1
|
||||
if "`latent'"=="" {
|
||||
tempname latent
|
||||
local savelatent=0
|
||||
}
|
||||
tempvar order
|
||||
gen `order'=_n
|
||||
tempfile pcmsasfile
|
||||
qui save `pcmsasfile'
|
||||
qui count `if' `in'
|
||||
local nbind=r(N)
|
||||
tokenize `varlist'
|
||||
local nbitems:word count `varlist'
|
||||
local max=0
|
||||
forvalues i=1/`nbitems' {
|
||||
qui su ``i''
|
||||
local max`i'=r(max)
|
||||
if `max`i''>`max' {
|
||||
local max=`max`i''
|
||||
}
|
||||
}
|
||||
tempname freq
|
||||
contract `varlist' `covariables' `covariablemean', freq(`freq')
|
||||
qui sort `varlist'
|
||||
qui outsheet `varlist' `covariables' `covariablemean' `freq' using "`dir'irtpoly_data.txt",replace
|
||||
|
||||
drop _all
|
||||
if "`fixed'"!="" {
|
||||
capture confirm matrix `fixed'
|
||||
if _rc {
|
||||
di as error "The {hi:`fixed'} matrix does not exist"
|
||||
error 198
|
||||
}
|
||||
tempname matfix
|
||||
matrix `matfix'=`fixed''
|
||||
qui svmat `matfix'
|
||||
qui rename `matfix'1 estimate
|
||||
qui gen parameter=""
|
||||
order parameter estimate
|
||||
local l=1
|
||||
forvalues j=1/`nbitems' {
|
||||
forvalues m=1/`max`j'' {
|
||||
if "`rasch'"=="" {
|
||||
qui replace parameter="beta``j''_`m'" in `l'
|
||||
}
|
||||
else {
|
||||
qui replace parameter="beta``j''" in `l'
|
||||
}
|
||||
local ++l
|
||||
}
|
||||
}
|
||||
qui outsheet using "`dir'/irtpoly_fixedparameters.txt",replace
|
||||
|
||||
}
|
||||
drop _all
|
||||
qui set obs 1000
|
||||
qui generate str txt="%include 'C:\ado\macros SAS\anaqolv48.sas';" in 1
|
||||
qui replace txt="%include 'C:\Documents and Settings\Jean-Benoit Hardouin\Mes documents\Boulot JB\Enseignement\ENSAI\2009-2010\macros\gammasymv1.sas';" in 2
|
||||
qui replace txt="PROC IMPORT OUT=WORK.data DATAFILE='`dir'irtpoly_data.txt' DBMS=TAB REPLACE;GETNAMES=YES;DATAROW=2; RUN;" in 3
|
||||
if "`fixed'"!="" {
|
||||
qui replace txt="PROC IMPORT OUT=WORK.fixed DATAFILE='`dir'irtpoly_fixedparameters.txt' DBMS=TAB REPLACE;GETNAMES=YES;DATAROW=2; RUN;" in 4
|
||||
}
|
||||
local txt="%anaqol(DATASET=data,ITEMS=`varlist',DETAILS=yes,WEIGHT=`freq',MODEL="
|
||||
if "`rsm'"==""&"`rasch'"=="" {
|
||||
local txt `txt'pcm
|
||||
}
|
||||
else if "`rasch'"!="" {
|
||||
local txt `txt'rasch, TEST=no
|
||||
}
|
||||
else {
|
||||
local txt `txt'rsm
|
||||
}
|
||||
if "`fixed'"!="" {
|
||||
local txt `txt',FIXED=fixed
|
||||
}
|
||||
if `fixedvar'>0 {
|
||||
local txt `txt',FIXEDVAR=`fixedvar'
|
||||
}
|
||||
if "`fixed'"!=""&"`fixedvar'"!="" {
|
||||
local centered nocentered
|
||||
}
|
||||
if "`centered'"!="" {
|
||||
local txt `txt',CENTERED=yes
|
||||
}
|
||||
if "`covariables'"!="" {
|
||||
local txt `txt',COVARIABLES=`covariables'
|
||||
}
|
||||
if "`covariablemean'"!="" {
|
||||
local txt `txt',COVARIABLEMEAN=`covariablemean'
|
||||
}
|
||||
local txt `txt');
|
||||
qui replace txt="`txt'" in 10
|
||||
qui replace txt="PROC EXPORT DATA= WORK.Out_parameters OUTFILE='`dir'irtpoly_parameters.txt' DBMS=TAB REPLACE;RUN;" in 11
|
||||
qui replace txt="PROC EXPORT DATA= WORK.Out_latent OUTFILE='`dir'irtpoly_latent.txt' DBMS=TAB REPLACE;RUN;" in 12
|
||||
qui replace txt="PROC EXPORT DATA= WORK.Out_rep OUTFILE='`dir'irtpoly_rep.txt' DBMS=TAB REPLACE;RUN;" in 13
|
||||
qui replace txt="PROC EXPORT DATA= WORK.Out_fit OUTFILE='`dir'irtpoly_fit.txt' DBMS=TAB REPLACE;RUN;" in 14
|
||||
|
||||
qui outsheet txt using "`dir'irtpoly_pgmsas.txt", replace nonames noquote
|
||||
|
||||
if "`last'"=="" {
|
||||
/*local date=c(current_date)
|
||||
local jour=substr("`date'",1,2)
|
||||
local mois=substr("`date'",4,3)
|
||||
local an=substr("`date'",8,4)
|
||||
if "`mois'"=="Jan" {local moisd 01}
|
||||
if "`mois'"=="Feb" {local moisd 02}
|
||||
if "`mois'"=="Mar" {local moisd 03}
|
||||
if "`mois'"=="Apr" {local moisd 04}
|
||||
if "`mois'"=="May" {local moisd 05}
|
||||
if "`mois'"=="Jun" {local moisd 06}
|
||||
if "`mois'"=="Jul" {local moisd 07}
|
||||
if "`mois'"=="Aug" {local moisd 08}
|
||||
if "`mois'"=="Sep" {local moisd 09}
|
||||
if "`mois'"=="Oct" {local moisd 10}
|
||||
if "`mois'"=="Nov" {local moisd 11}
|
||||
if "`mois'"=="Dec" {local moisd 12}
|
||||
di "`jour' `mois' `an' `moisd'"
|
||||
shell "date" "01/01/2009"
|
||||
*/
|
||||
if "`long'"!=""{
|
||||
local cmd winexec
|
||||
}
|
||||
else {
|
||||
local cmd shell
|
||||
}
|
||||
`cmd' "C:\Program Files\SAS\SAS 9.2\SASFoundation\9.2\sas.exe" "`dir'irtpoly_pgmsas.txt" -print "`dir'irtpoly_pgmsas.lst" -nolog
|
||||
*shell "cmd.exe" "date `jour'/`moid'/`an'"
|
||||
if "`long'"!="" {
|
||||
exit
|
||||
}
|
||||
|
||||
}
|
||||
if "`sasoutput'"!="" {
|
||||
view "`dir'irtpoly_pgmsas.lst"
|
||||
}
|
||||
*set trace on
|
||||
|
||||
*set trace on
|
||||
drop _all
|
||||
qui insheet using "`dir'irtpoly_fit.txt"
|
||||
qui su value if descr=="-2 Log Likelihood"
|
||||
local m2ll=r(mean)
|
||||
local ll=-`m2ll'/2
|
||||
qui su value if descr=="AIC (smaller is better)"
|
||||
local aic=r(mean)
|
||||
qui su value if descr=="BIC (smaller is better)"
|
||||
local bic=r(mean)
|
||||
|
||||
drop _all
|
||||
qui insheet using "`dir'irtpoly_parameters.txt"
|
||||
tempname parameters separameters
|
||||
qui su estimate if parameter=="var"
|
||||
local variance=r(mean)
|
||||
qui su standarderror if parameter=="var"
|
||||
local sevariance=r(mean)
|
||||
*set trace on
|
||||
local nbcov:word count `covariables'
|
||||
forvalues i=1/`nbcov' {
|
||||
local cov`i':word `i' of `covariables'
|
||||
qui su estimate if parameter=="beta`cov`i''"
|
||||
local betacov`i'=r(mean)
|
||||
qui su standarderror if parameter=="beta`cov`i''"
|
||||
local secov`i'=r(mean)
|
||||
}
|
||||
*set trace off
|
||||
*su
|
||||
di in gr "Number of individuals: " in ye `nbind'
|
||||
di in gr "Number of items: " in ye `nbitems'
|
||||
di in gr "log-likelihood: " in ye %10.4f `ll'
|
||||
di in gr "AIC: " in ye %10.4f `aic'
|
||||
di in gr "BIC: " in ye %10.4f `bic'
|
||||
di
|
||||
di
|
||||
if "`rsm'"=="" {
|
||||
matrix `parameters'=J(`nbitems',`max',0)
|
||||
matrix `separameters'=J(`nbitems',`max',0)
|
||||
local l=1
|
||||
|
||||
forvalues i=1/`nbitems' {
|
||||
forvalues j=1/`max`i'' {
|
||||
if "`fixed'"=="" {
|
||||
qui su estimate if parameter=="beta``i''_`j'"
|
||||
matrix `parameters'[`i',`j']=r(mean)
|
||||
qui su standarderror if parameter=="beta``i''_`j'"
|
||||
matrix `separameters'[`i',`j']=r(mean)
|
||||
}
|
||||
else {
|
||||
matrix `parameters'[`i',`j']=`fixed'[1,`l']
|
||||
}
|
||||
local ++l
|
||||
}
|
||||
}
|
||||
di in gr "{hline 52}"
|
||||
di in gr "Items" _col(18) "Modality" _col(30) "Estimate" _col(39) "Standard error"
|
||||
di in gr "{hline 52}"
|
||||
forvalues j=1/`nbitems' {
|
||||
di in gr "``j''" _c
|
||||
forvalues m=1/`max`i'' {
|
||||
di _col(25) in gr `m' _col(30) %8.4f in ye `parameters'[`j',`m'] _col(45) %8.4f in ye `separameters'[`j',`m']
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
matrix `parameters'=J(`=`nbitems'+`max'-1',1,0)
|
||||
matrix `separameters'=J(`=`nbitems'+`max'-1',1,0)
|
||||
local l=1
|
||||
if "`fixed'"=="" {
|
||||
forvalues i=1/`nbitems' {
|
||||
qui su estimate if parameter=="beta``i''"
|
||||
matrix `parameters'[`i',1]=r(mean)
|
||||
qui su standarderror if parameter=="beta``i''"
|
||||
matrix `separameters'[`i',1]=r(mean)
|
||||
local ++l
|
||||
}
|
||||
forvalues l=`=`nbitems'+1'/`=`nbitems'+`max'-1' {
|
||||
local m=`l'-`nbitems'+1
|
||||
qui su estimate if parameter=="t`m'"
|
||||
matrix `parameters'[`l',1]=r(mean)
|
||||
local tau`m'=r(mean)
|
||||
qui su standarderror if parameter=="t`m'"
|
||||
matrix `separameters'[`l',1]=r(mean)
|
||||
}
|
||||
}
|
||||
else {
|
||||
matrix `parameters'=`fixed'
|
||||
}
|
||||
di in gr "{hline 52}"
|
||||
di in gr "Items" _col(30) "Estimate" _col(39) "Standard error"
|
||||
di in gr "{hline 52}"
|
||||
forvalues j=1/`nbitems' {
|
||||
di in gr "``j''" _col(30) %8.4f in ye `parameters'[`j',1] _col(45) %8.4f in ye `separameters'[`j',1]
|
||||
}
|
||||
forvalues l=`=`nbitems'+1'/`=`nbitems'+`max'-1' {
|
||||
di in gr "tau`=`l'-`nbitems''" _col(30) %8.4f in ye `parameters'[`l',1] _col(45) %8.4f in ye `separameters'[`l',1]
|
||||
}
|
||||
}
|
||||
di in gr "{hline 52}"
|
||||
di in gr "Variance" _col(30) %8.4f in ye `variance' _col(45) %8.4f in ye `sevariance'
|
||||
di in gr "{hline 52}"
|
||||
forvalues i=1/`nbcov' {
|
||||
di in gr "`cov`i''" _col(30) %8.4f in ye `betacov`i'' _col(45) %8.4f in ye `secov`i''
|
||||
}
|
||||
if "`covariables'"!="" {
|
||||
di in gr "{hline 52}"
|
||||
}
|
||||
*matrix list `parameters'
|
||||
*fdsjklgvsjf
|
||||
|
||||
*set trace on
|
||||
|
||||
drop _all
|
||||
qui insheet using "`dir'irtpoly_rep.txt"
|
||||
qui sort anaqol_id
|
||||
qui sort `varlist' `covariables' `covariablemean'
|
||||
qui tempfile pcmsas
|
||||
qui rename theta `latent'
|
||||
qui rename stderrpred se`latent'
|
||||
qui save `pcmsas',replace
|
||||
qui use `pcmsasfile', clear
|
||||
qui sort `varlist'
|
||||
qui gen anaqol_id=_n
|
||||
qui sort anaqol_id
|
||||
qui sort `varlist' `covariables' `covariablemean'
|
||||
|
||||
/***********************************************
|
||||
qui merge 1:1 anaqol_id using "`pcmsas'",nogen
|
||||
***********************************************/
|
||||
qui merge m:1 `varlist' `covariables' `covariablemean' using "`pcmsas'",nogen
|
||||
|
||||
*tempvar group
|
||||
*set trace on
|
||||
forvalues i=1/`nbcov' {
|
||||
qui replace `latent'=`latent'+`betacov`i''*`cov`i''
|
||||
}
|
||||
*qui save `latent' using c:\latent.dta
|
||||
qui gengroup `latent', det replace continuous newvariable(`group')
|
||||
qui su `group'
|
||||
local nbgroup=r(max)
|
||||
forvalues g=1/`nbgroup' {
|
||||
qui count if `group'==`g'
|
||||
local group`g'=r(N)
|
||||
}
|
||||
forvalues i=1/`nbitems' {
|
||||
*set trace on
|
||||
tempname freq`i'
|
||||
qui tab `group' ``i'',matcell(`freq`i'') row nofreq m
|
||||
*matrix list `freq`i''
|
||||
forvalues g=1/`nbgroup' {
|
||||
qui count if `group'==`g'&``i''!=.
|
||||
local freq`g'_`i'=r(N)
|
||||
forvalues j=0/`max`i'' {
|
||||
matrix `freq`i''[`g',`=`j'+1']=`freq`i''[`g',`=`j'+1']/`freq`g'_`i''
|
||||
}
|
||||
}
|
||||
local D`i'=0
|
||||
forvalues j=0/`max`i'' {
|
||||
local D`i'_`j' exp(`j'*`latent'
|
||||
forvalues l=1/`j' {
|
||||
if "`rsm'"=="" {
|
||||
local D`i'_`j' `D`i'_`j''-`parameters'[`i',`l']
|
||||
}
|
||||
else {
|
||||
local D`i'_`j' `D`i'_`j''-`parameters'[`i',1]
|
||||
}
|
||||
}
|
||||
if "`rsm'"!="" {
|
||||
forvalues m=2/`j' {
|
||||
local D`i'_`j' `D`i'_`j''-`tau`m''
|
||||
}
|
||||
}
|
||||
local D`i'_`j' `D`i'_`j'')
|
||||
local D`i' `D`i''+`D`i'_`j''
|
||||
}
|
||||
}
|
||||
tempvar theta2
|
||||
qui gen `theta2'=0
|
||||
forvalues g=1/`nbgroup' {
|
||||
qui su `latent' if `group'==`g'
|
||||
local thetag`g'=r(mean)
|
||||
qui replace `theta2'=`thetag`g'' if `group'==`g'
|
||||
}
|
||||
local colors="blue red green gray pink purple"
|
||||
|
||||
*local chi2=0
|
||||
forvalues i=1/`nbitems' {
|
||||
local line`i'
|
||||
local scatter`i'
|
||||
tempvar propE``i'' propO``i''
|
||||
qui gen `propE``i'''=0
|
||||
qui gen `propO``i'''=0
|
||||
forvalues j=0/`max`i'' {
|
||||
local color:word `=`j'+1' of `colors'
|
||||
tempvar propE``i''_`j' propO``i''_`j'
|
||||
*matrix list `parameters'
|
||||
*di "qui gen `propE``i''_`j''=`D`i'_`j''/(`D`i'')"
|
||||
qui gen `propE``i''_`j''=`D`i'_`j''/(`D`i'')
|
||||
*su `propE``i''_`j''
|
||||
label variable `propE``i''_`j'' "Expected values / modality `j'"
|
||||
local line`i' `line`i'' (line `propE``i''_`j'' `latent', lcolor(`color') lwidth(thick))
|
||||
qui gen `propO``i''_`j''=0
|
||||
forvalues g=1/`nbgroup' {
|
||||
local tmp=`freq`i''[`g',`=`j'+1']
|
||||
qui replace `propO``i''_`j''=`tmp' if `group'==`g'
|
||||
}
|
||||
label variable `propO``i''_`j'' "Observed values / modality `j'"
|
||||
qui replace `propO``i'''=`propO``i'''+`j'*`propO``i''_`j''
|
||||
qui replace `propE``i'''=`propE``i'''+`j'*`propE``i''_`j''
|
||||
local scatter`i' `scatter`i'' (scatter `propO``i''_`j'' `theta2', mcolor(`color'))
|
||||
}
|
||||
qui sort `latent'
|
||||
if "`graph'"!="" {
|
||||
twoway `line`i'' `scatter`i'',name(``i'', replace)
|
||||
}
|
||||
label variable `propE``i''' "Expected values"
|
||||
label variable `propO``i''' "Observed values"
|
||||
if "`graph'"!="" {
|
||||
twoway (line `propE``i''' `latent', lcolor(green) lwidth(thick)) (scatter `propO``i''' `theta2',mcolor(green)),name(``i''2, replace)
|
||||
}
|
||||
*set trace on
|
||||
if "`test'"!="" {
|
||||
local chi2=0
|
||||
forvalues g=1/`nbgroup' {
|
||||
qui ttest `propE``i'''=`propO``i''' if `group'==`g'
|
||||
local t`g'=r(t)
|
||||
qui count if `group'==`g'
|
||||
local nb`g'=r(N)
|
||||
di "local chi2=`chi2'+/*`nb`g''**/(`t`g'')^2"
|
||||
local chi2=`chi2'+/*`nb`g''**/(`t`g'')^2
|
||||
}
|
||||
di "Chi-square statistics: " %8.4f `chi2'
|
||||
local pchi2=chi2(`=`nbgroup'-1',`chi2')
|
||||
di "p-values: " %8.4f `pchi2'
|
||||
}
|
||||
}
|
||||
*set trace on
|
||||
tempfile saveu
|
||||
qui keep `order' `latent' se`latent' `group'
|
||||
if `savegroup'==0 {
|
||||
drop `group'
|
||||
}
|
||||
if `savelatent'==0 {
|
||||
drop `latent'
|
||||
drop se`latent'
|
||||
}
|
||||
sort `order'
|
||||
qui save `saveu' ,replace
|
||||
|
||||
restore
|
||||
qui gen `order'=_n
|
||||
qui sort `order'
|
||||
if "`replace'"!="" {
|
||||
capture drop `group'
|
||||
capture drop `latent'
|
||||
capture drop se`latent'
|
||||
}
|
||||
qui merge 1:1 `order' using `saveu',nogen
|
||||
end
|
27
Modules/ado/personal/i/isvar.ado
Normal file
27
Modules/ado/personal/i/isvar.ado
Normal file
@ -0,0 +1,27 @@
|
||||
*! NJC 1.0.0 19 Sept 2005
|
||||
program isvar, rclass
|
||||
version 8
|
||||
syntax anything
|
||||
|
||||
foreach v of local anything {
|
||||
capture unab V : `v'
|
||||
if _rc == 0 local varlist `varlist' `V'
|
||||
else local badlist `badlist' `v'
|
||||
}
|
||||
|
||||
di
|
||||
|
||||
if "`varlist'" != "" {
|
||||
local n : word count `varlist'
|
||||
local what = plural(`n', "variable")
|
||||
di as txt "{p}`what': `varlist'{p_end}"
|
||||
return local varlist "`varlist'"
|
||||
}
|
||||
|
||||
if "`badlist'" != "" {
|
||||
local n : word count `badlist'
|
||||
local what = plural(`n', "not variable")
|
||||
di as txt "{p}`what': `badlist'{p_end}"
|
||||
return local badlist "`badlist'"
|
||||
}
|
||||
end
|
Reference in New Issue
Block a user