Module_Statistics_Others - vorcyc/Vorcyc.Mathematics GitHub Wiki
Location: Home / Statistics module / Other statistics functions
Vorcyc.Mathematics.Statistics.Others provides additional statistical functions including covariance, correlation coefficient, and linear regression analysis.
All methods below are on class:
Vorcyc.Mathematics.Statistics.Others
πContents
Vorcyc.Mathematics.Statistics.Others provides additional statistical functions including covariance, correlation coefficient, and linear regression analysis.
-
public static T Covariance<T>(this Span<T> x, Span<T> y) where T : INumber<T>- Computes the covariance of two data sets.
- Parameters:
-
x: First data set. -
y: Second data set.
-
- Returns: Covariance of the two data sets.
-
public static T CorrelationCoefficient<T>(this Span<T> x, Span<T> y) where T : IFloatingPointIeee754<T>- Computes the correlation coefficient of two data sets.
- Parameters:
-
x: First data set. -
y: Second data set.
-
- Returns: Correlation coefficient of the two data sets.
-
public static (T Slope, T Intercept) LinearRegression<T>(this Span<T> x, Span<T> y) where T : IFloatingPointIeee754<T>- Performs simple linear regression analysis.
- Parameters:
-
x: Independent variable data. -
y: Dependent variable data.
-
- Returns: Tuple of slope and intercept.
Example using multiple methods from the Others class, with comments:
using System;
using Vorcyc.Mathematics.Statistics;
public class OthersExample
{
public static void Main()
{
// Define two data sets
Span<double> x = new double[] { 1.0, 2.0, 3.0, 4.0, 5.0 };
Span<double> y = new double[] { 2.0, 4.0, 6.0, 8.0, 10.0 };
// Compute covariance
double covariance = x.Covariance(y);
Console.WriteLine("Covariance: " + covariance);
// Compute correlation coefficient
double correlationCoefficient = x.CorrelationCoefficient(y);
Console.WriteLine("Correlation Coefficient: " + correlationCoefficient);
// Linear regression
var (slope, intercept) = x.LinearRegression(y);
Console.WriteLine($"Linear Regression: Slope = {slope}, Intercept = {intercept}");
}
}