开发者

Finding standard deviation/variance in data values [duplicate]

开发者 https://www.devze.com 2023-04-06 02:07 出处:网络
This question already has answers here: How do I determine the standard deviation (stddev) of a set of values?
This question already has answers here: How do I determine the standard deviation (stddev) of a set of values? (12 answers) Closed 9 years ago.

So this is quite a complex problem and I googled alot about it but haven't really come up with anything. So the problem, I need to find the Standard Deviation of some variables within files. So let me state what I need to do: I have the code to find the average v开发者_运维技巧alue of some numbers extracted from files. What I need to do with that average value is subtract it from the value in the files and then take that new value and square it.

Code to find the average value:

var query5 = from file in fileEntries             
 doc = XDocument.Load(file)              
let x = doc.Descendants("").Single()              
let y = doc.Descendants("").Single()              
let z = doc.Descendants("")Single()             
select new             
{                
 X1 = x.Element("Max").Value,                  
 X2 = x.Element("Min").Value,                  
 Y1 = y.Element("Max").Value,                  
 Y2 = y.Element("Min").Value,                  
 Z1 = z.Element("Max").Value,                 
 Z2 = z.Element("Min").Value             
 }; 


Given your above, if you want the population variance and standard deviation, you could do:

// ... code from above
double averageMaximumX = query.Average(t => double.Parse(t.XMax)); 
double varianceMaximumX = query.Sum(t => 
                Math.Pow(double.Parse(t.XMax) - averageMaximumX, 2)));

double stdDevMaximumX = Math.Sqrt(varianceMaximumX);
varianceMaximumX /= query.Count();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号