// g02gd Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.IO; namespace NagDotNetExamples { public class G02GDE { static bool defaultdata = true; static string datafile = ""; static void Main(String[] args) { if (args.Length == 1) { defaultdata = false; datafile = args[0]; } StartExample(); } public static void StartExample() { try { DataReader sr = null; if (defaultdata) { sr = new DataReader("exampledata/g02gde.d"); } else { sr = new DataReader(datafile); } double a, dev, eps, s, tol; int i, idf, ip, iprint, irank, j, m, maxit, n; string link = "", mean = "", offset = "", weight = ""; int ifail; Console.WriteLine("g02gd Example Program Results"); // Skip heading in data file a = 0.0; sr.Reset(); sr.Reset(); link = sr.Next(); mean = sr.Next(); offset = sr.Next(); weight = sr.Next(); n = int.Parse(sr.Next()); m = int.Parse(sr.Next()); s = double.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) { if ((weight == "W") || (weight == "w")) { for (i = 1; i <= n; i++) { sr.Reset(); for (j = 1; j <= m; j++) { x[i - 1, j - 1] = double.Parse(sr.Next()); } y[i - 1] = double.Parse(sr.Next()); wt[i - 1] = double.Parse(sr.Next()); } } else { for (i = 1; i <= n; i++) { sr.Reset(); for (j = 1; j <= m; j++) { x[i - 1, j - 1] = double.Parse(sr.Next()); } y[i - 1] = double.Parse(sr.Next()); } } sr.Reset(); for (j = 1; j <= m; j++) { isx[j - 1] = int.Parse(sr.Next()); } // Calculate ip ip = 0; for (j = 1; j <= m; j++) { if (isx[j - 1] > 0) { ip = ip + 1; } } if ((mean == "M") || (mean == "m")) { ip = ip + 1; } double[] b = new double[ip]; double[] cov = new double[(ip*ip+ip)/2]; double[] se = new double[ip]; double[,] v = new double[n, 7+ip]; if ((link == "E") || (link == "e")) { sr.Reset(); a = double.Parse(sr.Next()); } // Set control parameters eps = 0.0000010e0; tol = 0.000050e0; maxit = 10; // G02.g02gd(link, mean, offset, weight, n, x, m, isx, ip, y, wt, ref s, 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.WriteLine(" {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]); } Console.WriteLine(" "); Console.Write(" {0}", " Y FV Residual H"); Console.WriteLine(" "); for (i = 1; i <= n; i++) { Console.WriteLine(" {0,7:f1}{1,10:f2}{2,12:f4}{3,10:f3}", y[i - 1], v[i - 1, 1], v[i - 1, 4], v[i - 1, 5]); } } else { Console.WriteLine(" "); Console.WriteLine("** g02gd failed with ifail = {0,5}", ifail); } } // } catch (Exception e) { Console.WriteLine(e.Message); Console.Write( "Exception Raised"); } } } }