Estimation method: Conditional maximum likelihood (CML)

" } local nbtest=`nbgroups'-1 local line=77 } else if "`method'"=="mml"{ if "`html'" == "" { di in green "Estimation method: " in yellow "Marginal maximum likelihood (MML)" } else { di "

Estimation method: Marginal maximum likelihood (MML)

" } local nbtest=`nbgroups'+1 local line=70 } else if "`method'"=="gee" { di in green "Estimation method: " in yellow "Generalized Estimating Equations (GEE)" local nbtest=`nbgroups'+1 local line=70 } if "`test'"=="NONE" { local line=35 } if "`html'" == "" { di in green "Number of items: " in yellow `nbitems' di in green "Number of groups: " in yellow `=`nbgroups'+1' `conttest' if "`test'"!="NONE" { di in green " (" in yellow "`nbtest'" in green " of them are used to compute the statistics of test)" } } else { di "Number of items: " `nbitems' "
" di "Number of groups: " `=`nbgroups'+1' `conttest' if "`test'"!="NONE" { di " (`nbtest' of them are used to compute the statistics of test)" } di "
" } if "`method'"=="cml" { local nbind=`nbind'+`effscore0'+`effscore`nbgroups'' local cont "_c" matrix `itemfit'=J(`nbitems',6,0) } else { local cont matrix `itemfit'=J(`nbitems',5,0) } local missing=`N'-`nbind' if "`html'" == "" { di in green "Number of individuals: " in yellow `N' di in green "Number of individuals with missing values: " in yellow `nbindmiss' _c if "`ld'"=="" { di in green " (removed)" } else { di } di in green "Number of individuals with nul or perfect score: " in yellow `=`effscore0'+`effscore`nbgroups''' } else { di "Number of individuals: `N'
" di "Number of individuals with missing values: " `nbindmiss' if "`ld'"=="" { di " (removed)" } di "
" di "Number of individuals with nul or perfect score: " `=`effscore0'+`effscore`nbgroups''' "
" } if "`method'"=="cml" { if "`html'" == "" { di in green "Conditional log-likelihood: " in yellow %-13.4f `ll' di in green "Log-likelihood: " in yellow %-13.4f `globalll' } } else { if "`html'" == "" { di in green "Marginal log-likelihood: " in yellow %-13.4f `ll' di in green "Log-likelihood: " in yellow %-13.4f `globalll' di } else { di "Marginal log-likelihood: " %-13.4f `ll' "
" di "Log-likelihood: " %-13.4f `globalll' "

" } } if "`html'" == "" { noi di in green _col(16) "Difficulty" `conttest' if "`test'"!="NONE" { di in green _col(58) "Standardized" } noi di in green _col(9) "Items" _col(16) "parameters" _col(28) "std Err." `conttest' if "`test'"!="NONE" { local varin=int(2/sqrt(`nbind')*100)/100 local varout=int(6/sqrt(`nbind')*100)/100 di _col(41) "`namewp'" _col(47) "df" _col(50) "p-value" _col(58) "Outfit" _col(66) "Infit" `cont' if "`method'"=="cml" { di in green _col(77) "U" } } di in green "{hline `line'}" } else { di "" di "" di "" if "`test'"!="NONE" { di "" } di "" di "" if "`test'"!="NONE" { local varin=int(2/sqrt(`nbind')*100)/100 local varout=int(6/sqrt(`nbind')*100)/100 di "" if "`method'"=="cml" { di "" } } di "" } forvalues i=1/`nbitems' { if "`html'" == "" { noi di in yellow _col(3) %12s abbrev("``i''`fixed`i''" ,12) in yellow _col(18) %8.5f `beta`i'' _col(29) %6.5f `sd`i'' `conttest' } else { di "" } if "`test'"!="NONE" { if "`html'" == "" { di _col(36) %8.3f `testitems'[`i',1] _col(46) %3.0f `=`nbgroups'-2' _col(51) %6.4f 1-chi2(`=`nbgroups'-2',`testitems'[`i',1]) _col(58) %6.3f `outfitstd`i'' _col(65) %6.3f `infitstd`i'' /*_col(72) %6.3f `outfit`i'' _col(79) %6.3f `infit`i''*/ `cont' } else { di "" } matrix `itemfit'[`i',1]=`testitems'[`i',1] matrix `itemfit'[`i',2]=`=`nbgroups'-2' matrix `itemfit'[`i',3]=1-chi2(`=`nbgroups'-2',`testitems'[`i',1]) matrix `itemfit'[`i',4]=`outfitstd`i'' matrix `itemfit'[`i',5]=`infitstd`i'' if "`method'"=="cml" { if "`html'" == "" { di in ye _col(72) %6.3f `U`i'' } else { di "" } matrix `itemfit'[`i',6]=`U`i'' } if "`html'" != "" { di "" } } } if "`html'" == "" { di in green "{hline `line'}" } else { di "" } if "`test'"!="NONE" { if "`method'"=="cml" { local df=(`nbgroups'-2)*(`nbitems'-1) } else { local df=(`nbgroups'-1)*(`nbitems'-1)-1 } matrix `globalfit'=(`stattest',`df',1-chi2(`df',`stattest')) if "`html'" == "" { noi di in green _col(6) "`descwp'" _col(32) in gr "`namewp'=" _col(36) in ye %8.3f `globalfit'[1,1] _col(46) %3.0f `globalfit'[1,2] _col(51) %6.4f `globalfit'[1,3] if "`method'"=="cml" { noi di in green _col(6) "Andersen LR test" _col(34) "Z=" in yellow _col(36) %8.3f `AndersenZ'[1,1] _col(46) %3.0f `AndersenZ'[1,2] _col(51) %6.4f `AndersenZ'[1,3] } di in green "{hline `line'}" } else { di "" if "`method'"=="cml" { di "" } di "
DifficultyStandardized
" %12s abbrev("``i''`fixed`i''" ,12) "" %8.5f `beta`i'' "" %6.5f `sd`i'' "" %8.3f `testitems'[`i',1] "" %3.0f `=`nbgroups'-2' "" %6.4f 1-chi2(`=`nbgroups'-2',`testitems'[`i',1]) "" %6.3f `outfitstd`i'' "" %6.3f `infitstd`i'' "" %6.3f `U`i'' "
`descwp'`namewp'=" %8.3f `globalfit'[1,1] "" %3.0f `globalfit'[1,2] "" %6.4f `globalfit'[1,3] "
Andersen LR testZ=" %8.3f `AndersenZ'[1,1] "" %3.0f `AndersenZ'[1,2] "" %6.4f `AndersenZ'[1,3] "
" } } if "`html'" == "" { if "`method'"=="cml"&"`meandiff'"==""{ di in green "*: The difficulty parameter of this item had been fixed to 0" } if "`method'"=="cml"&"`meandiff'"!=""{ di in green "The mean of the difficulty parameters is fixed to 0" } if `smallgroup'==1&"`test'"!="NONE" { di in green "You have groups of scores with less than 30 individuals. The tests can be invalid." } if "`method'"!="cml"&"`test'"=="Q" { di in green "The Q statistics is approximated in the `method' approach. It is preferable to use the R1m test." } di } else { if "`method'"=="cml"&"`meandiff'"==""{ di "*: The difficulty parameter of this item had been fixed to 0
" } if "`method'"=="cml"&"`meandiff'"!=""{ di "The mean of the difficulty parameters is fixed to 0
" } if `smallgroup'==1&"`test'"!="NONE" { di "You have groups of scores with less than 30 individuals. The tests can be invalid.
" } if "`method'"!="cml"&"`test'"=="Q" { di "The Q statistics is approximated in the `method' approach. It is preferable to use the R1m test.
" } di "

" } if "`html'" == "" { if "`method'"!="cml" { di in green "{hline 56}" noi di in green _col(5) "Parameters" _col(21) "Coef." _col(28) "std Err." _col(43) "z" _col(52) "P>|z|" di in green "{hline 56}" local zsig=`sig'/`sesig' local pzsig=2*(1-norm(abs(`zsig'))) di in green _col(10) in yellow "Sigma" _col(18) %8.5f `sig' _col(29) %6.5f `sesig' _col(38) %6.3f `zsig' _col(50) %7.4f `pzsig' di in green "{hline 56}" } } else { if "`method'"!="cml" { di "" di "" di "" local zsig=`sig'/`sesig' local pzsig=2*(1-norm(abs(`zsig'))) di "
ParametersCoef.std Err.zP>|z|
Sigma" %8.5f `sig' "" %6.5f `sesig' "" %6.3f `zsig' "" %7.4f `pzsig' "
" } } *set trace on if "`covariables'"!="" { tempname zcovariates pcovariates matrix `zcovariates'=J(1,`nbcovariables',0) matrix `pcovariates'=J(1,`nbcovariables',0) forvalues i=1/`nbcovariables' { local tmp :word `i' of `covariables' local zcov=`betacov'[1,`i']/`Vbetacov'[`i',`i']^.5 local pzcov=2*(1-norm(abs(`zcov'))) matrix `zcovariates'[1,`i']=`zcov' matrix `pcovariates'[1,`i']=`pzcov' di in green _col(3) %12s in yellow abbrev("`tmp'",12) _col(18) %8.5f `betacov'[1,`i'] _col(29) %6.5f `Vbetacov'[`i',`i']^.5 _col(38) %6.3f `zcov' _col(50) %7.4f `pzcov' } di in green "{hline 56}" local difficulties2 if "`difficulties'"!="" { local difficulties2 diff(`difficulties') } if "`ss1'"!="" { tempfile ss1save qui save `ss1save' qui use `saveraschtest' qui keep if `touse'==1 qui raschtestv7 `varlist' ,id(`id') meth(`method') test(none) `ld' `difficulties2' local sigma0=r(sigma) local var0=`sigma0'^2 local nbobs=r(N_obs) *di "nbobs=`nbobs'" local df0=`nbobs'-(`nbitems'+1)-1 local ss10=`var0'*(`df0') local ss1c0=0 di di in green "Type 1 Sum of Squares (sequential)" di "{hline 85}" di in green _col(44) "Degrees" _col(56) "Variance of the" _col(77) "Explained" di in green _col(4) "Covariates" _col(25) "SS" _col(35) "Diff" _col(41) "of freedom"_col(59) "latent trait" _col(78) "Variance" di "{hline 85}" di _col(10) in green "None" _col(15) in ye %12.3f `ss10' _col(47) %4.0f `df0' _col(63) %8.3f `var0' di in green "{dup 85:-}" local covariablesss1 forvalues i=1/`nbcovariables' { local covariablesss1 `covariablesss1' `covariable`i'' qui raschtestv7 `varlist' ,id(`id') meth(`method') covariates(`covariablesss1') test(none) `ld' `difficulties2' local nbobs=r(N_obs) local sigma`i'=r(sigma) local var`i'=`sigma`i''^2 local nbcovtmp:word count `covariablesss1' *di " ss1`i'=`var`i''*`=`nbobs'-(`nbitems'+1+`nbcovtmp')-1'" local df`i'=`nbobs'-(`nbitems'+1+`nbcovtmp')-1 *di "local df`i'=`nbobs'-(`nbitems'+1+`nbcovtmp')-1 (cov:`covariablesss1')" local ss1`i'=`var`i''*`df`i'' *di "cov : `covariablesss1' var=`var`i'' df=`df`i''" di _col(2) %12s in yellow abbrev("`covariable`i''",12) _col(15) %12.3f in ye `ss1`i'' _col(25) %12.3f `=`ss1`=`i'-1''-`ss1`i''' _col(47) %4.0f `df`i'' _col(63) %8.3f `var`i'' _col(81) %5.3f (`=`ss1`=`i'-1''-`ss1`i''')/`ss10' } di in green "{hline 85}" qui use `ss1save' } if "`ss3'"!="" { tempfile ss3save qui save `ss3save' qui use `saveraschtest' qui keep if `touse'==1 if "`ss1'"=="" { qui raschtestv7 `varlist' ,id(`id') meth(`method') test(none) `ld' `difficulties2' local sigma0=r(sigma) local var0=`sigma0'^2 local nbobs=e(N_obs) local df0=`nbobs'-(`nbitems'+1)-1 local ss30=`var0'*(`df0') } else { local ss30=`ss10' } local ss3ref=`=`sig'^2*(`df0'-`nbcovariables')' di di in green "Type 3 Sum of Squares " di "{hline 85}" di in green _col(44) "Degrees" _col(56) "Variance of the" _col(77) "Explained" di in green _col(4) "Covariates" _col(25) "SS" _col(35) "Diff" _col(41) "of freedom"_col(59) "latent trait" _col(78) "Variance" di "{hline 85}" di _col(10) in green "None" _col(15) in ye %12.3f `ss30' _col(47) %4.0f `df0' _col(63) %8.3f `var0' di _col(6) in green "Complete" _col(15) in ye %12.3f `ss3ref' _col(25) %12.3f `=`ss30'-`ss3ref'' _col(47) %4.0f `=`df0'-`nbcovariables'' _col(63) %8.3f `sig'^2 _col(81) %5.3f 1-`sig'^2*(`df0'+`nbcovariables')/`ss30' di in green "{dup 85:-}" forvalues i=1/`nbcovariables' { local covariablesss3 forvalues j=1/`nbcovariables' { if `i'!=`j' { local covariablesss3 `covariablesss3' `covariable`j'' } } qui raschtestv7 `varlist' ,id(`id') meth(`method') covariates(`covariablesss3') test(none) `ld' `difficulties2' *ereturn list local sigmas`i'=r(sigma) local vars`i'=`sigmas`i''^2 local nbobs=e(N) local dfs`i'=`nbobs'-(`nbitems'+1)-1-(`nbcovariables'-1) *di "local dfs`i'=`nbobs'-(`nbitems'+1)-1-(`nbcovariables'-1)" local ss3s`i'=`vars`i''*`dfs`i'' local vara`i'=`sig'^2 local dfa`i'=`nbobs'-(`nbitems'+1)-1-`nbcovariables' local ss3a`i'=`vara`i''*`dfa`i'' *di "cov : `covariablesss3' var=`vars`i'' df=`dfs`i''" di _col(2) %12s in green abbrev("`covariable`i''",12) _col(15) in ye %12.3f `ss3s`i'' _col(25) %12.3f in ye `=`ss3s`i''-`ss3a`i''' _col(47) %4.0f `=`df0'-`nbcovariables'+1' _col(63) %8.3f `vars`i'' _col(80) %6.3f (`=`ss3s`i''-`ss3a`i''')/`ss30' } di in green "{hline 85}" qui use `ss3save' } } /*Tabular of the estimated values of the latent trait*/ if "`covariables'"=="" { if "`html'" == "" { di di noi di in green _col(33) "Ability" _col(60) "Expected" noi di in green _col(17) "Group" _col(23) "Score" _col(30) "parameters" _col(42) "std Err." _col(54) "Freq." _col(63) "Score"_c if "`method'"=="cml"&"`test'"!="NONE" { noi di in green _col(75) "ll" } else { noi di "" } if "`method'"=="cml"&"`test'"!="NONE" { local line=62 } else { local line=51 } di in green _col(17) "{hline `line'}" } else { di "" di "" di "" if "`method'"=="cml"&"`test'"!="NONE" { di "" } di "" } local nonul=0 forvalues g=0/`nbgroups' { if `g'!=0 { if "`html'" == "" { di in green _col(17) "{dup `line':-}" } } forvalues s=`liminf`g''/`limsup`g'' { if `s'==`liminf`g'' { local tmp `ll`g'' local gr `g' } else { local tmp local gr } local expscore`nonul'=0 forvalues i=1/`nbitems' { local expscore`nonul'=`expscore`nonul''+1/(1+exp(-`theta`nonul''+`beta`i'')) } if "`method'"=="cml" { local format1 %8.3f } else { local format1 %8.5f } if "`html'" == "" { noi di in yellow _col(17) %5s "`gr'"_col(23) %5s "`s'" _col(32) `format1' `theta`nonul'' _col(42) `format1' `sdtheta`nonul'' _col(55) %4.0f `nbrealscore`s'' _col(64) % 4.2f `expscore`nonul'' _col(68) %11.4f `tmp' } else { di "" } local nonul=`nonul'+1 } } if "`html'" == "" { di in green _col(17) "{hline `line'}" } else { di "
GroupScoreAbility
parameters
std Err.Freq.Expected
Score
ll
" %5s "`gr'" "" %5s "`s'" "" `format1' `theta`nonul'' "" `format1' `sdtheta`nonul'' "" %4.0f `nbrealscore`s'' "" % 4.2f `expscore`nonul'' "" %11.4f `tmp' "
" } } if "`method'"=="mml"|"`method'"=="gee" { if "`html'" == "" { di *di in green "Variance of the estimated latent trait" _col(45) in ye %10.4f `vartheta' di in green "Mean variance of the error" _col(45) in ye %10.4f `meanse2' local sig2=`sig'^2 di in green "Estimated variance of the latent trait" _col(45) in ye %10.4f `sig2' local psi2=1-`meanse2'/`sig2' di in green "Personal Separation Index (PSI)" _col(45) in ye %10.4f `psi2' di in green "Adjusted PSI on covariates (PSIadj)" _col(45) in ye %10.4f `psi' } else { di "" di "" di "" di "" local sig2=`sig'^2 di "" local psi2=1-`meanse2'/`sig2' di "" di "" di "
Mean variance of the error " %10.4f `meanse2' " " %10.4f `sig2' " " %10.4f `psi2' " " %10.4f `psi' "
" } } /*********************************************************************************************************** DETAILS OPTION ************************************************************************************************************/ if "`details'"!="" { if "`html'"=="" { forvalues g=0/`nbgroups' { if (`g'!=0&`g'!=`nbgroups')|"`method'"!="cml" { di di in green "{hline 44}" di in green "Group: " in ye "`g'" in green " from " in ye "`liminf`g''" in green " to " in ye "`limsup`g''" in green " (n=" in ye "`nbscore`g''" in green")" di di _col(3) "Item" _col(10) "Observed" _col(23) "Expected" _col(37) "Scaled" di in green "{dup 44:-}" } if `g'!=0&`g'!=`nbgroups' { forvalues j=1/`nbitems' { local tmp=`d2`g''[`j',1]/sqrt(`W2`g''[`j',`j']) di _col(3) in ye "``j''" _col(14) %4.0f `Obs2'[`j',`g'] _col(25) %6.2f `Th2'[`j',`g'] _col(36) %7.4f `tmp' } di in green "{dup 44:-}" di in green "Contribution to the `namewp' statistics: " %8.4f in ye `test`g''[1,1] } else if "`method'"!="cml" { if `g'==0 { local h=0 } else { local h=`nbitems' } local tmp=abs(`nbrealscore`h''-`ci`h'')/sqrt(`ci`h'') di in ye _col(14) %4.0f `nbrealscore`h'' _col(25) %6.2f `ci`h'' _col(36) %7.4f `tmp' di in green "{dup 44:-}" local tmp=`tmp'^2 di in green "Contribution to the `namewp' statistics: " %8.4f in ye `tmp' } } } else { forvalues g=0/`nbgroups' { if (`g'!=0&`g'!=`nbgroups')|"`method'"!="cml" { di in gr "" di in gr "" di in gr "" } if `g'!=0&`g'!=`nbgroups' { forvalues j=1/`nbitems' { local tmp=`d2`g''[`j',1]/sqrt(`W2`g''[`j',`j']) di "" } di "" } else if "`method'"!="cml" { if `g'==0 { local h=0 } else { local h=`nbitems' } local tmp=abs(`nbrealscore`h''-`ci`h'')/sqrt(`ci`h'') di "" local tmp=`tmp'^2 di "" } di "
Group: `g' from `liminf`g'' to `limsup`g'' (n=`nbscore`g'')
ItemObservedExpectedScaled
``j''" %4.0f `Obs2'[`j',`g'] "" %6.2f `Th2'[`j',`g'] "" %7.4f `tmp' "
Contribution to the `namewp' statistics:" %8.4f `test`g''[1,1] "
" %4.0f `nbrealscore`h'' "" %6.2f `ci`h'' "" %7.4f `tmp' "
Contribution to the `namewp' statistics:" %8.4f `tmp' "
" } } } /*********************************************************************************************************** OPTION ICC ************************************************************************************************************/ *set trace on if "`icc'"!="" { if "`trace'"!="" { di in green "*** Items Characteristic Curves" } tempvar proba propemp propth propthb qui replace `tl'=. if `realscore'==0|`realscore'==`nbitems'|`realscore'==. qui gen `propemp'=. qui gen `propth'=. qui gen `propthb'=. label variable `propth' "Expected ICC" label variable `propemp' "Observed ICC" label variable `propthb' "Expected ICC" label variable `tl' "Latent trait" global iccs forvalues i=1/`nbitems' { forvalues s=1/`=`nbitems'-1' { qui replace `propthb'=exp(`theta`s''-`beta`i'')/(1+exp(`theta`s''-`beta`i'')) if `item'==`i'&`realscore'==`s' } qui replace `propemp'=. qui replace `propth'=. tempvar propemp`i' propth`i' qui bysort `realscore' `item' : egen `propth`i''=mean(`propthb') if `item'==`i' qui bysort `realscore' `item' : egen `propemp`i''=mean(`rep') if `item'==`i' qui replace `propth'=`propth`i'' if `item'==`i' qui replace `propemp'=`propemp`i'' if `item'==`i' local mintl=floor(`theta1') local maxtl=floor(`theta`=`nbitems'-1'')+1 if "`filessave'"!=""{ local saving "`dirsave'\\icc``i''" } if "`html'"!="" { local saving "`c(tmpdir)'/`html'_icc_``i''" } if "`v8'"!=""|"`html'"!="" { graph twoway (line `propemp' `propth' `tl') if `item'==`i' , `htmlregion' name(icc``i'',replace) ytitle("") ylabel(0(.25)1) title("Observed and Expected ICC for the item ``i''") xlabel(`mintl'(1)`maxtl') xsize(12) ysize(9) `draw' if "html"=="" { pause } else { qui graph save icc``i'' "`saving'" , `replace' qui graph export `c(tmpdir)'/`html'_icc_``i''.eps, replace di "" } if "`filessave'"!="" { qui graph save icc``i'' "`saving'" , `replace' } } else { if "`filessave'"!="" { local saving "saving(`saving'" if "`replace'"=="" { local saving "`saving')" } else { local saving "`saving',replace)" } } qui graph `propemp' `propth' `tl' if `item'==`i' , twoway `saving' c(ll) ylabel(0(.25)1) xlabel(`mintl'(1)`maxtl') title("Observed and Expected ICC for the item ``i''") pause } } } /*********************************************************************************************************** OPTION INFORMATION ************************************************************************************************************/ if "`information'"!="" { if "`trace'"!="" { di in green "*** Information graph" } tempfile saveinfo qui save "`saveinfo'",replace tempvar info latent drop _all qui set obs 2001 gen `latent'=((_n-1)/1001-1)*3 label variable `latent' "latent trait" gen `info'=0 forvalues i=1/`nbitems' { qui replace `info'=`info'+exp(`latent'-`beta`i'')/(1+exp(`latent'-`beta`i''))^2 } local saving "`dirsave'\\information" if "`html'"!="" { local saving "`c(tmpdir)'/`html'_information" } if "`v8'"!=""|"`html'"!="" { *set trace on graph twoway (line `info' `latent') , `htmlregion' name(information,replace) ytitle("Information") xlabel(-3(1)3) title("Information graph of the scale") xsize(12) ysize(9) `draw' if "`filessave'"!="" { graph save information "`saving'" , `replace' } if "`html'"=="" { pause } else { qui graph save information "`saving'" , `replace' qui graph export `c(tmpdir)'/`html'_information.eps, replace di "" } } else { if "`filessave'"!="" { local saving "saving(`saving'" if "`replace'"=="" { local saving "`saving')" } else { local saving "`saving',replace)" } } if "`filessave'"=="" { local saving } qui graph `info' `latent' , twoway `saving' c(l) xlabel(-3(1)3) title("Information graph of the scale") pause } qui use "`saveinfo'",replace } /*********************************************************************************************************** OPTION FITGRAPH ************************************************************************************************************/ if "`fitgraph'"!="" { if "`trace'"!="" { di in green "*** Graphical validation of the fit" } *set trace on tempname outfit meanz2 meanv2 sumd infit Voutfit outfitstd Vinfit infitstd qui egen `outfit'=mean(`y2'),by(`id') qui egen `Voutfit'=sum(`r'),by(`id') qui replace `Voutfit'=`Voutfit'/(`nbitems')^2-1/`nbitems' qui gen `outfitstd'=(`outfit'^(1/3)-1)*(3/sqrt(`Voutfit'))-sqrt(`Voutfit')/3 qui egen `meanz2'=sum(`z2'),by(`id') qui egen `meanv2'=sum(`v2'),by(`id') qui gen `infit'=`meanz2'/`meanv2' qui egen `Vinfit'=sum(`e'),by(`id') qui replace `Vinfit'=`Vinfit'/(`meanv2')^2 qui gen `infitstd'=(`infit'^(1/3)-1)*(3/sqrt(`Vinfit'))-sqrt(`Vinfit')/3 qui su `outfitstd' local mino=floor(2*min(`r(min)',-2))/2 local maxo=ceil(2*max(`r(max)',2))/2 qui su `infitstd' local mini=floor(2*min(`r(min)',-2))/2 local maxi=ceil(2*max(`r(max)',2))/2 if "`filessave'"!=""{ local savingo "`dirsave'\\outfitind" local savingi "`dirsave'\\infitind" } if "`v8'"!="" { graph twoway (scatter `outfitstd' `id'), `htmlregion' name(outfit,replace) yline(-2 2) title("Outfit indexes") xtitle("Individual indexes") ytitle("Outfit") ylabel(`mino'(.5)`maxo') `draw' if "`html'"=="" { pause } graph twoway (scatter `infitstd' `id'), `htmlregion' name(infit,replace) yline(-2 2) title("Infit indexes") xtitle("Individual indexes") ytitle("Infit") ylabel(`mini'(.5)`maxi') `draw' if "`html'"=="" { pause } if "`filessave'"!=""|"`html'"!="" { qui graph save outfit "`savingo'" , `replace' if "`html'"!="" { qui graph export `c(tmpdir)'/`html'_outfit.eps, replace } qui graph save infit "`savingi'" , `replace' if "`html'"!="" { qui graph export `c(tmpdir)'/`html'_infit.eps, replace } } } else { if "`filessave'"!="" { local savingo "saving(`savingo'" local savingi "saving(`savingi'" if "`replace'"=="" { local savingo "`savingo')" local savingi "`savingi')" } else { local savingo "`savingo',replace)" local savingi "`savingi',replace)" } } graph `outfitstd' `id', `savingo' twoway sy(.) c(.) yline(-2 2) title("Outfit indexes") b2title("Individual indexes") l1("") l2title("Outfit") ylabel(`mino'(.5)`maxo') pause graph `infitstd' `id', `savingi' twoway sy(.) c(.) yline(-2 2) title("Infit indexes") b2title("Individual indexes") l1("") l2title("Infit") ylabel(`mini'(.5)`maxi') pause } drop _all qui set obs `nbitems' tempvar name betap outfitstdj infitstdj qui gen str9 `name'="" qui gen `betap'=. qui gen `outfitstdj'=. qui gen `infitstdj'=. local mino=-2 local maxo=2 local mini=-2 local maxi=2 forvalues j=1/`nbitems' { qui replace `name'="``j''" in `j' qui replace `betap'=`beta`j'' in `j' qui replace `outfitstdj'=`outfitstd`j'' in `j' qui replace `infitstdj'=`infitstd`j'' in `j' local mino=floor(min(`mino',`outfitstd`j'')*2)/2 local mini=floor(min(`mini',`infitstd`j'')*2)/2 local maxo=ceil(max(`maxo',`outfitstd`j'')*2)/2 local maxi=ceil(max(`maxi',`infitstd`j'')*2)/2 } if "`filessave'"!=""{ local savingo "`dirsave'\\outfititems" local savingi "`dirsave'\\infititems" } if "`v8'"!="" { graph twoway (scatter `outfitstdj' `betap',`htmlregion' name(outfititem,replace) mlabel(`name')), yline(-2 2) title("Outfit indexes") xtitle("Difficulty") ytitle("Outfit") ylabel(`mino'(.5)`maxo') `draw' if "`html"=="" { pause } graph twoway (scatter `infitstdj' `betap',`htmlregion' name(infititem,replace) mlabel(`name')), yline(-2 2) title("Infit indexes") xtitle("Difficulty") ytitle("Infit") ylabel(`mini'(.5)`maxi') `draw' if "`html"=="" { pause } if "`filessave'"!=""|"`html'"!="" { qui graph save outfititem "`savingo'" , `replace' if "`html'"!="" { qui graph export `c(tmpdir)'/`html'_outfititem.eps, replace } qui graph save infititem "`savingi'" , `replace' if "`html'"!="" { qui graph export `c(tmpdir)'/`html'_infititem.eps, replace } } } else { if "`filessave'"!="" { local savingo "saving(`savingo'" local savingi "saving(`savingi'" if "`replace'"=="" { local savingo "`savingo')" local savingi "`savingi')" } else { local savingo "`savingo',replace)" local savingi "`savingi',replace)" } } graph `outfitstdj' `betap', `savingo' twoway c(.) yline(-2 2) title("Outfit indexes") b2title("Difficulty") l1title("") l2title("Outfit") ylabel(`mino'(.5)`maxo') sy([`name']) pause graph `infitstdj' `betap', `savingi' twoway c(.) yline(-2 2) title("Infit indexes") b2title("Difficulty") l1title("") l2title("Infit") ylabel(`mini'(.5)`maxi') sy([`name']) pause } } /*********************************************************************************************************** OPTION SPLITTESTS ************************************************************************************************************/ if "`splittests'"!="" { if "`trace'"!="" { di in green "*** Splitting tests" } forvalues j=1/`nbitems' { tempname estneg`j' estpos`j' local listitems forvalues k=1/`nbitems' { if `j'!=`k' { local listitems `listitems' ``k'' } } qui use "`saveraschtest'",replace qui keep if `touse'==1 qui raschtestv7 `listitems' if ``j''==0,test(NONE) meth(cml) `ld' id(`id') matrix `estneg`j''=r(beta) local llneg=r(cll) qui raschtestv7 `listitems' if ``j''==1,test(NONE) meth(cml) `ld' id(`id') matrix `estpos`j''=r(beta) local llpos=r(cll) qui raschtestv7 `listitems',test(NONE) meth(cml) `ld' id(`id') local llnegpos=r(cll) local nbcol=colsof(`estneg`j'') local meanneg=0 local meanpos=0 forvalues k=1/`nbcol' { local meanneg=`meanneg'+`estneg`j''[1,`k'] local meanpos=`meanpos'+`estpos`j''[1,`k'] } local meanneg=`meanneg'/`nbitems' local meanpos=`meanpos'/`nbitems' forvalues k=1/`nbcol' { matrix `estneg`j''[1,`k']=`estneg`j''[1,`k']-`meanneg' matrix `estpos`j''[1,`k']=`estpos`j''[1,`k']-`meanpos' if "`method'"=="cml" { matrix `estneg`j''=`estneg`j'',-`meanneg' matrix `estpos`j''=`estpos`j'',-`meanpos' } } drop _all qui set obs `=`nbitems'+1' tempvar neg pos name diag qui gen `neg'=. qui gen `pos'=. qui gen str9 `name'="" local min=`estneg`j''[1,1] local max=`estneg`j''[1,1] forvalues k=1/`=`nbitems'-1' { qui replace `neg'=`estneg`j''[1,`k'] in `k' qui replace `pos'=`estpos`j''[1,`k'] in `k' local min=min(`min',`estneg`j''[1,`k'],`estpos`j''[1,`k']) local max=max(`max',`estneg`j''[1,`k'],`estpos`j''[1,`k']) local tmp:word `k' of `listitems' qui replace `name'="`tmp'" in `k' } local min=floor(`min') local max=floor(`max')+1 qui gen `diag'=. qui replace `diag'=`min' in `nbitems' qui replace `diag'=`max' in `=`nbitems'+1' local Zgr=round(2*(`llneg'+`llpos'-`llnegpos'),0.001) local Zgr=substr("`Zgr'",1,6) local pgr=round(1-chi2(`=`nbitems'-1',`Zgr'),0.0001) local pgr=substr("`pgr'",1,5) local note="Z=`Zgr', df=`=`nbitems'-1' , p=`pgr'" if "`filessave'"!=""{ local saving "`dirsave'\\split``j''" } if "`v8'"!="" { graph twoway (scatter `pos' `neg' ,mlabel(`name')) (line `diag' `diag'), ytitle("Positive answer") xtitle("Negative answer") xlabel(`min'(1)`max') ylabel(`min'(1)`max') title(Splitting on ``j'') `draw' legend(off) note("Andersen Z test: `note'") name(split,replace) `draw' pause if "`filessave'"!="" { graph save split "`saving'" , `replace' } } else { if "`filessave'"!="" { local saving "saving(`saving'" if "`replace'"=="" { local saving "`saving')" } else { local saving "`saving',replace)" } } qui replace `diag'=`neg' if `diag'==. graph `pos' `diag' `diag', `saving' c(.l) sy([`name']i) l1title("") l2title("Positive answer") b2title("Negative answer") xlabel(`min'(1)`max') ylabel(`min'(1)`max') title("Splitting on ``j'' (`note')") `draw' pause } } } /*********************************************************************************************************** OPTION GRAPH ************************************************************************************************************/ if "`graph'"!=""&"`v8'"!="" { if "`trace'"!="" { di in green "*** Graph option" } tempvar latent2 tl2 delta2 tlth2 labdelta2 labtl2 drop _all qui set obs 1001 gen `latent2'=(_n-501)/100 label variable `latent2' "latent trait" qui gen `tl2'=. qui gen `labtl2'="" forvalues i=0/`nbitems' { *if (`i'!=0&`i'!=`nbitems')|"`method'"!="cml" { qui replace `tl2'=`nbrealscore`i''/`N' if round(`latent2',0.01)==round(`theta`i'',0.01) qui replace `labtl2'="`i'" if round(`latent2',0.01)==round(`theta`i'',0.01) *} } qui gen `delta2'=. qui gen `labdelta2'="" forvalues i=1/`nbitems' { qui replace `delta2'=-.05 if round(`latent2',0.01)==round(`beta`i'',0.01) qui replace `labdelta2'="``i''" if round(`latent2',0.01)==round(`beta`i'',0.01) } if "`method'"=="mml"|"`method'"=="gee" { qui gen `tlth2'=1/(2*_pi*`sig')*exp(-.5*(`latent2'/`sig')^2) label variable `tlth2' "Theorical distribution" local graphmml line `tlth2' `latent2' } label variable `tl2' "Score" label variable `delta2' "Items" local saving "`dirsave'\\graph" if "`html'"!="" { local saving "`c(tmpdir)'/`html'_map" } local min=-2 local max=2 forvalues j=1/`nbitems' { if `beta`j''<`min' { local min=`beta`j''-.5 } if `beta`j''>`max'&`beta`j''!=. { local max=`beta`j''+.5 } } if "`method'"=="cml" { if `theta0'<`min' { local min=`theta0'-.5 } if `theta`=`nbitems'-1''>`max' { local max=`theta`=`nbitems'-1''+.5 } } else if "`method'"!="cml" { if `theta0'<`min'&`theta0'!=. { local min=`theta0'-.5 } if `theta`nbitems''>`max'&`theta`nbitems''!=. { local max=`theta`nbitems''+.5 } } local min=floor(`min') local max=floor(`max')+1 qui su `tl2' local max2=r(max) if "`method'"!="cml" { qui su `tlth2' local max2=max(`max2',`r(max)') } qui replace `latent2'=. if `latent2'<`min'|`latent2'>`max' if "`v8'"!="" { graph twoway (bar `tl2' `latent2',/*mlabel(`labtl2')*/ barwidth(.3) ) (dropline `delta2' `latent2',mlabel(`labdelta2') mlabposition(6)) (`graphmml'), `htmlregion' name(graph,replace) ytitle("") xlabel(`min'(1)`max') ylabel(-.1 0(0.05)`max2') title("Individuals/items representations") xsize(12) ysize(9) `draw' if "`filessave'"!="" { graph save graph "`saving'" , `replace' } if "`html'"=="" { pause } else { qui graph save graph "`saving'" , `replace' qui graph export `c(tmpdir)'/`html'_map.eps, replace di "" } } } else if "`graph'"!=""&"`v8'"=="" { di in ye "The graph option is not available with Stata 7" } /*********************************************************************************************************** COMPARISON OF TWO POPULATION ************************************************************************************************************/ if "`comp'"!=""&"`method'"!="cml" { di di _col(4) "{hline 30}" di _col(4) in green "Comparison of two populations" di _col(4) "{hline 30}" di di _col(4) in green "`comp'==`mincomp':" _col(20) "N=" _col(22) in yellow %7.0f `Nmin' _col(30) in green "mean= " _col(35) in yellow %8.4f `meanmin' _col(45) in green "variance=" _col(55) in yellow %8.4f `varmin' di _col(4) in green "`comp'==`maxcomp':" _col(20) "N=" _col(22) in yellow %7.0f `Nmax' _col(30) in green "mean= " _col(35) in yellow %8.4f `meanmax' _col(45) in green "variance=" _col(55) in yellow %8.4f `varmax' di _col(33) in green "Z= " _col(35) in yellow %8.4f `Zcomp' _col(47) in green "pvalue= " _col(57) in yellow %6.4f `pvalue' } /*********************************************************************************************************** TEST DIF ************************************************************************************************************/ if "`method'"=="cml"&"`dif'"!=""&"`test'"!="NONE" { if "`trace'"!="" { di in green "*** Tests of DIF" } local ssll=0 tempname DIFfile qui save "`DIFfile'", replace qui use "`saveraschtest'",replace qui keep if `touse'==1 unab list:`dif' local nbdif:word count `list' tempname DIF matrix define `DIF'=J(`nbdif',4,0) local count=1 di di _col(4) in green "{hline 45}" di _col(4) in green "Test of Differential Item Functioning (DIF)" di _col(4) in green "{hline 45}" foreach j in `list' { qui inspect `j' local nbdif=r(N_unique) qui su `j' local maxdif=r(max) if `nbdif'>10&`maxdif'<=10 { di in ye "The {hi:dif} option is available with variables containing 10 or less modalities (coded from 0 or 1 to k<10)." di in ye "The variable `j' (`nbdif' modalities) is omitted." } else { local ssll=0 forvalues i=0/10 { qui count if `j'==`i' local effdif=r(N) if `effdif'>0 { qui raschtestv7 `varlist' if `j'==`i', test(NONE) id(`id') local ll`i'=r(cll) local ssll=`ssll'+(`ll`i'') } } local Z=2*`ssll'-2*`ll' local ddl=(`nbdif'-1)*(`nbitems'-1) matrix define `DIF'[`count',1]=(`count',`Z',`ddl',1-chi2(`ddl',`Z')) di di _col(4) in green "Variable:" in ye " `j' " in green " Number of groups: " in ye "`nbdif'" di _col(4) in green "LR Test Z=" in ye %8.3f `Z' in gr " ddl=" in ye %4.0f `ddl' in gr " p-value=" in ye %6.4f `=1-chi2(`ddl',`Z')' di } local ++count } use "`DIFfile'",replace } /*********************************************************************************************************** RETURN ************************************************************************************************************/ if "`trace'"!="" { di in green "*** Returns" } local colnametheta forvalues i=0/`nbgroups' { local colnametheta `colnametheta' score_`i' } return clear if `nbitems'>=3&"`test'"!="NONE" { matrix colnames `globalfit'=`namewp' df p matrix rownames `globalfit'=`method' matrix rownames `itemfit'=`varlist' matrix roweq `itemfit'=`method' if "`method'"=="cml" { matrix colnames `itemfit'=`namewp' df p outfit infit U matrix rownames `AndersenZ'=`method' matrix colnames `AndersenZ'=Z df p return matrix AndersenZ=`AndersenZ' if "`dif'"!="" { matrix rownames `DIF'=`list' matrix colnames `DIF'=num Z df p return matrix DIF=`DIF' } } else { matrix colnames `itemfit'=`namewp' df p outfit infit } return matrix itemFit=`itemfit' return matrix globalFit=`globalfit' } matrix colnames `theta'=`colnametheta' matrix rownames `theta'=theta return matrix theta `theta' matrix colnames `sdtheta'=`colnametheta' matrix rownames `sdtheta'=`colnametheta' return matrix Vartheta `sdtheta' local varlist2 matrix coleq `beta'=`method' matrix coleq `Vbeta'=`method' matrix roweq `Vbeta'=`method' if "`method'"=="cml" { forvalues i=1/`=`nbitems'-1' { local varlist2 `varlist2' ``i'' } return scalar cll=`ll' return scalar ll=`globalll' local AIC=-2*`globalll'+2*(`nbitems'-1) } else { return scalar ll=`ll' local varlist2 `varlist' return scalar sigma=`sig' return scalar sesigma=`sesig' local AIC=-2*`ll'+2*(`nbitems'+1) } if "`comp'"!="" { return scalar Zcomp=`Zcomp' return scalar pZcomp=`pvalue' } matrix colnames `beta'=`varlist2' matrix rownames `beta'=beta return matrix beta `beta' matrix colnames `Vbeta'=`varlist2' matrix rownames `Vbeta'=`varlist2' return matrix Varbeta `Vbeta' return scalar AIC=`AIC' return scalar N=`nbind' return scalar N_obs=`nbobserv' if "`method'"=="mml" { return scalar PSI=`psi2' return scalar PSIadj=`psi' } if "`covariables'"!="" { local tmp local tmp2 forvalues i=1/`nbcovariables' { local tmp `tmp' `covariable`i'' local tmp2 "`tmp2' :`covariable`i''" } matrix colnames `betacov'=`tmp2' matrix rownames `Vbetacov'=`tmp2' matrix colnames `Vbetacov'=`tmp2' matrix colnames `zcovariates'=`tmp' matrix colnames `pcovariates'=`tmp' return matrix betacovariates=`betacov' return matrix Vbetacovariates=`Vbetacov' return matrix zcovariates=`zcovariates' return matrix pcovariates=`pcovariates' } if "`pause'"!="" { pause off } drop _all restore,not use "`saveraschtest'" /*********************************************************************************************************** CREATE EVENTUAL NEW VARIABLES ************************************************************************************************************/ *set trace on if "`genres'"!="" { qui sort `id' qui merge `id' using `ltsave' qui rename `u'm1 `genlt' qui rename `u's1 se`genlt' qui drop _merge se`genlt' forvalues i=1/`nbitems' { gen `genres'`i'=exp(``i''*(`genlt'-`beta`i''))/(1+exp(`genlt'-`beta`i''))/sqrt(exp(`genlt'-`beta`i'')/(1+exp(`genlt'-`beta`i''))^2) } corr `genres'* pca `genres'* drop `u'm1 } if "`genfit'"!=""|"`genlt'"!=""|"`genscore'"!="" { tempname genlt2 genscore2 outfit2 infit2 qui gen `score'=0 `if' forvalues i=1/`nbitems' { qui replace `score'=`score'+``i'' `if' } if "`genscore'"!="" { qui gen `genscore'=`score' `if' } if "`genlt'"!="" { if "`replacegenlt'"=="replace" { capture drop `genlt' capture drop se`genlt' } if "`method'"=="mml" { qui sort `id' qui merge `id' using `ltsave' qui rename `u'm1 `genlt' qui rename `u's1 se`genlt' qui drop _merge } else if "`method'"!="mml" { qui gen `genlt2'=. `if' forvalues i=0/`nbitems' { qui replace `genlt2'=`theta`i'' `if'&`score'==`i' } qui gen `genlt'=`genlt2' `if' } } if "`genfit'"!="" { local outfit:word 1 of `genfit' local infit:word 2 of `genfit' qui gen `outfit'=0 `if' qui gen `infit'=0 `if' tempname infit1 infit2 qui gen `infit1'=0 `if' qui gen `infit2'=0 `if' forvalues j=1/`nbitems' { tempname pi`j' qui gen `pi`j''=exp(`genlt2'-`beta`j'')/(1+exp(`genlt2'-`beta`j'')) `if' qui replace `pi`j''=0 `if' forvalues s=1/`nbitems' { qui replace `pi`j''=`Pi'[`j',`s'] `if'&`score'==`s' } qui gen `outfit'``j''=(``j''-`pi`j'')^2/(`pi`j''*(1-`pi`j'')) `if' qui replace `infit1'=`infit1'+(``j''-`pi`j'')^2 `if' qui replace `infit2'=`infit2'+(`pi`j''*(1-`pi`j'')) `if' qui replace `outfit'=`outfit'+`outfit'``j''/`nbitems' `if' } qui replace `infit'=`infit1'/`infit2' `if' } } if "`trace'"!=""|"`time'"!="" { capture qui elapse `st' di in green "** Time : " in yellow "\$S_elap " in green "seconds" } end