Question: Need some help doing this in R Studio. A screen shot of all the steps would help. The problem is this: You receive a sample
Need some help doing this in R Studio. A screen shot of all the steps would help.
The problem is this: You receive a sample containing the ages of 30 students. You are wondering whether this sample is a group of undergraduates (mean age = 20 years) or graduates (mean age = 25 years). To answer this question, you must compare the mean of the sampleyou receive to a distribution of means from the population. The following fragment of R code begins the solution:
set.seed(2)
sampleSize <- 30
studentPop <- rnorm(20000,mean=20,sd=3)
undergrads <- sample(studentPop,size=sampleSize,replace=TRUE)
grads <- rnorm(sampleSize,mean=25,sd=3)
if (runif(1)>0.5) { testSample <- grads } else { testSample <- undergrads }
mean(testSample)
After you run this code, the variable testSample will contain either a sample of undergrads or a sample of grads. The line before last flips a coin by generating one value from a uniform distribution (by default the distribution covers 0 to 1) and comparing it to 0.5. The question you must answer with additional code is: Which is it, grad or undergrad?
Here are the steps that will help you finish the job:
Annotate the code above with line-by-line commentary. To get full credit on this assignment, you must demonstrate a clear understanding of what the six lines of code actually do! You will have to look up the meaning of some commands.
The next line of code should generate a list of sample meansfrom the population called studentPop. Very similar code to accomplish this appears right in Chapter 10. How many sample means should you generate? You can create any number that you want hundreds, thousands, whatever but I suggest that you generate just 100 means for ease of inspection. That is a pretty small number, but it makes it easy to think about percentiles and ranks.
Once you have your list of sample means generated from studentPop, the trick is to compare mean (testSample) to that list of sample means and see where it falls. Is it in the middle of the pack? Far out toward one end? Here is one hint that will help you: In Chapter 10, the quantile() command is used to generate percentiles based on thresholds of 2.5% and 97.5%. Those are the thresholds we want, and the quantile() command will help you create them.
Your code should end with a print() statement that could say either, Sample mean is extreme, or Sample mean is not extreme.
So, which is testSample, grad or undergrad? HINT: If you did the prior steps correct, you should get Sample mean is extreme, output.
Please submit both the output of your runs and the R code from your R Console.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
