(*:Mathematica:: V2.1 *) (*:Context:: "exoa2`" *) (*Title: observer agreement with replicate binary classifications *) (*References: Baker,S.G. Freedman,L.S and Parmar, M., 1991. Using replicate observations in observer agreement studies with binary assessments, Biometrics, 47 1327-1338, standard errors are possible for model 4 because estimates are not on the boundary of the parameter space deviances are with respect to a saturated model, not model 1 as in the manuscript *) (*Keywords: observer agreement *) (*Requirements: "clmmat`" *) (*History: 1992 Stuart G. Baker *) Clear[exoa2,designmatrix12,createcmatrix]; y=Vcat[Transpose[{{9,1,4,6, 0,0,0,0, 0,0,1,0, 1,0,1,4}}], Transpose[{{1,0,0,0, 0,1,0,0}}], Transpose[{{0,0,0,0, 0,0,0,1}}], Transpose[{{49,13,0,2}}], Transpose[{{1,1}}], Transpose[{{1,0}}]]; mod1="model3"; mod2="model4"; mod={mod1,mod2}; exoa2[y_,modelname_]:= Module[{zt12,xt12, fourset,true1,true2, g1latent,g2latent,g3latent, q1,w1,g1,h1,z1,x1, func1,m1,x1a,x1b,arg1, q2,w2,g2,h2,z2,x2, func2,m2,x2a,x2b,arg2, q3,w3,g3,h3,z3,x3, func3,m3,x3a,x3b,arg3, nv,ncore,n,q,w,g,h,z,x, components,mstepfunc,msteparg,c,ratio}, (*preliminaries*) (*same as true,same as true},{same,differ},{differ,same},{same,same}*) fourset= {{1,1,0,0}, {1,0,1,0}, {0,1,0,1}, {0,0,1,1}}; (*fourset with 1=true*) true1=fourset; (*fourset with 2=true*) true2={{0,0,0,1},{0,0,1,0},{0,1,0,0},{1,0,0,0}} . fourset; zt12=J[2,1] ~Dir~ Transpose[{{1,1,0,0}}]; xt12=designmatrix12[modelname]; (*model 1 Observer A--pathologist 2*) q1=Identity; w1=J[6 64,1,0]; g1latent=BlockDiag[J[8,1] ~Dir~ true1, J[8,1] ~Dir~ true2]; g1=J[6,1] ~Dir~ g1latent; h1=Log[#1+#2]&; z1=zt12; x1=xt12; func1=NPS; m1=Transpose[g1]; x1a=IndicatorMatrix[x1,1]; x1b=Abs[x1]; arg1={m1,x1a,x1b}; (*model 2 Observer B pathologist 1*) q2=Identity; w2=J[6 64,1,0]; g2latent=J[2,1] ~Dir~ BlockDiag[true1 ~Dir~ J[4,1], true2 ~Dir~ J[4,1]]; g2=J[6,1] ~Dir~ g2latent; h2=Log[#1+#2]&; z2=zt12; x2=designmatrix12[modelname]; func2=NPS; m2=Transpose[g2]; x2a=IndicatorMatrix[x2,1]; x2b=Abs[x2]; arg2={m2,x2a,x2b}; (*model 3 Between Observer*) q3=Identity; w3= J[6 64,1,0]; g3latent=Id[4] ~Dir~ J[16,1]; g3=J[6,1] ~Dir~ g3latent; h3=Log[#1+#2]&; z3=Transpose[{{0,0,0,1}}]; x3=Vcat[Id[3],J[1,3,-1]]; func3=NPS; m3=Transpose[g3]; x3a=IndicatorMatrix[x3,1]; x3b=J[4,3]; arg3={m3,x3a,x3b}; (*combinations*) ncore=BlockDiag[J[1,16],J[1,8],J[1,8],J[1,4],J[1,2],J[1,2]] . y; nv=(Id[6] ~Dir~ J[64,1]) . ncore; n={nv,ncore}; q={q1,q2,q3}; w={w1,w2,w3}; g={g1,g2,g3}; h={h1,h2,h3}; z={z1,z2,z3}; x={x1,x2,x3}; c=createcmatrix[]; components={n,q,w,g,h,z,x}; mstepfunc={func1,func2,func3}; msteparg={arg1,arg2,arg3}; model={components,mstepfunc,msteparg}; ratio="None"; parametername=createparametername[modelname]; rationame=Automatic; name={parametername,rationame}; Return[{c,model,ratio,name}]]/;MemberQ[mod,modelname] createparametername[modelname_]:= Switch[modelname, "model3", {"alpha12","alpha21","beta12","beta21", "theta11", "theta12", "theta21"}, "model4",{"alpha","beta","theta11", "theta12", "theta21"}] designmatrix12[modelname_]:= Switch[modelname, "model3", Id[2] ~Dir~ Transpose[{{-1,-1,1,1}}], "model4", J[2,1] ~Dir~ Transpose[{{-1,-1,1,1}}]] createcmatrix[]:= Module[{clatent,cmissa,cmissb,cmissc,cmissd,cmisse,cmissf,cmiss}, (*--composite link matrix--*) clatent=Dir[Id[6],J[1,4],Id[16]]; cmissa=Id[16]; cmissb=Id[8] ~Dir~ J[1,2]; cmissc=Dir[Id[2],J[1,2],Id[4]]; cmissd={{1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0}, {0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0}, {0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1}}; cmisse={{1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0}, {0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1}}; cmissf=Id[2] ~Dir~ J[1,8]; cmiss=BlockDiag[cmissa,cmissb,cmissc,cmissd,cmisse,cmissf]; c= cmiss . clatent; Return[c]]