(*:Mathematica:: V2.2.1 *) (*:Context:: "cdanps`" *) (*:Version:: 1.1 *) (*:Title:: proportional substitution*) (*:Summary:: NPS: proportional substitution NPSLogit: logit of proportional substitution *) (*References:: *) (*Keywords:: proportional substitution *) (*Requirements:: matrixlx`: matrix funcitons *) (*History: 1992 Stuart G. Baker *) BeginPackage["clm`cdxnps`","clm`matrixlx`"] (*---------------------Proportion Substitution --------*) NPS::usage= "NPS[ys,{m,xa,xb},options] or NPS[ys,{xa,xb},options] returns a a proportion (NPS stands for proportion substitution). The argument ys is the complete data, m is a matrix which multiplies ys to put the data into the correct form. The arguments xa and xb create the proportions in the following way: Transpose[m . ys] . xa is the numerator and Transpose [m . ys] . xb is the denominator." (*---------------------Logit of Proportion Substitution --------*) NPSLogit::usage= "NPSLogit[ys,{m,xa,xb},options] or NPSLogit[ys,{xa,xb},options] returns the logit of a proportion (NPSLogit stands for proportion substitution with logit). The argument ys is the data, m is a matrix which multiplies ys to put the data into the correct form. The quantity xa . m . ys is the numerator and xb . m. ys is the denominator." Clear[NPS,NPSLogit] Begin["Private`"] NPS[ys_,{xa_,xb_}]:= Module[{y,num,den,denadj}, y=N[ys]; num=Transpose[y].xa; den=Transpose[y].xb; (*check that zero denominator implies zero numerator*) If[Sign[den]=!=Sign[den+num],Print["warning bad NPS"]]; (*set 0/0 equal to 0/1*) denadj=den + (1-Sign[den]); ratio=Transpose[num/denadj]; Return[ratio]] NPS[ys_,{m_,xa_,xb_}]:=NPS[m.N[ys],{xa,xb}] NPSLogit[ys_,{xa_,xb_}]:= With[{t=NPS[ys,{xa,xb}]},Log[t/(1-t)]] NPSLogit[ys_,{m_,xa_,xb_}]:= With[{t=NPS[m.ys,{xa,xb}]},Log[t/(1-t)]] End[] (*Protect[NPS,NPSLogit,NLR,NPR,NLLR]*) EndPackage[]