(*:Mathematica:: V2.1 *) (*:Context: "excross`" *) (*Title: cross-over incomplete data *) (*References: model related to (but not identical with) Ezzet and Whitehead,1992. A Random Effects Model for Binary Data from Crossover Clinical Trials, Applied Statistics, 41, 117-26 *) (*Keywords: *) (*Requirements: "clm`" *) (*History: 1993 Stuart G. Baker *) Clear[excross,createx1,createx2] y=Transpose[{{26,41,15,57,38,16,32,54, 2,2,2,3}}]; mod1={"intercept","group","mcar"}; mod2={"treat","group","mcar"}; mod3={"treat+period","group","mcar"}; mod11={"intercept","no_group","C"}; mod12={"treat","no_group","C"}; mod13={"treat+period","no_group","C"}; mod21={"intercept","group","LOR"}; mod22={"treat","group","LOR"}; mod23={"treat+period","group","LOR"}; mod31={"intercept","group","LUR"}; mod32= {"treat","group","LUR"}; mod33={"treat+period","group","LUR"}; mod41={"intercept","no_group","LOR,C"}; mod42={"treat","no_group","LOR,C"}; mod43={"treat+period","no_group","LOR,C"}; mod51={"intercept","no_group","LUR,C"}; mod52={"treat","no_group","LUR,C"}; mod53={"treat+period","no_group","LUR,C"}; mod61={"intercept","no_group","LOR,LUR"}; mod62={"treat","no_group","LOR,LUR"}; mod63={"treat+period","no_group","LOR,LUR"}; mod={mod1,mod2,mod3,mod4, mod11,mod12,mod13, mod21,mod22,mod23, mod31,mod32,mod33, mod41,mod42,mod43, mod51,mod52,mod53, mod61,mod62,mod63}; excross[y_,modelname_]:= Module[{q1,w1,g1,h1,z1,x1, func1,m1,components1,nv1,ncore1,arg1, nv,ncore,n,q,w,g,h,z,x, components,mstepfunc,msteparg, parametername,rationame, c,model,ratio,name}, (*model 1*) (*order of parameter*) (*p1,q1,pi1,p2,q2,pi2*) (*p1=1+;q1=++,pi=11*) q1=Log; w1=J[4,1] ~Dir~ {{0},{0},{0},{1}}; g1= Dir[J[2,1],Id[2], {{0,0,1}, {1,0,-1}, {0,1,-1}, {-1,-1,1}}]; h1= Exp[#2]/(1+Exp[#2])&; z1=J[6,1]; x1=createx1[modelname]; func1=NGLR; m1= Dir[J[1,2],Id[2], {{1,1,0,0}, {0,0,1,1}, {1,0,1,0}, {0,1,0,1}, {1,0,0,0}, {0,1,1,1}}]; nv1=J[16,1]; ncore1={{1}}; components1={{nv1,ncore1},{q1},{w1},{g1},{h1},{z1},{x1}}; arg1={m1,components1}; (*model 2*) q2=Identity; w2=J[16,1,0]; g2=Id[16]; h2=Log[#1+#2]&; z2={{0},{1}} ~Dir~ J[8,1]; x2=createx2[modelname]; func2=NPS; x2a=IndicatorMatrix[x2,1]; x2b=Abs[x2]; arg2={x2a,x2b}; (*combination*) ncore=Hcat[Id[2] ~Dir~J[1,4],Id[2] ~Dir~ J[1,2]].y; nv=Dir[J[2,1],ncore,J[4,1]]; n={nv,ncore}; q={q1,q2}; w={w1,w2}; g={g1,g2}; h={h1,h2}; z={z1,z2}; x={x1,x2}; c=BlockDiag[Id[8],Id[4] ~Dir~ J[1,2]]; components={n,q,w,g,h,z,x}; mstepfunc={func1,func2}; msteparg={arg1,arg2}; model={components,mstepfunc,msteparg}; ratio="None"; parametername=createparametername[modelname]; rationame=Automatic; name={parametername,rationame}; Return[{c,model,ratio,name}]]/;MemberQ[mod,modelname] (*---createx1----------*) createx1[modelname_]:= Module[{nu,tau,pi,lambda,res1,res2}, nu=Transpose[{{1,1,0,1,1,0}}]; tau=Transpose[{{.5,-.5,0,-.5,.5,0}}]; pi=Transpose[{{.5,-.5,0,.5,-.5,0}}]; lambda=Transpose[{{0,-1,0,0,1,0}}]; res1=Switch[modelname[[1]], "intercept", Hcat[nu], "treat", Hcat[nu,tau], "treat+period", Hcat[nu,tau,pi], "treatxperiod", Hcat[nu,tau,pi,lambda]]; res2=Switch[modelname[[2]], "group", {{0,0},{0,0},{1,0},{0,0},{0,0},{0,1}}, "no_group", {{0},{0},{1},{0},{0},{1}}]; res=Hcat[res1,res2]; Return[res]] (*---createx2----------*) createx2[modelname_]:= Switch[modelname[[3]], "mcar", Dir[{{1},{-1}},J[8,1]], "C", Dir[{{1},{-1}},Id[2],J[4,1]], "LOR", Dir[{{1},{-1}},J[2,1],Id[2],J[2,1]], "LOR,C", Dir[{{1},{-1}},Id[4],J[2,1]], "LUR", Dir[{{1},{-1}},J[4,1],Id[2]], "LUR,C", Dir[{{1},{-1}},Id[2],J[2,1],Id[2]], "LOR,LUR", Dir[{{1},{-1}},J[2,1],Id[4]]] (*-----createparametename----*) createparametername[modelname_]:= Module[{name1,name2,name3}, name1=Switch[modelname[[1]], "intercept", {"v"}, "treat", {"v","t"}, "treat+period", {"v","t","w"}, "treatxperiod", {"v","t","w","l"}]; name2=Switch[modelname[[2]], "group", {"d1","d2"}, "no_group", {"d"}]; name3=Switch[modelname[[3]], "mcar", {"q"}, "C", {"g1","g2"}, "LOR", {"i1","i2"}, "LUR", {"j1","j2"}, "LOR,C", {"c1i1","c1i2","c2i1","c2i2"}, "LUR,C", {"c1j1","c1j2","c2j1","c2j2"}, "LOR,LUR", {"i1j1","i1j2","i2j1","i2j2"}]; res=Join[name1,name2,name3]; Return[res]] (*------all-------*) all2[ ]:= Module[{}, Print[CLMFit[y,{excross,#},ShowProgress->False]]& /@ {mod2,mod12,mod22,mod22,mod42,mod52,mod62}] all3[ ]:= Module[{}, Print[CLMFit[y,{excross,#},ShowProgress->False]]& /@ {mod3,mod13,mod23,mod33,mod43,mod53,mod63}]