Tell me more ×
Cross Validated is a question and answer site for statisticians, data analysts, data miners and data visualization experts. It's 100% free, no registration required.

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.

share|improve this question
1  
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

1 Answer

up vote 1 down vote accepted

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

R
Y<-read.table("~/mydata.txt",header=T)
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)
share|improve this answer
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.