% Written by Vanja Dukic, 2000.
%
% Please cite: 
% Dukic and Gatsonis, “Meta-analysis of Diagnostic Test Accuracy Assessment Studies with Varying Number of Thresholds”, Biometrics, 59(4):936-946
% Any questions or comments, please contact me: vanja.dukic@colorado.edu
%
% Prof. Vanja Dukic
% Department of Applied Mathematics
% University of Colorado-Boulder
% Box 526; Boulder, CO 80309-0526
% tel: 303-735-0919; fax: 303-492-4066
%
%
%       Program to fit an ordinal regression model to a multiple
%       study situation resulting in common location&scale parameters 
%       and study-dependent cut-off parameters.
%      
%       Disease:     pregnancy failure
%       Test:        serum progesterone (single measurement)
%       Diagnosis:   lower progesterone == disease 
%
%       There are K studies. It is required that all studies have
%       the same independent variables (at least for now). 
%
%       Example: Let's look at the k-th study with Nk patients (i=1,Nk):
%	Suppose  Yk  takes values in  hk  ordered categories, and let  p_ijk
%	be the cumulative probability that  Yk(i)  falls in the j'th category
%	( 0 < j <= hk ) or lower.  The ordinal logistic regression model is
%
%	 logit(p_ijk) = (theta(jk) + x_ik'beta)/(xs_ik'alpha) , 
%              i = 1,..,length(Yk), j = 1,..,hk-1,
%
%	where  x_ik  is the i'th row of  Xk and xs_ik is the
%       i-th row of XSk where Xk is location and XSk is the scale
%       covariate matrix. We assume that each Xk (and XSk) matrix
%       contains values of the same variables, and therefore 
%       have the same number of columns in all studies. 
%
%       The number of ordinal categories
%	hk  is taken to be the number of distinct values of round(Yk).
%	If  hk = 2  the model is a simple plain logistic regression.
%
%	Xk (and XSk) is assumed to have full column rank. Missing data 
%       observations are deleted: do not use this program if data is 
%       missing under other than MCAR.
%
%
%       Vanja Dukic,
%       BROWN UNIVERSITY


clear all;   % gets rid of all variables in the current workspace

global stepr tol incr decr K Link;  % sets these vars as global


% starting values

sc1=-0.02; beta=-2.275; scale=0.4814;  nt=1;

% NOTE: I performed separate analyses for each study and averaged the 
% parameters. I used PLUM (Peter McCullagh's very old program for
% fitting ord log regression), but you can use any other
% method, inlcuding my own in this program (MA of just one study 
% at a time). The starting values might have to be chosen quite
% carefully, and it's a good idea to try a few sets of them,
% along with a few sets of step-sizes to be used for numerical 
% optimization (a global variable above)


InputStudy   % InputStudy.m reads in all the data

MaximLN

TidyOutput

%PlotROC



L=Lt(iter)
dev=-2*L



