# Biased and Unbiased Variance

#### Miguelogy

##### New Member
Hello everyone,

I did an binomial experiment to flip 10 coins and count the total number of heads.This was repeated 200 times.However at the end of the 200 tries, i noticed that the biased sample variance is actually closer to my population variance.Why is this so? Isn't the unbiased variance supposed to be closer to the population variance? The population variance is 2.5, while the biased variance is 2.7,unbiased variance is 2.77.

Also, if instead of 10 coins, we flip 5 coins each time, what will be the difference theoretically?

#### Dason

Keep in mind that you're dealing with a random variable. There is variation. I wrote some code to simulate this process

Code:
experiment <- function(n, k = 10){
# Flip a coin k times and count the number of heads, do that n times
vals <- rbinom(n, k, 0.5)
# This gives the unbiased estimate of variance
sampvar <- var(vals)
# Need to multiply by (k-1)/k to get the biased estimate
popvar <- sampvar * (k-1)/k
# Return the results
result <- c(unbiased = sampvar, biased = popvar)
return(result)
}

# Do the experiment where you flip a coin 10 times and repeat that 200 times...
# But do that whole process 1000 times and record the results
test <- replicate(1000, experiment(200, 10))

# > summary(test["unbiased",])
# Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
# 1.789   2.329   2.494   2.500   2.660   3.552
# > summary(test["biased",])
# Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
# 1.610   2.096   2.244   2.250   2.394   3.197
The results are at the bottom. So on average if you do this experiment the unbiased result will be 2.5 and the biased result will be 2.25.

#### Miguelogy

##### New Member
Keep in mind that you're dealing with a random variable. There is variation. I wrote some code to simulate this process

Code:
experiment <- function(n, k = 10){
# Flip a coin k times and count the number of heads, do that n times
vals <- rbinom(n, k, 0.5)
# This gives the unbiased estimate of variance
sampvar <- var(vals)
# Need to multiply by (k-1)/k to get the biased estimate
popvar <- sampvar * (k-1)/k
# Return the results
result <- c(unbiased = sampvar, biased = popvar)
return(result)
}

# Do the experiment where you flip a coin 10 times and repeat that 200 times...
# But do that whole process 1000 times and record the results
test <- replicate(1000, experiment(200, 10))

# > summary(test["unbiased",])
# Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
# 1.789   2.329   2.494   2.500   2.660   3.552
# > summary(test["biased",])
# Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
# 1.610   2.096   2.244   2.250   2.394   3.197
The results are at the bottom. So on average if you do this experiment the unbiased result will be 2.5 and the biased result will be 2.25.
We did this experiment manually, we really went to flip it 200 times.And we are required to explain our results. Is there any reason why the Biased variance may be more accurate?