(*:Mathematica:: V2.1 *) (*:Context:: "exmiscla`" *) (*Title:: misclassification example*) (*References: Ekholm, A. and Palmgren J. (1982) A model for a binary response with misclassification, GLMIM-82 Proceeding of the International Conference on Generalized Linear Models, ed R. Gilchrist. Burn, R. (1983) Fitting a logit model to data with classification errors. Glim Newsletter June 83. Palmgren, J. and Ekholm, A. (1987) Exponential family non-linear models for categorical data with errors of observation, Applied Stochastic Models and Data Analysis, 3, 111-124. *) (*Keywords: misclassification error *) (*Requirements: "clm`" *) (*History: 1993 Stuart G. Baker *) Clear[exmiscla,createy] createy[]:= Module[{wheeze,examined}, wheeze={104,128,231,378,442,593,649,631,504}; examined={1952,1791,2113,2783,2274,2393,2090,1750,1136}; res=Transpose[{Flatten @ Transpose[{wheeze,examined-wheeze}]}]; Return[res]] y=createy[]; mod1="epsilon/delta" mod={mod1}; exmiscla[y_,modelname_]:= Module[{q1,w1,g1,h1,z1,x1, age, q2,w2,g2,h2,z2,x2, nv,ncore,n,q,w,g,h,z,x, func1,x1a,m1,arg1, func2,x2a,x2b,m2,arg2, components,mstepfunc,msteparg, parametername,rationame, c1,c2,c,model,ratio,name}, (*model 1; wheeze model *) (*p1,1-p1,p2,1-p2.....p9,1-p9,p1,1-p1...p9,1-p9*) q1=Identity; w1=J[36,1,0]; g1=J[2,1] ~ Dir~ Id[18]; h1=#2 #1 - Log[1+Exp[#2]]&; z1=Dir[J[9,1],{{1},{0}}]; age=Transpose[{{22.5,27.5,32.5,37.5,42.5,47.5,52.5,57.5,62.5}}]; x1a=Hcat[J[9,1],age]; x1=Dir[x1a,J[2,1]]; func1=NLR; m1=Id[18] ~Hcat~ Id[18]; arg1={m1,x1a}; (*model 2: misclassification model*) (*1-epsilon,delta,1-epsilon,delta......epsilon,1-delta,epsilon,1-delta..*) q2=Identity; w2=J[36,1,0]; g2=Id[36]; h2= Log[#1+#2]&; z2=Vcat[J[9,1] ~Dir~ {{1},{0}}, J[9,1] ~Dir~ {{0},{1}}]; x2= Vcat[J[9,1] ~Dir~ {{-1,0},{0,1}}, J[9,1] ~Dir~ {{1,0},{0,-1}}]; func2=NPS; x2a=IndicatorMatrix[x2,1]; x2b=Abs[x2]; arg2={x2a,x2b}; (*combination*) ncore=Dir[Id[9],J[1,2]].y; nv=Dir[J[2,1],ncore,J[2,1]]; n={nv,ncore}; q={q1,q1}; w={w1,w2}; g={g1,g2}; h={h1,h2}; z={z1,z2}; x={x1,x2}; c=Hcat[Id[9] ~Dir~ {{1,1},{0,0}}, Id[9] ~Dir~ {{0,0},{1,1}}]; components={n,q,w,g,h,z,x}; mstepfunc={func1,func2}; msteparg={arg1,arg2}; model={components,mstepfunc,msteparg}; ratio="None"; parametername={"alpha","beta","epsilon","delta"}; rationame=Automatic; name={parametername,rationame}; Return[{c,model,ratio,name}]]/;MemberQ[mod,modelname] t1={{-4.2},{.076}}; t2={{.32},{.01}}; t={t1,t2};