Question: Lab 6 Sampling: Decision - Making Thresholds A key focus of Chapter 1 0 is how to make inferences about populations based on samples. The

Lab 6 Sampling: Decision-Making Thresholds
A key focus of Chapter 10 is how to make inferences about populations based on samples. The essential logic lies in comparing a single instance of a statistic, such as a sample mean, to a distribution of such values. The comparison can lead to one of two conclusions the sample statistic is either extreme or not extreme. But what are the thresholds for making this kind of judgment call (i.e., whether a value is extreme or not)? This activity explores that question.
The problem is this: You receive a sample containing the ages of 30 students. You should be able to telwhether 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 sample you receive to a distribution of means from the population. The following fragment of R code begins the solution:
#q1: this is to set seed. By doing so, the initiation point is always the same, not random.
set.seed(2)
# assign the value 30 to the variable "sampleSize"
sampleSize <-30
#q2: randomly generate 20000 numbers that obeyed normal distribution with mean 20 and standard deviation 3.
# Then assign those numbers to the vector "studentPop".
studentPop <- rnorm(20000,mean=20,sd=3)
#investigate studentPop now. How many rows? What are the values look like? Are they close to the mean value 20?
#q3: draw sampleSize (30 sample defined above) from studentPop and assign the 30 numbers to "undergrads".
undergrads <- sample(studentPop,size=sampleSize,replace=TRUE)
#q4: create a sample of graduate students--randomly generate 30 numbers (use sampleSize) that obeyed normal distribution with mean 25 and sd 3. See the mean is 5 years older than the undergraduate sample apparently.
# Assign the numbers to the vector "grads".
# Sample size is sampleSize (==30), mean is 25, standard deviation is 3.
grads <- rnorm(sampleSize,mean=25,sd=3)
#q5: Randomly assign either the grads sample or the undergrads sample to testSample, depending on the value generated by runif(1).
# "runif(1)" would generate a random number between 0 and 1.
# If the number is greater than 0.5, assign grads sample to testSample. Otherwise, assign undergrads sample to testSample.
if (runif(1)>0.5){ testSample <- grads } else { testSample <- undergrads }
mean(testSample)
#q6: calculate the mean of "testSample" What is the mean of 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?
#q7: Generate 100 sample means from studentPop and assign it as mySample
mySample <- replicate(---your code here-----)
#q8: Compare mean(testSample) to that list of sample means (mySample) and see where it falls. quantile() function helps display data distribution. Produce quantiles on thresholds 2.5% and 97.5%.
---your code here-----
#q9: if the sample mean is less than quantiles on thresholds 2.5% or greater than quantiles on thresholds 97.5%, then it can be definded as extreme. Otherwise it is not extreme.
if (mean(object name here)< quantile(object name here, probs=0.025)| mean(object name here)>quantile(object name here, probs=0.975))
{ print("Sample mean is extreme")} else { print("Sample mean is not extreme")}
-----

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!