// g02gn Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.Globalization; using System.IO; namespace NagDotNetExamples { public class G02GNE { static string datafile = "ExampleData/g02gne.d"; static void Main(String[] args) { if (args.Length == 1) { datafile = args[0]; } StartExample(); } public static void StartExample() { try { DataReader sr = new DataReader(datafile); double a, dev, eps, sestat, stat, tol, z; int i, idf, ip, iprint, irank, j, m, maxit, n, nestfn; bool est = false; int ifail; Console.WriteLine("g02gn Example Program Results"); // Skip heading in data file a = 0.0; sr.Reset(); sr.Reset(); n = int.Parse(sr.Next()); m = int.Parse(sr.Next()); iprint = int.Parse(sr.Next()); double[] wt = new double[n]; double[,] x = new double[n, m]; double[] y = new double[n]; int[] isx = new int[m]; if (n >= 2 && m >= 1) { for (i = 1; i <= n; i++) { sr.Reset(); for (j = 1; j <= m; j++) { x[i - 1, j - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); } y[i - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); } sr.Reset(); for (j = 1; j <= m; j++) { isx[j - 1] = int.Parse(sr.Next()); } ip = int.Parse(sr.Next()); double[] b = new double[ip]; double[] cov = new double[(ip*ip+ip)/2]; double[] f = new double[ip]; double[] se = new double[ip]; double[,] v = new double[n, 7+ip]; // Set control parameters eps = 0.0000010e0; tol = 0.000050e0; maxit = 10; // // Fit Log-linear model using g02gc G02.g02gc("L", "M", "N", "U", n, x, m, isx, ip, y, wt, a, out dev, out idf, b, out irank, se, cov, v, tol, maxit, iprint, eps, out ifail); // if ((ifail == 0) || (ifail >= (7))) { Console.WriteLine(" "); Console.WriteLine(" {0}{1,12:e4}", "Deviance = ", dev); Console.Write(" {0}{1,2}", "Degrees of freedom = ", idf); Console.WriteLine(" "); Console.Write(" {0}", " Estimate Standard error"); Console.WriteLine(" "); for (i = 1; i <= ip; i++) { Console.WriteLine(" {0,14:f4}{1,14:f4}", b[i - 1], se[i - 1]); } sr.Reset(); nestfn = int.Parse(sr.Next()); for (i = 1; i <= nestfn; i++) { sr.Reset(); for (j = 1; j <= ip; j++) { f[j - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); } // G02.g02gn(ip, irank, b, cov, v, f, out est, out stat, out sestat, out z, tol, out ifail); // if ((ifail == 0) || (ifail == 2)) { Console.WriteLine(" "); Console.Write(" {0}{1,4}", "Function ", i); Console.WriteLine(" "); for (j = 1; j <= ip; j++) { Console.Write(" {0, 8:f2}{1}", f[j - 1],j%5==0?"\n":""); } Console.WriteLine(" "); Console.WriteLine(" "); if (est) { Console.WriteLine(" {0}{1,10:f4}{2}{3,10:f4}{4}{5,10:f4}", "STAT = ", stat, " SE = ", sestat, " Z = ", z); } else { Console.WriteLine(" {0}", "Function not estimable"); } } else { Console.WriteLine(" "); Console.WriteLine("** g02gn failed with ifail = {0,5}", ifail); } } } else { Console.WriteLine(" "); Console.WriteLine("** g02gc failed with ifail = {0,5}", ifail); } } // } catch (Exception e) { Console.WriteLine(e.Message); Console.Write( "Exception Raised"); } } } }