Example 1: Example: Mortality of beetles.

The first example is from Prentice (1976) and involves the mortality of beetles after exposure to various concentrations of carbon disulphide. Both a logit and a probit fit are produced for linear model \mu + \beta x. The data is given as

Covariate(x) N y
1.690 59 6
1.724 60 13
1.755 62 18
1.784 56 28
1.811 63 52
1.836 59 53
1.861 62 61
1.883 60 60

using System;
using Imsl.Math;
using Imsl.Stat;

public class CategoricalGenLinModelEx1
{
    public static void  Main(String[] args)
    {
        // Set up a PrintMatrix object for later use.
        PrintMatrixFormat mf;
        PrintMatrix p;
        p = new PrintMatrix();
        mf = new PrintMatrixFormat();
        mf.SetNoRowLabels();
        mf.SetNoColumnLabels();
                mf.NumberFormat = "0.0000";
        
        double[,] x = {
                       {1.69, 59.0, 6.0},
                       {1.724, 60.0, 13.0},
                       {1.755, 62.0, 18.0},
                       {1.784, 56.0, 28.0},
                       {1.811, 63.0, 52.0},
                       {1.836, 59.0, 53.0},
                       {1.861, 62.0, 61.0},
                       {1.883, 60.0, 60.0}
                      };
 
        CategoricalGenLinModel CATGLM3, CATGLM4;
        // MODEL3
        CATGLM3 = new CategoricalGenLinModel(x,
         CategoricalGenLinModel.DistributionParameterModel.Model3);
        CATGLM3.LowerEndpointColumn = 2;
        CATGLM3.OptionalDistributionParameterColumn = 1;
        CATGLM3.InfiniteEstimateMethod = 1;
        CATGLM3.ModelIntercept = 1;
        int[] nvef = new int[]{1};
        int[] indef = new int[]{0};
        CATGLM3.SetEffects(indef, nvef);
        CATGLM3.UpperBound = 1;
        
        Console.Out.WriteLine("MODEL3");
        p.SetTitle("Coefficient Statistics");
        p.Print(mf, CATGLM3.Solve());
        Console.Out.WriteLine("Log likelihood " + CATGLM3.OptimizedCriterion);
        p.SetTitle("Asymptotic Coefficient Covariance");
        p.SetMatrixType(PrintMatrix.MatrixType.UpperTriangular);
        p.Print(mf, CATGLM3.CovarianceMatrix);
        p.SetMatrixType(PrintMatrix.MatrixType.Full);
        p.SetTitle("Case Analysis");
        p.Print(mf, CATGLM3.CaseAnalysis);
        p.SetTitle("Last Coefficient Update");
        p.Print(CATGLM3.LastParameterUpdates);
        p.SetTitle("Covariate Means");
        p.Print(CATGLM3.DesignVariableMeans);
        p.SetTitle("Observation Codes");
        p.Print(CATGLM3.ExtendedLikelihoodObservations);
        Console.Out.WriteLine("Number of Missing Values " + CATGLM3.NRowsMissing);
        
        // MODEL4
        CATGLM4 = new CategoricalGenLinModel(x,
         CategoricalGenLinModel.DistributionParameterModel.Model4);
        CATGLM4.LowerEndpointColumn = 2;
        CATGLM4.OptionalDistributionParameterColumn = 1;
        CATGLM4.InfiniteEstimateMethod = 1;
        CATGLM4.ModelIntercept = 1;
        CATGLM4.SetEffects(indef, nvef);
        CATGLM4.UpperBound = 1;
        CATGLM4.Solve();
        
        Console.Out.WriteLine("\nMODEL4");
        Console.Out.WriteLine("Log likelihood " + CATGLM4.OptimizedCriterion);
        p.SetTitle("Coefficient Statistics");
        p.Print(mf, CATGLM4.Parameters);
    }
}

Output

MODEL3
        Coefficient Statistics
                                      
-60.7568  5.1876  -11.7118  0.0000  
 34.2985  2.9164   11.7607  0.0000  

Log likelihood -18.7781790423339
Asymptotic Coefficient Covariance
                      
 26.9117  -15.1243  
           8.5052   

               Case Analysis
                                            
0.0577   2.5934  1.7916  0.2674   1.4475  
0.1644   3.1390  2.8706  0.3470   1.0935  
0.3629  -4.4976  3.7860  0.3108  -1.1879  
0.6063  -5.9517  3.6562  0.2322  -1.6279  
0.7954   1.8901  3.2020  0.2688   0.5903  
0.9016  -0.1949  2.2878  0.2380  -0.0852  
0.9558   1.7434  1.6193  0.1976   1.0767  
0.9787   1.2783  1.1185  0.1382   1.1429  

 Last Coefficient Update
            0            
0  1.85192237936898E-07  
1  1.33163785440457E-05  

Covariate Means
     0    
0  1.793  
1  0      

Observation Codes
   0  
0  0  
1  0  
2  0  
3  0  
4  0  
5  0  
6  0  
7  0  

Number of Missing Values 0

MODEL4
Log likelihood -18.2323545743846
        Coefficient Statistics
                                      
-34.9441  2.6412  -13.2305  0.0000  
 19.7367  1.4852   13.2888  0.0000  


Link to C# source.