# Re: [R] Standard Deviation Distribution

From: Erich Neuwirth <erich.neuwirth_at_univie.ac.at>
Date: Sun 18 Jun 2006 - 21:30:08 EST

> > sddist

```>>> > >>
```

> > function(s,n) {
> > sig2 <- n*s*s/(n-1)
> > 2*(n/(2*sig2))^((n-1)/2) / gamma((n-1)/2) * exp(-n*s*s/(2*sig2)) *
s^(n-2)
> > }

There is another way using more statistical knowledge: Building on functions already available in R one may note that the easiest way of defining sddist is

sddist<-function(s,n) dchisq(n*s^2,n-1)*2*n*s

Plotting this function for n in seq(2,12,2) reproduces the graph in Mathworld.

The idea is the following:
given a random variable x with a chisquare distribution with df n-1, s can be defined by s=sqrt(x/n) and therefore x=n*s^2

If F and G are the cumulative distribution functions of x and s and f and g are the density functions of x and s, then we have G(s)=F(n*s^2) and therefore
g(s)=f(n*s^2)*2*n*s

```--
Erich Neuwirth, University of Vienna
Faculty of Computer Science
Computer Supported Didactics Working Group