0

So I am trying to calculate the MSE in two ways.

Say T is an estimator for the value t.

First I am trying to calculate it in R by using the theorem:

MSE(T) = Var(T) + (Bias(T))^2

Secondly, I am trying to calculate it in R by definition, i.e. MSE(T) = E((T-t)^2).

And say that T is an unbiased estimator, i.e. Bias(T) = 0

So in R, MSE(T) = Var(T) which we can just in R: var(T)

But when I try calculating the MSE by definition I get a different number from Var(T)...

And I think that my formula that I wrote in R is wrong, this is what I wrote for MSE definition in R:

It was suggested that "weighted.mean" is equivalent to the "expected value" function.

So I wrote: weighted.mean( (T - 2)^2) where my t = 2.

I hope I provided enough information to get help, thanks in advance.

javacoder
  • 131
  • 1
  • 3
  • This doesn't seem like a programming question. If you need help with statistics, you should be asking at [stats.se]. When asking here you should provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and the code you are actually running. Note that the `var` function in R returns the **sample** variance, not the population variance (it divides by `n-1`, not `n`), – MrFlick Mar 29 '19 at 02:07
  • 1
    I'm suggesting we close and move to cross-validated. My best guess is that the root of the problem is confusion about the difference between the expected value of a random variable and the sample mean of several realizations of the random variable. – Gregor Thomas Mar 29 '19 at 02:31
  • A reproducible example would be something like `T = c(1, 2, 3)` as estimates of `t = 2`. We can see that the bias is 0 in this case because `mean(T) == t`. We can run OP's calculations, `mean((T - t)^2)` which gives `0.6667`. We can also calculate it with `var(T) * (length(T) - 1) / length(T)` which also gives `0.6667`. (We multiply by `(n - 1) / n` to convert the sample variance to the population variance, as referenced in MrFlick's comment.) But just because the *expectation* is 0 bias doesn't mean the *sample mean* of finite realizations of the estimator will equal the true value. – Gregor Thomas Mar 29 '19 at 02:34
  • One last note, unless you are specifying weights, then you can use `mean` instead of `weighted.mean`. – Gregor Thomas Mar 29 '19 at 02:36

0 Answers0