library(downloader) url <- "https://raw.githubusercontent.com/genomicsclass/dagdata/master/inst/extdata/femaleControlsPopulation.csv" filename <- basename(url) download(url, destfile=filename) x <- unlist( read.csv(filename) )Here
x represents the weights for the entire population.
Random Variables Exercises #1
1 point possible (graded)
What is the average of these weights?mean(x)
Answer: 23.89338
Random Variables Exercises #2
1 point possible (graded)
After setting the seed at 1, set.seed(1) take a random sample of size 5. What is the absolute value (use abs) of the difference between the average of the sample and the average of all the values?set.seed(1) X <- sample(x,5) abs( mean(X) - mean(x) )
Answer: 0.2706222
Random Variables Exercises #3
1 point possible (graded)
After setting the seed at 5, set.seed(5) take a random
sample of size 5. What is the absolute value of the difference between
the average of the sample and the average of all the values?set.seed(5) X <- sample(x,5) abs( mean(X) - mean(x) )
Answer: 1.433378
Random Variables Exercises #4
1/1 point (graded)
Why are the answers from 2 and 3 different?Answer: Because the average of the samples is a random variable.
For these exercises, we will be using the following dataset:
library(downloader) url <- "https://raw.githubusercontent.com/genomicsclass/dagdata/master/inst/extdata/femaleControlsPopulation.csv" filename <- basename(url) download(url, destfile=filename) x <- unlist( read.csv(filename) )Here
x represents the weights for the entire population.Null Distributions Exercises #1
1 point possible (graded)
Set the seed at 1, then using a for-loop take a random sample of 5
mice 1,000 times. Save these averages. What proportion of these 1,000
averages are more than 1 gram away from the average of x ?set.seed(1)
n <- 1000
averages5 <- vector("numeric",n)
for(i in 1:n){
X <- sample(x,5)
averages5[i] <- mean(X)
}
hist(averages5) ##take a look
mean( abs( averages5 - mean(x) ) > 1)
Answer: 0.498
Null Distributions Exercises #2
1 point possible (graded)
We are now going to increase the number of times we redo the sample
from 1,000 to 10,000. Set the seed at 1, then using a for-loop take a
random sample of 5 mice 10,000 times. Save these averages. What
proportion of these 10,000 averages are more than 1 gram away from the
average of x ?set.seed(1)
n <- 10000
averages5 <- vector("numeric",n)
for(i in 1:n){
X <- sample(x,5)
averages5[i] <- mean(X)
}
hist(averages5) ##take a look
mean( abs( averages5 - mean(x) ) > 1)
Answer: 0.4976
Note that the answers to 1 and 2 barely changed. This is expected. The way we think about the random value distributions is as the distribution of the list of values obtained if we repeated the experiment an infinite number of times. On a computer, we can't perform an infinite number of iterations so instead, for our examples, we consider 1,000 to be large enough, thus 10,000 is as well. Now if instead we change the sample size, then we change the random variable and thus its distribution.
Set the seed at 1, then using a for-loop take a random sample of 50 mice 1,000 times. Save these averages. What proportion of these 1,000 averages are more than 1 gram away from the average of
x ?set.seed(1)
n <- 1000
averages50 <- vector("numeric",n)
for(i in 1:n){
X <- sample(x,50)
averages50[i] <- mean(X)
}
hist(averages50) ##take a look
mean( abs( averages50 - mean(x) ) > 1)
Answer: 0.019
ไม่มีความคิดเห็น:
แสดงความคิดเห็น