# Calculate the Sample Skewness

Page 1 of 1

## 0 Replies - 1720 Views - Last Post: 02 April 2012 - 07:07 AM

### #1 Ryano121

• D.I.C Lover

Reputation: 1461
• Posts: 3,289
• Joined: 30-January 11

# Calculate the Sample Skewness

Posted 02 April 2012 - 07:07 AM

Description: See Example Usage in snippetIn probability theory and statistics, skewness is a measure of the asymmetry of the probability distribution of a real-valued random variable. More information - http://en.wikipedia....Sample_skewness
```public class Skewness
{
public static double sampleSkewness(double[] data)
{
double mean = average(data); // get the mean of the data
double numerator = 0, denominator = 0;

for (int i = 0; i < data.length; i++)
{
numerator += Math.pow(data[i] - mean, 3); // deviations to the third power
denominator += Math.pow(data[i] - mean, 2); // deviations to the second power
}

numerator = (1.0 / data.length) * numerator; // multiply by 1/ data size

denominator = Math.pow(denominator * (1.0 / data.length), 3.0 / 2.0); // multiply by 1/data size and raise to the power of 1.5

return numerator / denominator;
}

// Returns the mean of the data set
private static double average(double[] data)
{
double sum = 0;

for (int i = 0; i < data.length; i++)
{
sum += data[i];
}

return sum / data.length;
}

public static void main(String[] args) throws Exception
{
double[] x = { 2, 3, 4, 5, 6, 8, 10, 11.53542 };

double skewness = Skewness.sampleSkewness(x);
System.out.println("Sample Skewness = " + skewness);
}
}

// OUTPUT

// Sample Skewness = 0.37424139836476816

```

Is This A Good Question/Topic? 0

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }