Dart program to calculate mean variance and standard deviation
Dart program to calculate mean variance and standard deviation

Hi Guy’s Welcome to Proto Coders Point. In this flutter dart programming article let’s understand what is mean variance & standard deviation & how to calculate them in dart programming language.

In data analysis, It’s is very crucial to understand the data tendency. mean, variance & standard deviation are main statistical data measures.

What is Mean, Variance & Standard deviation?

Mean:

Mean is calculated by dividing sum of all the numbers in a given set (array)by the total number of numbers. 

Mean = (Sum of all the observations/Total number of observations)


Variance:

Variance is calculated using mean of the squared differences from the average of the data set (array). It is a statistical measure that quantifies the amount of variability or dispersion within a dataset

variance = s^2 = Σ(xi - x̅)^2 / (N - 1);

xi = each value from the data set.
= Mean.
N = Number of value in the data set.


Standard Deviation:

is calculated by square root of variance.

SD = sqrt(variance)


Dart Program to find mean variance and standard deviation

Let’s calculate mean, variance & standard deviation using versatile programming language DART.

import 'dart:math';

void main() {
  List<double> data = [0.6, 1.2, 6, 3, 8, 11, 13, 8, 9.3, 9.4];

  // Calculate the mean
  double mean = data.reduce((a, b) => a + b) / data.length;

  // Calculate the variance
  double variance = data.map((x) => pow(x - mean, 2)).reduce((a, b) => a + b) /
      (data.length - 1);

  // Calculate the standard deviation
  double standardDeviation = sqrt(variance);

  print('Mean: $mean');
  print('Variance: $variance');
  print('Standard Deviation: $standardDeviation');
}

Mean: 6.95
Variance: 17.402777777777782
Standard Deviation: 4.171663670261276