Dew Stats Master .NET
LogisticRegress Routines
Summary
Ordinal logistic regression.

Unit
Regress

Declaration
Function LogisticRegress(y: TVec; A: TMtx; B, Theta: TVec; StdErr: TVec; out FMin: TSample; out StopReason: TOptStopReason; MaxIter: Integer = 100; Tolerance: TSample = SQRTEPS; AutoInitEstimates: boolean = true): integer;
 Parameter  Description 
Matrix of independent variables. It is assumed to have full column rank. 
Set it to define initial estimates for B. After the call to LogisticRegress returns regression parameter estimates for B. 
Theta Set it to define initial estimates for Theta. After the call to LogisticRegress returns regression parameter estimates for Theta. 
FMin Returns logistic log-likehood function, evaluated at minimum. 
StopReason Returns why the internal Marquardt optimization method stopped. 
MaxIter Maximum number of allowed iterations in main optimisation loop. 
Tolerance Desired tolerance for optimisation minimum. 
StdErr Returns Theta and B coefficients standard error. This is an estimate of the precision of the Theta and B estimates. The covariance matrix is obtained by inverting the observed information matrix evaluated at the maximum likelihood estimates. The standard errors are the square roots of the diagonal elements of this covariance matrix. 
AutoInitEstimates If true then B and Theta initial estimates will be calculated. If false then you must specify initial values for B and Theta. 
Result
number of iterations needed to converge to solution with Tolerance precision.
Description
Performs logistic or ordinal logistic regression. Suppose y takes values in k ordered categories, and let p_ij be the cumulative probability that y(i) falls in the j'th category or higher. The ordinal logistic regression model is defined as:

logit(p_ij) = theta(j) + A_i'B , i = 1,..,length(Y), j = 1,..,k-1,

where A_i is the i'th row of A . The number of ordinal categories k is taken to be the number of distinct values of int)y. If k is 2 the model is ordinary logistic regression[1].

Categories
Regression routines.
 See Also 
[1] Statbox 4.2: Statistics ToolBox for Matlab. 
[2] Code adapted from Gordon K Smyth, U of Queensland, Australia, gks@maths.uq.oz.au 

Example 1

The following example performs ordinal logistic regression. There are three levels of response and two intercepts in the output to distinguish the three levels.
Uses Math387, MtxExp, Regress, Optimization; procedure Example; var y, b, theta, StdErr: Vector; A: Matrix; FMin: TSample; StopReason: TOptStopReason; begin y.SetIt(false,[1,1,2,1,3,2,3,2,3,3]); A.SetIt(false,10,1,[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); LogisticRegress(y,A,b,theta,StdErr,FMin,StopReason); // Result => b = (0.801), theta=(2.779,5.366) end;
#include "MtxVecCpp.h" #include "Regress.hpp" #include "Math387.hpp" void __fastcall Example() { Matrix A; Vector y,b,theta,se; double min; TOptStopReason stopreason; y->SetIt(false,OPENARRAY(TSample,(1,1,2,1,3,2,3,2,3,3))); A->SetIt(false,10,1,OPENARRAY(TSample,(1,2,3,4,5,6,7,8,9,10))); LogisticRegress(y,A,b,theta,se,min,stopreason); // Result => b = (0.801), theta=(2.779,5.366)
using Dew.Math; using Dew.Stats; using Dew.Stats.Units; namespace Dew.Examples { private void Example() { Vector y = new Vector(0); Vector b = new Vector(0); Vector theta = new Vector(0); Vector se = new Vector(0); Matrix A = new Matrix(0,0,false); double min; TOptStopReason stopreason; y.SetIt(false,new double[] {1,1,2,1,3,2,3,2,3,3}); A.SetIt(false,10,1,new double[] {1,2,3,4,5,6,7,8,9,10}); Regression.LogisticRegress(y,A,b,theta,se,out min, out stopreason, 100,1.0e-8,true); // Result => b = (0.801), theta=(2.779,5.366) } }


Declaration
Procedure LogisticRegress(y, n: TVec; b: TVec; A: TMtx = nil; Offset: TSample = 0.0; YCalc: TVec = nil; BStd: TVec = nil; Tolerance: TSample = EPS);
Summary
Logistic regression.
 Parameter  Description 
response vector containing binomial counts. 
number of trials for each count. Y is assumed to be binomial(p,N). 
matrix of covariates, including the constant vector if required. 
Offset offset if required. 
regression parameter estimates. 
YCalc fitted values. 
BStd Regression parameter estimates errors.This is an estimate of the precision of the B estimates. 
Tolerance Default precision for reweighted LQR. 

Description
Fit logistic regression model.

Example 1

The following example calculates coefficients for simple logistic regression. The counts are out of 10 in each case and there is one covariate[1].
Uses MtxExpr, Regress; procedure Example; var y,n,B: Vector; X: Matrix; begin y.SetIt(false,[2,0,3,1,5,5,6,9,5,9]); n.Size(y); n.SetVal(10.0); X.SetIt(false,10,2 [1,1, 1,2, 1,3, 1,4, 1,5, 1,6, 1,7, 1,8, 1,9, 1,10]); LogisticRegress(y,n,B); // Result => B = (-2.58,0.42) end;
#include "MtxVecCpp.h" #include "Regress.hpp" #include "Math387.hpp" void __fastcall Example() { Matrix X; Vector y,n,B; y->SetIt(false,OPENARRAY(TSample,(2,0,3,1,5,5,6,9,5,9))); n->Size(y); n->SetVal(10.0); X->SetIt(false,10,2, OPENARRAY(TSample,( 1,1, 1,2, 1,3, 1,4, 1,5, 1,6, 1,7, 1,8, 1,9, 1,10))); LogisticRegress(y,n,B,NULL); // Result => B = (-2.58,0.42) }
using Dew.Math; using Dew.Stats; using Dew.Stats.Units; namespace Dew.Examples { private void Example() { Vector y = new Vector(0); Vector n = new Vector(0); Vector B = new Vector(0); Matrix X = new Matrix(0,0); y.SetIt(false,new double[] {2,0,3,1,5,5,6,9,5,9}); n.Size(y); n.SetVal(10.0); X.SetIt(false,10,2, new double[] {1,1, 1,2, 1,3, 1,4, 1,5, 1,6, 1,7, 1,8, 1,9, 1,10}); Regress.LogisticRegress(y,n,B,null); // Result => B = (-2.58,0.42) } }

Copyright 2008 Dew Research
http://www.dewresearch.com