0
$\begingroup$

My task is given below and I'm stuck on 3 step (probably I made a mistake in 2 step as I'm not 100% sure what m means there and what I have to calculate.

enter image description here

My code is:

set.seed(123)
t <- seq(from = 1, to = 1000, by = 1) + 10 + rnorm(1000, mean = 0.3, sd = 0.9) 
#1
plot(t)
#2
mean(t)
sd(t)

Could someone help me with it and say if I done 1 and 2 correct and how to do the 3?

$\endgroup$
3
  • $\begingroup$ What's $\hat{m}$? $\endgroup$ Commented Apr 16, 2021 at 15:22
  • $\begingroup$ I have the same question because it's not given in the task :( $\endgroup$
    – Gina
    Commented Apr 16, 2021 at 15:51
  • 1
    $\begingroup$ But I believe it's estimated mean $\endgroup$
    – Gina
    Commented Apr 16, 2021 at 15:59

1 Answer 1

1
$\begingroup$

If I understand the text of the exercise correctly, the task is to iteratively draw a sample from the normal distribution, increasing the sample size at each step with the aim of empirically demonstrating that the larger the sample, the closer the variance and mean estimates to real values. The following code should be useful.

set.seed(888)

#an empty object to be filled with the values obtained at each iteration 
y<-NULL

for (k in 1:1000) {

  #sample size for the iteration k
  n <- 10+2*k

  #sample drawing
  sample <- rnorm(n, 0.3, 0.9)

  #calculating mean and variance of the sample
  var <- var(sample)
  mean <- mean(sample)

  #calculating the difference from the real values
  d_var <- 0.81-var
  d_mean <- 0.3-mean

  #storing the values in a permanent dataframe
  x <- data.frame(k, d_var, d_mean)
  y <- rbind(y,x)
}

plot(y$k, y$d_var)
plot(y$k, y$d_mean)
$\endgroup$
1
  • $\begingroup$ Thank you sooo much! Yes, I think the same about the task that it requires to iteratively draw a sample from the normal distribution but I didn't know how to do it correctly. Thanks again! $\endgroup$
    – Gina
    Commented Apr 16, 2021 at 18:39

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.