Simulation code ready
This commit is contained in:
@ -49,7 +49,7 @@
|
||||
|
||||
program define simirt , rclass
|
||||
version 8.0
|
||||
syntax [, NBObs(integer 2000) Dim(string) MU(string) COV(string) COVMatrix(string) DISc(string) DIFf(string) PMIN(string) PMAX(string) ACC(string) clear STOre(string) REPlace PREFix(string) DRAW drawall ICC GRoup(real 0) noRANDom DELtagroup(real 0) rsm1(string) rsm2(string) THReshold TITle(string) PCM(string) id(string) GENProba GENIcc]
|
||||
syntax [, NBObs(integer 2000) Dim(string) MU(string) COV(string) COVMatrix(string) DISc(string) DIFf(string) PMIN(string) PMAX(string) ACC(string) clear STOre(string) REPlace PREFix(string) DRAW drawall ICC GRoup(real 0) noRANDom DELtagroup(real 0) rsm1(string) rsm2(string) THReshold TITle(string) PCM(string) id(string) GENProba GENIcc]
|
||||
|
||||
|
||||
/********************************************************************************
|
||||
@ -112,12 +112,6 @@ if "`dim'"!="" {
|
||||
local nbdiff:word count `diff'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
else if "`dim'"==""{
|
||||
if "`diff'"==""&"`pcm'"=="" {
|
||||
di in red "{p 0 0 0}You must indicate the number of items to simulate with the {hi:dim}, the {hi:pcm} or the {hi:diff} option(s)."
|
||||
@ -151,8 +145,6 @@ if (`group'!=0|`deltagroup'!=0)&`dim'!=1 {
|
||||
exit
|
||||
}
|
||||
|
||||
|
||||
|
||||
if "`prefix'"=="" {
|
||||
local prefix item
|
||||
}
|
||||
@ -174,17 +166,6 @@ else {
|
||||
local prefix`d' `prefix'`tmp'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if "`covmatrix'"=="" {
|
||||
tempname covmatrix2
|
||||
local nbcov:word count `cov'
|
||||
@ -204,15 +185,6 @@ if "`covmatrix'"=="" {
|
||||
}
|
||||
matrix `covmatrix2'=(`cov')
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
else if `dim'==2 {
|
||||
if `nbcov'!=3&`nbcov'>0 {
|
||||
di in red "You simulate two dimensions. You must indicate exactly 3 values in the {hi:cov} option (Variance of the first simulated latent trait, Variance of the second simulated latent trait, Covariance between the two simulated latent traits)."
|
||||
@ -244,13 +216,6 @@ if "`covmatrix'"=="" {
|
||||
local covmatrix `covmatrix2'
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
local nbmu:word count `mu'
|
||||
if `nbmu'!=`dim'&`nbmu'!=0 {
|
||||
di in red "You must indicate as many values in the {hi:mu} option as the number of dimension(s) (`dim')"
|
||||
@ -345,10 +310,6 @@ while $seed>2^31-1 {
|
||||
|
||||
qui set seed $seed
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if "`typediff'"=="uniform" {
|
||||
if `nbdiff'==`=`dim'*2+1' {
|
||||
local min`d':word `=(`d'-1)*2+2' of `diff'
|
||||
@ -369,14 +330,6 @@ if "`typediff'"=="uniform" {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
else if "`typediff'"=="gauss" {
|
||||
if `nbdiff'==`=`dim'*2+1' {
|
||||
forvalues d=1/`dim' {
|
||||
@ -404,12 +357,6 @@ else if "`typediff'"=="gauss" {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
forvalues d=1/`dim' {
|
||||
if "`rsm`d''"!="" {
|
||||
local nbrsm`d':word count `rsm`d''
|
||||
@ -452,21 +399,6 @@ forvalues i=1/`nbitems'{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if "`pcm'"==""|"`rsm1'"!="" {
|
||||
tempname pcm
|
||||
if "`rsm1'"=="" {
|
||||
@ -497,7 +429,7 @@ if "`pcm'"==""|"`rsm1'"!="" {
|
||||
local tmp:word `j' of `rsm2'
|
||||
matrix `pcm'[`i',`=1+`j'']=`pcm'[`i',1]+`tmp'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -544,7 +476,7 @@ forvalues i=1/`nbitems' {
|
||||
}
|
||||
|
||||
if "`covmatrix'"=="" {
|
||||
tempname covmatrix
|
||||
tempname covmatrix
|
||||
if `nbcov'==1 {
|
||||
matrix `covmatrix'=(`cov')
|
||||
}
|
||||
@ -582,7 +514,7 @@ local names
|
||||
forvalues d=1/`dim' {
|
||||
qui gen x`d'=invnorm(uniform())
|
||||
qui compress
|
||||
local names `names' lt`d' /*En R: names <- c(names,paste('lt',d)) */
|
||||
local names `names' lt`d'
|
||||
}
|
||||
|
||||
matrix Chol=cholesky(corr(`covmatrix'))
|
||||
@ -598,8 +530,8 @@ forvalues d=1/`dim' {
|
||||
qui replace lt`d'=lt`d'*sqrt(`covmatrix'[`d',`d'])+`matmu'[`d',1]
|
||||
qui compress
|
||||
}
|
||||
qui replace lt1=_n-`nbobs' if `graphobs'
|
||||
qui replace lt1=(lt1-1001)/1000*4*sqrt(`covmatrix'[1,1])+`matmu'[1,1] if `graphobs'
|
||||
qui replace lt1=_n-`nbobs' if `graphobs'
|
||||
qui replace lt1=(lt1-1001)/1000*4*sqrt(`covmatrix'[1,1])+`matmu'[1,1] if `graphobs'
|
||||
|
||||
if `dim'==1&`group'!=0 {
|
||||
if "`random'"=="" {
|
||||
@ -742,14 +674,14 @@ if "`draw'"!=""|"`icc'"!=""|"`drawall'"!="" {
|
||||
else {
|
||||
local title3="`title'"
|
||||
}
|
||||
graph twoway (line `icc`i'' lt1) if `graphobs', ylabel(0(1)`nbmodas') legend(off) ytitle("Expected response") title("`title3'") name(iccitem`i',replace)
|
||||
graph twoway (line `icc`i'' lt1) if `graphobs', ylabel(0(1)`nbmodas') legend(off) ytitle("Expected response") title("`title3'") name(iccitem`i',replace)
|
||||
local hicc `hicc' (line `icc`i'' lt1)
|
||||
label variable `icc`i'' "Item `i'"
|
||||
}
|
||||
graph twoway `hicc' if `graphobs', ylabel(0(1)`nbmodas') legend(on) ytitle("Expected response") title("Item Characteristic Curves") name(icc,replace)
|
||||
graph twoway `hicc' if `graphobs', ylabel(0(1)`nbmodas') legend(on) ytitle("Expected response") title("Item Characteristic Curves") name(icc,replace)
|
||||
}
|
||||
}
|
||||
qui drop if `graphobs'
|
||||
qui drop if `graphobs'
|
||||
|
||||
|
||||
/********************************************************************************
|
||||
|
Reference in New Issue
Block a user