Example #1
0
        private void init(double[][] inputs, double[] outputs)
        {
            if (inputs == null)
            {
                throw new ArgumentNullException("inputs");
            }

            if (outputs == null)
            {
                throw new ArgumentNullException("outputs");
            }

            if (inputs.Length != outputs.Length)
            {
                throw new ArgumentException("The number of rows in the input array must match the number of given outputs.");
            }

            this.NumberOfInputs  = inputs[0].Length;
            this.NumberOfOutputs = 1;

            for (int i = 0; i < inputs.Length; i++)
            {
                if (inputs[i].Length != NumberOfInputs)
                {
                    throw new ArgumentException("All input vectors must have the same length.");
                }
            }

            // Create the linear regression
            regression = new MultipleLinearRegression()
            {
                NumberOfInputs = NumberOfInputs
            };

            // Create additional structures
            int coefficientCount = NumberOfInputs + 1;

            this.standardErrors = new double[coefficientCount];
            this.confidences    = new DoubleRange[coefficientCount];
            this.ftests         = new FTest[coefficientCount];
            this.ttests         = new TTest[coefficientCount];

            if (outputName == null)
            {
                this.outputName = "Output";
            }

            if (inputNames == null)
            {
                this.inputNames = new string[NumberOfInputs];
                for (int i = 0; i < inputNames.Length; i++)
                {
                    inputNames[i] = "Input " + i;
                }
            }

            // Create object-oriented structure to represent the analysis
            var coefs = new LinearRegressionCoefficient[coefficientCount];

            for (int i = 0; i < coefs.Length; i++)
            {
                coefs[i] = new LinearRegressionCoefficient(this, i);
            }
            this.coefficientCollection = new LinearRegressionCoefficientCollection(this, coefs);
        }
        /// <summary>
        ///   Constructs a Multiple Linear Regression Analysis.
        /// </summary>
        ///
        /// <param name="inputs">The input data for the analysis.</param>
        /// <param name="outputs">The output data for the analysis.</param>
        /// <param name="intercept">True to use an intercept term, false otherwise. Default is false.</param>
        ///
        public MultipleLinearRegressionAnalysis(double[][] inputs, double[] outputs, bool intercept = false)
        {
            // Initial argument checking
            if (inputs == null)
            {
                throw new ArgumentNullException("inputs");
            }

            if (outputs == null)
            {
                throw new ArgumentNullException("outputs");
            }

            if (inputs.Length != outputs.Length)
            {
                throw new ArgumentException("The number of rows in the input array must match the number of given outputs.");
            }

            this.inputCount = inputs[0].Length;

            for (int i = 0; i < inputs.Length; i++)
            {
                if (inputs[i].Length != inputCount)
                {
                    throw new ArgumentException("All input vectors must have the same length.");
                }
            }

            // Store data sets
            this.inputData  = inputs;
            this.outputData = outputs;



            // Create the linear regression
            regression = new MultipleLinearRegression(inputCount, intercept: intercept);

            // Create additional structures
            this.coefficientCount = regression.Coefficients.Length;
            this.standardErrors   = new double[coefficientCount];
            this.confidences      = new DoubleRange[coefficientCount];
            this.ftests           = new FTest[coefficientCount];
            this.ttests           = new TTest[coefficientCount];

            this.outputName = "Output";
            this.inputNames = new string[inputCount];
            for (int i = 0; i < inputNames.Length; i++)
            {
                inputNames[i] = "Input " + i;
            }


            // Create object-oriented structure to represent the analysis
            var coefs = new LinearRegressionCoefficient[coefficientCount];

            for (int i = 0; i < coefs.Length; i++)
            {
                coefs[i] = new LinearRegressionCoefficient(this, i);
            }
            this.coefficientCollection = new LinearRegressionCoefficientCollection(this, coefs);

            this.Source = inputs.ToMatrix();
        }