Homework VI Part 2, question2

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Homework VI Part 2, question2

Kelsi
I am struggling with finding out how to repeat the process 10 times for question 2.  I thought maybe that
>rep(c(lower, upper),times=10) would work since that returned 10 different intervals, but I do not know where to go from there. I tried entering the intervals into the plot_ci function but that did not seem right either.  I have also tried using the repeat function for the entire loop, but I always get an error.
Any help would be appreciated.
Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: Homework VI Part 2, question2

Taeho Kim
Administrator
Hi Kelsi,

You've already tried several approaches.
It is not a time wasting because we learn things
when we try many different things.

Now for the question, let us take a look at that the following codes:

population <- ames$Gr.Liv.Area
samp_mean <- rep(NA, 50)
n <- 60
pop_sd<-sd(population) # save population sd
for(i in 1:50){
  samp <- sample(population, n) # obtain a sample of size n = 60 from the population
  samp_mean[i] <- mean(samp)    # save sample mean in ith element of samp_mean
}
lower_vector <- samp_mean - 1.96 * pop_sd / sqrt(n)
upper_vector <- samp_mean + 1.96 * pop_sd / sqrt(n)

plot_ci(lower_vector, upper_vector, mean(population))


If you run this code, then it will show you the plot
so that you can calculate the proportion.
Now, to repeat this procedure, we need to rerun this code again.
(Practically speaking the part with bold letters.)

We could set up another for loop for this repetition.
This will certainly be an interesting task.

But, since the repetition is just 10 times.
You could choose to run this sequence of code for 10 times
and record the proportion for each trial.

It is your call which way you want to go.
If you want to set up another loop, then I can give you more tips.
So, just let me know!