# How to find 3D normal distribution function from a sample of 3D data?

I have a series of three dimensional data like so:

    1    2     3     4    5

1   0    0     0     0    0

2   0   0.3   0.5   0.3   0

3   0   0.5   1.0   0.5   0

4   0   0.3   0.5   0.3   0

5   0    0     0     0    0


Which is clearly a normal distribution. I want some way to give this as input, and to get as output the mean and standard deviation.

Is there a program which can do this for me? Preferably an online solution, if not, then a free program for linux. However, if necessary I am willing to code it myself. Finally, as a last resort I might be able to get the program for free from my school.

Note: I was considering placing this in the Mathematics site, but I thought it bordered more on data. Feel free to move it if necessary.

-
What do you mean by 3D data? What do you mean by "clearly a normal distribution"? It looks more like you have 2D data, $f(2,2)=0.3,f(2,3)=0.5$, etc and you want to fit a two-dimensional normal distribution to it, so that you also have values for $f(2.1,3.6)$, etc that are not in your data set. –  Dilip Sarwate Jan 4 '12 at 12:42
Is it not 3D? [[1,1,0],[1,2,0],[1,3,0]...] –  puk Jan 4 '12 at 21:48

Assuming your input file is placed in a text file named "mydata.txt" in your home directory. Under linux, in the terminal , type:

R
X<-matrix(NA,ncol(Y)^2,3)
X[,1:2]<-cbind(sort(rep(1:ncol(Y),ncol(Y))),rep(1:ncol(Y),ncol(Y)))
X[,3]<-Y[X[,1:2]]
#3 by 1 matrix of means
colMeans(X)
#3 by 3 covariance matrix
cov(X)

-
For data in the format specified in the question, this answer is not correct. It answers a different question where the rows are considered iid draws from a common multivariate Normal distribution (which is five dimensional as illustrated, not three). –  whuber Jan 4 '12 at 15:36
@whuber If each row of the OP's data set is considered as a draw from a $5$-dimensional multivariate normal distribution, it would indeed be a highly suspicious draw! Ditto for a draw from a $3$-dimensional distribution if we prune the first and last columns. –  Dilip Sarwate Jan 4 '12 at 17:19
@Dilip Perhaps. Or maybe there are strong correlations and the data were rounded. But all this is beside the point: it's clear that this interpretation of the data is not appropriate. The asker wants to fit a Gaussian to a 2D grid, as you suggested in your comment to the question. (There are nevertheless some technical issues to settle, such as whether the grid values are probabilities for equal-area cells or values of a PDF at the cell centers or something else and how the values were measured or computed--that is, their error structure.) –  whuber Jan 4 '12 at 17:31
@whuber/Dilip Sarwate. Corrected the code. A bit of an ambiguous formulation+too quick response i guess. –  user603 Jan 5 '12 at 1:05