3
$\begingroup$

I am learning Mathematica on the fly, one of my tasks is to find the variance of white noise. I followed the tutorial for finding white noise by using the code:

WN = WhiteNoiseProcess[NormalDistribution[0, 10]];
data = RandomFunction[WN, {0, 10000}];

I know I can use the following code to find the variance:Variance[data]

However, I would like to find it by using the formula for variance. I checked the reference built into Mathematica and it says I can simply use:

Total[(list-Mean[list])^2]/(Length[list]-1)

I input data for the list:

Total[(data-Mean[data])^2]/(Length[data]-1)

When I do this, I don't get the same output as when I use the Variance[data] code, but instead get: enter image description here

So, I am curious what I am doing wrong? I'm sure it's something simple I am not doing, but after spending a couple of hours wrestling with this, I am breaking down to ask. Sorry if this is a dumb question. Thank you in advance for your time.

$\endgroup$
3
  • $\begingroup$ Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise. $\endgroup$
    – bbgodfrey
    Commented May 15, 2015 at 22:24
  • 1
    $\begingroup$ You must extract the values (path) - see the doc for details under properties of temporaldata... $\endgroup$
    – ciao
    Commented May 15, 2015 at 22:31
  • 2
    $\begingroup$ I did some digging in there and used: Total[(data["Values"] - Mean[data["Values"]])^2]/(Length[ data["Values"]] - 1) This resolved the same as the Variance expression. $\endgroup$
    – Sean Alto
    Commented May 15, 2015 at 22:39

3 Answers 3

5
$\begingroup$

The specific approach is as follows. Convert data to an ordinary list, eliminate an extra set of {}, and insert the list into your formula:

dta = First@Normal@data;
Last@Total[(dta - Last@Mean[dta])^2]/(Length[dta] - 1)

which gives the same result as

Variance[data]

namely 102.245 for the particular set of random numbers used.

$\endgroup$
1
  • $\begingroup$ Outstanding, I was positive it was something small I was missing. Thank you for your help. $\endgroup$
    – Sean Alto
    Commented May 15, 2015 at 22:41
5
$\begingroup$

It is valuable to look at the properties of these complex objects, e.g. in your example:

data["Properties"]

To do your own variance:

val = First@data["ValueList"];
Variance[val]
Total[(val - Mean[val])^2]/(Length[val] - 1)

You can compare results of Variance and your mimic.

$\endgroup$
1
$\begingroup$
SeedRandom[1]
WN = WhiteNoiseProcess[NormalDistribution[0, 10]];
data = RandomFunction[WN, {0, 10000}];

CentralMoment

variance = # /(# - 1)& @ #["PathLength"] CentralMoment[#["Values"], 2]&;
variance[data]

97.25341025240807

Variance[data]

97.25341025240806

MomentConvert + MomentEvaluate

variance2 = MomentEvaluate[MomentConvert[CentralMoment[2], "UnbiasedSampleEstimator"], 
 #["Values"]]&;

variance2 @ data

97.25341025240809

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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