# Statistics

Maple has a statistics package built in. To activate the package use the `with(stats)` command:

```> with(stats);

[describe, fit, importdata, random,statevalf, statplots, transform]
```

Let us go ahead and describe a sample data set. Note that the data is enclosed in square brackets, [].

```> sample := [52.54, 89.45, 36.98, 101.32,74.03, 58.65, 18.00, 25.45];

sample := [52.54, 89.45, 36.98, 101.32,74.03, 58.65, 18.00, 25.45]
```

Now we can quickly calculate the mean, median, and standard deviations with the `describe` command:

```> describe[mean](sample);

57.05250000

> describe[median](sample);

55.59500000

> describe[standarddeviation](sample);

27.94432131
```

Maple can calculate probability distributions including normal, c-squared, student T, F, and exponential. For example, suppose you had a mean value of 76.43 with a 2.3 standard deviation:

```> ex_mean := 76.43;

ex_mean :=76.43

> ex_sdev := 2.3;

ex_sdev :=2.3
```

Now, you want the (`normald`) probability that a value is <= 73.40:

```> prob := statevalf[cdf,normald[ex_mean,ex_sdev]](73.40);

prob :=.09385374720
```

Maple can fit models to data via Least Squares methods. One needs to define the data:

```> Xdata := [-1.9,-1.1,0.2,2.1,3.0];

Xdata := [-1.9, -1.1,.2, 2.1, 3.0]

> Ydata := [-4.1,-3.0,-2.2,-0.1,0.8];

Ydata := [-4.1, -3.0,-2.2, -.1, .8]
```

Now, go ahead and fit this to a standard y=mx+b equation:

```>eq_fit:=fit[leastsquare[[x,y],y=m*x+b,{m,b}]]([Xdata,Ydata]);

eq_fit := y = .9758308159 x - 2.168882175
```