Question

In: Computer Science

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.

Solutions

Expert Solution

code

solution

#output

#copyable code

#R code

#user set the random seed values

set.seed(123)

#set the mean value by using 2 populations

mu_val<-10

#standard deviation by using 2 populations

sigma_val<-4

#set the number

D<-900

#set the size

num<-20

#initialize the variable by using the statistics process

tstat<-numeric(D)

#using for loop

for (k in 1:D){

#draw a sample using rnorm

sample1<-rnorm(num,mu_val,sigma_val)

#draw a another sample

sample2<-rnorm(num,mu_val,sigma_val)

#store t.test statistics

tstat[k]<-t.test(sample1,sample2)$statistic

}

#draw histogram

hist(tstat,main="Histogram of t-­test statistic",xlab="t stat")


Related Solutions

2. Write a simulation in R that shows the distribution of the t-test statistic when the...
2. Write a simulation in R that shows the distribution of the t-test statistic when the null hypothesis 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...
The test statistic of a two-tailed t-test for a sample size of 12 was found to...
The test statistic of a two-tailed t-test for a sample size of 12 was found to be 2.1. At a significance level of α = 0.05 ,which of the following statements is correct? Group of answer choices a.The P-value is smaller than 0.05 b.We fail to reject the Null hypothesis c.The test statistic is in the critical region d.The alternative hypothesis is H1: A market researcher wants to estimate the proportion of households in the Bay Area who order food...
The MINITAB printout shows a test for the difference in two population means. Two-Sample T-Test and...
The MINITAB printout shows a test for the difference in two population means. Two-Sample T-Test and CI: Sample 1, Sample 2 Two-sample T for Sample 1 vs Sample 2      N Mean StDev SE Mean Sample 1 5 29.00 4.00 1.8 Sample 2 9 28.86 4.61 1.5 Difference = mu (Sample 1) - mu (Sample 2) Estimate for difference: 0.14 95% CI for difference: (-5.2, 5.5) T-Test of difference = 0 (vs not =): T-Value = 0.06 P-Value = 0.96...
Which statement below describes a property of the t statistic of the one-sample t test? A....
Which statement below describes a property of the t statistic of the one-sample t test? A. The distribution of the t statistic (t distribution) under H0 has a smaller (i.e. more narrow) spread than a standard normal distribution. B. The distribution of the t statistic (t distribution) under H0 depends on n. C. The distribution of the t statistic (t distribution) under H0 cannot be estimated unless n is large. D. Both A and B.
When conducting a two sample t-test using R, which of the following is not a possible...
When conducting a two sample t-test using R, which of the following is not a possible alternative hypothesis? A. true difference in means is not equal to zero B. true difference in means is greater than zero C. true difference in means is less than zero D. true difference in means is equal to zero
1. Match the following situations with the correct test statistic distribution. Provide the correct test statistic...
1. Match the following situations with the correct test statistic distribution. Provide the correct test statistic you would use (or what type of test). Provide an explanation as to why this is the correct distribution or test. (2 points) A. normal distribution B. t distribution with 29 degrees of freedom C. t-distribution with 70 degrees of freedom D. Chi-square with 2 degrees of freedom E. Chi-square with 1 degree of freedom Match Question Items __ ___ A. The sponsors of...
Compute both a paired t-test and two-sample t-test (for practice) but report the t-value for the...
Compute both a paired t-test and two-sample t-test (for practice) but report the t-value for the correct test. XI (Girl Guides) X2 (Boy Scouts) 9 6 9 7 5 5 10 8 6 5 8 6 6 7 7 5 9 4 6 7
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 H0 : μ=100 vs Ha : μ<100 using the sample results x¯=91.7, s=12.5, with n=30.
A sample has a mean of M = 60 and a t statistic of t =...
A sample has a mean of M = 60 and a t statistic of t = 4.5. For a one-tailed hypothesis test with α = .01, what is the correct statistical decision for this sample? Why? a. The researcher can reject the null hypothesis with α = .05 but not with α = .01. b. The researcher can reject the null hypothesis with either α = .05 or α = .01. c. The researcher must fail to reject the null...
Prove that the Kolmogorov-Smirnov two-sample test is a distribution -free test.
Prove that the Kolmogorov-Smirnov two-sample test is a distribution -free test.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT