Question

Write a simulation in R that shows the distribution of the t-­‐test statistic for a two-­‐sample...

Write a simulation in R that shows the distribution of the t-­‐test statistic for a two-­‐sample t test when the null hypothesis is true (i.e. when H0: µ1 -­‐ µ2 = 0 is true). To do this, you should use a for loop that repeatedly performs t-­‐tests comparing sample means of data that come from distributions with the same population mean and standard deviation. Use rnorm() to take samples, t.test() to perform the t-­‐ tests, and use “$statistic” to extract the t-­‐test statistic from the t.test() procedure (e.g. t.test(x,y)$statistic). Make a histogram of the test statistics.

Homework Answers

Answer #1

R code with comments (all statements starting with # are comments and can be removed)

#set the random seed
set.seed(123)

#set the mean of the 2 populations
mu<-10
#set the standard deviation of 2 populations
sigma<-5
#set the number of simulations
R<-1000
#set the sample size
n<-20
#initialize the variable to hold the test statistics
tstat<-numeric(R)

#loop R times
for (i in 1:R){
#draw a sample of size n
s1<-rnorm(n,mu,sigma)
#draw a second sample of size n
s2<-rnorm(n,mu,sigma)
#store the statistics part of the t test
tstat[i]<-t.test(s1,s2)$statistic
}
#Make a histogram
hist(tstat,main="Histogram of t-­test statistic",xlab="t stat")

# get this

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Use the t-distribution and the given sample results to complete the test of the given hypotheses....
Use the t-distribution and the given sample results to complete the test of the given hypotheses. Assume the results come from random samples, and if the sample sizes are small, assume the underlying distributions are relatively normal. Test H0 : μ1=μ2 vs Ha : μ1≠μ2 using the sample results x¯1=15.3, s1=11.6 with n1=100 and x¯2=18.4, s2=14.3 with n2=80. (a) Give the test statistic and the p-value. Round your answer for the test statistic to two decimal places and your answer...
Use the t-distribution and the given sample results to complete the test of the given hypotheses....
Use the t-distribution and the given sample results to complete the test of the given hypotheses. Assume the results come from random samples, and if the sample sizes are small, assume the underlying distributions are relatively normal. Test H0 : μ1=μ2 vs Ha : μ1≠μ2 using the sample results x¯1=15.3, s1=11.6 with n1=100 and x¯2=18.4, s2=14.3 with n2=80. (a) Give the test statistic and the p-value. Round your answer for the test statistic to two decimal places and your answer...
Write an R function that will simulate 2 data sets from gamma distributions (``rgamma'' function, this...
Write an R function that will simulate 2 data sets from gamma distributions (``rgamma'' function, this gives us skewed samples) then does a standard t-test comparing the 2 means (``t.test'' function) and returns the p-value. The function should have 2 sample sizes and 2 sets of parameters as input. Now use the function to simulate a case with small sample sizes and the null hypothesis being true (equal means) and see how the type I error rate is affected by...
A researcher used an independent sample t test to compare two treatment conditions. He wanted to...
A researcher used an independent sample t test to compare two treatment conditions. He wanted to test whether there is a significant difference between two treatments. Following data were obtained: Treatment one group: # of participants = 12, sample mean = 55, sample standard dev (s) = 2.83 Treatment two group: # of participants = 12, sample mean = 52, sample standard dev (s) = 2.00 Use 5% significance level. Assume    µ1 and  µ2 are the population means for group one and...
A researcher used an independent sample t test to compare two treatment conditions. He wanted to...
A researcher used an independent sample t test to compare two treatment conditions. He wanted to test whether there is a significant difference between two treatments. Following data were obtained: Treatment one group: # of participants = 12, sample mean = 55, sample standard dev (s) = 2.83 Treatment two group: # of participants = 12, sample mean = 52, sample standard dev (s) = 2.00 Use 5% significance level. Assume    µ1 and µ2 are the population means for group...
Calculate the test statistic. Are you working with a normal or a t-distribution? If it is...
Calculate the test statistic. Are you working with a normal or a t-distribution? If it is a t-distribution, report the degrees of freedom. Is the observed statistic unusual or not? Justify with a probability. Formally complete the hypothesis test. That is, compute a p-value, make a decision, and write out a final conclusion (in context). A school principal wants to test if it is true that high school juniors use the computer an average 3.2 hours a day. He selects...
Use the t-distribution and the sample results to complete the test of the hypotheses. Use a...
Use the t-distribution and the sample results to complete the test of the hypotheses. Use a 5% significance level. Assume the results come from a random sample, and if the sample size is small, assume the underlying distribution is relatively normal. Test Ho : μ=120 vs Ha : μ<120 using the sample results x¯=112.3, s=18.4, with n=100. a) Give the test statistic and the p-value Test statistic = _____ P-value = _____
Use a t-distribution and the given matched pair sample results to complete the test of the...
Use a t-distribution and the given matched pair sample results to complete the test of the given hypotheses. Assume the results come from random samples, and if the sample sizes are small, assume the underlying distribution of the differences is relatively normal. Assume that differences are computed using d=x1-x2. Test H0 : μd=0 vs Ha : μd>0 using the paired data in the following table: Situation 1 120 156 145 175 153 148 180 135 168 157 Situation 2 120...
Describe an experiment that would require use of one of the three different t-tests (One Sample,...
Describe an experiment that would require use of one of the three different t-tests (One Sample, Correlated Samples, or Independent Groups), but don’t tell us which statistic you think should be used. Then go into the discussion and look at another student's t-test experiment, and tell us which of the three t-test statistics would be appropriate to analyze his data.
Answer the following about T-Test & T-distributions: 1. Which of the following statements related to the...
Answer the following about T-Test & T-distributions: 1. Which of the following statements related to the t-distribution is not true? Select one: a. Since the population standard deviation is usually unknown, the standard error of the sample mean is estimated using the sample standard deviation as an estimator for the population standard deviation. The formula is s/sqrt(n). b. The population must be t-distributed in order to use the t-distribution. c. Like the Normal distribution, the t-distribution is symmetric and unimodal....
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT