using System; using System.Text; using System.Runtime.InteropServices; using NagLibrary; public class NagG02Functions { public static void Main() { nag_declarations.Nag_IncludeMean mean = nag_declarations.Nag_IncludeMean.Nag_MeanInclude; int n = 12; int m = 4; int ip = (mean == nag_declarations.Nag_IncludeMean.Nag_MeanInclude ? m + 1 : m); int tdx = m; int tdq = ip + 1; double[] x = new double[] { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0 }; double[] y = new double[] { 33.63, 39.62, 38.18, 41.46, 38.02, 35.83, 35.99, 36.58, 42.92, 37.80, 40.43, 37.89 }; int[] sx = new int[m]; double[] b = new double[ip]; double[] se = new double[ip]; double[] cov = new double[ip * (ip + 1) / 2]; double[] res = new double[n]; double[] h = new double[n]; double[] q = new double[n * (ip + 1)]; double[] p = new double[2 * ip + ip * ip]; double[] com_ar = new double[5 * (ip - 1) + ip * ip]; nag_declarations.Nag_Boolean svd = nag_declarations.Nag_Boolean.Nag_FALSE; int rank = 0; double[] wt = new double[n]; double rss = 0.0, df = 0.0, tol = 0.00001; nag_declarations.NagError fail = new nag_declarations.NagError(); fail.message = new byte[512]; Encoding enc = Encoding.ASCII; for (int i = 0; i < m; i++) sx[i] = 1; for (int i = 0; i < n; i++) wt[i] = 1.0; /* nag_regsn_mult_linear (g02dac). * Fits a general (multiple) linear regression model */ nag_declarations.nag_regsn_mult_linear(mean, n, x, tdx, m, sx, ip, y, wt, ref rss, ref df, b, se, cov, res, h, q, tdq, ref svd, ref rank, p, tol, com_ar, ref fail); if (fail.code != 0) { Console.WriteLine("Error from nag_regsn_mult_linear (g02dac):"); Console.WriteLine(enc.GetString(fail.message)); } else { if (svd == nag_declarations.Nag_Boolean.Nag_TRUE) Console.WriteLine("Model not of full rank, rank = {0}", rank); Console.WriteLine("Residual sum of squares = {0,12:e4}", rss); Console.WriteLine("Degrees of freedom = {0, 3:f1}", df); Console.WriteLine(); Console.WriteLine("Variable Parameter estimate Standard error"); for (int j = 0; j < ip; j++) Console.WriteLine("{0, 6:d} {1, 20:e4} {2, 20:e4}", j + 1, b[j], se[j]); Console.WriteLine(); Console.WriteLine(" Obs Residuals h"); for (int i = 0; i < n; i++) Console.WriteLine("{0, 6:d} {1, 20:e4} {2, 20:e4}", i + 1, res[i], h[i]); } } }