// g02be Example Program Text // C# version, NAG Copyright 2008 using System; using NagLibrary; using System.Globalization; using System.IO; namespace NagDotNetExamples { public class G02BEE { static string datafile = "ExampleData/g02bee.d"; static void Main(String[] args) { if (args.Length == 1) { datafile = args[0]; } StartExample(); } public static void StartExample() { try { DataReader sr = new DataReader(datafile); int i, j, ncases; const int m = 3; const int n = 5; double[,] rz = new double[m, m]; double[,] sspz = new double[m, m]; double[] std = new double[m]; double[,] x = new double[n, m]; double[] xbar = new double[m]; double[] xmiss = new double[m]; int[] miss = new int[m]; int ifail; Console.WriteLine("g02be Example Program Results"); // Skip heading in data file sr.Reset(); sr.Reset(); for (i = 1; i <= n; i++) { for (j = 1; j <= m; j++) { x[i - 1, j - 1] = double.Parse(sr.Next(), CultureInfo.InvariantCulture); } } Console.WriteLine(" "); Console.WriteLine(" {0}{1,5}", "Number of variables (columns) =", m); Console.WriteLine(" {0}{1,5}", "Number of cases (rows) =", n); Console.WriteLine(" "); Console.Write(" {0}", "Data matrix is:-"); Console.Write("\r\n "); for (j = 1; j <= m; j++) { Console.Write("{0,10}", j); } Console.WriteLine(" "); for (i = 1; i <= n; i++) { Console.Write(" " + i + " "); for (j = 1; j <= m; j++) { Console.Write(" {0,8:f4}", x[i - 1, j - 1]); } Console.WriteLine(" "); } Console.WriteLine(" "); Console.WriteLine(" "); // // Set up missing values before calling method // miss[0] = 1; miss[1] = 0; miss[2] = 1; xmiss[0] = 0.00e0; xmiss[2] = 0.00e0; // G02.g02be(n, m, x, miss, xmiss, xbar, std, sspz, rz, out ncases, out ifail); // if (ifail < 0) { Console.WriteLine(" "); Console.WriteLine("** g02be failed with ifail = {0,5}", ifail); } else { if (ifail != 0) { Console.Write(" {0}{1,5}", "Routine fails, ifail =", ifail); } else { Console.Write(" {0}", "Variable Mean St. dev.\n"); for (i = 1; i <= m; i++) { Console.Write(" {0} {1,10:f4}{2,10:f4}", i, xbar[i - 1], std[i - 1]); Console.WriteLine(" "); } Console.WriteLine(" "); Console.WriteLine(" "); Console.Write(" {0}", ("Sums of squares and cross-products about") + (" zero")); Console.Write("\r\n "); for (i = 1; i <= m; i++) { Console.Write("{0,13}", i); } Console.WriteLine(" "); for (i = 1; i <= m; i++) { Console.Write("\t{0}", i); for (j = 1; j <= m; j++) { Console.Write(" \t{0,10:f4}", sspz[i - 1, j - 1]); } Console.WriteLine(" "); } Console.WriteLine(" "); Console.Write(" {0}", "Correlation-like coefficients\r\n"); Console.Write(" "); for (i = 1; i <= m; i++) { Console.Write("{0,14}", i); } Console.Write("\r\n "); for (i = 1; i <= m; i++) { Console.Write("\t{0}", i); for (j = 1; j <= m; j++) { Console.Write(" \t{0,10:f4}", rz[i - 1, j - 1]); } Console.WriteLine(" "); } Console.WriteLine(" "); Console.WriteLine(" "); Console.WriteLine(" {0}{1,5}", "Number of cases actually used: ", ncases); } } // } catch (Exception e) { Console.WriteLine(e.Message); Console.Write("Exception Raised"); } } } }