Ordinal logistic regression.
number of iterations needed to converge to solution with Tolerance precision.
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:
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].
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.
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)
}
}