Browsing resource, all submissions are temporary.
Copy and paste the following code to your R console.
set.seed(7490072) x1 <- rnorm(1e4,mean=2,sd=2) x2 <- rnorm(1e4,mean=2,sd=2)
By construction, x1 and x2 are numeric vectors each with 10,000 random numbers drawn from a normal distribution with mean = 2 and standard deviation = 2.
a. Calculate the means and sample standard deviations of x1 and x2. Enter your answers to 3 decimal places.
Mean of x1 = sample standard deviation of x1 =
Mean of x2 = sample standard deviation of x2 =
b. Perform a two-sample t-test on x1 and x2. Don't forget to use the option var.equal=TRUE. Enter the (two-sided) p-value to 3 significant figures.
var.equal=TRUE
P-value of the t-test =
Reject the null at 5% significance level? yes no
c. Perform a Wilcoxon test on x1 and x2. Enter the p-value to 3 significant figures.
P-value of the Wilcoxon test =
Use the following code to create a new vector x3.
set.seed(7490072) x3 <- rchisq(1e4, 2)
By construction, x3 contains 10,000 random numbers drawn from the χ2 distribution with 2 degrees of freedom.
d. What is the mean and sample standard deviation of x3? Enter your answers to 3 decimal places.
Mean of x3 = sample standard deviation of x3 =
e. Perform a t-test on x1 and x3. Enter the (two-sided) p-value to 3 significant figures. Enter 0 if the p-value is less than 10-10.
What do you conclude?
There is strong no/not enough evidence to reject the null hypothesis that x1 and x3 are random samples drawn from exactly the same probability distribution. two probability distributions with the same variance. two probability distributions with the same mean. two normal distributions with the same variance.
f. Perform a Wilcoxon test on x1 and x3. Enter the p-value to 3 significant figures. Enter 0 if the p-value is less than 10-10.
There is strong no/not enough evidence to reject the null hypothesis that x1 and x3 are random samples drawn from two probability distributions with the same mean. two probability distributions with the same variance. two normal distributions with the same variance. exactly the same probability distribution.
Use the following code to create a new vector x4.
set.seed(7490072) x4 <- rnorm(1e4, 2*log(2), 0.2)
By construction, x4 contains 10,000 random numbers drawn from the normal distribution with mean = 2ln(2) and sd=0.2.
g. Perform a t-test on x3 and x4. Enter the (two-sided) p-value to 3 significant figures. Enter 0 if the p-value is less than 10-10.
h. Perform a Wilcoxon test on x3 and x4. Enter the p-value to 3 significant figures. Enter 0 if the p-value is less than 10-10.
Next we want to perform an F test and a Kruskal-Wallis test on x1, x2, x3 and x4. To do these, we first need to combine x1, x2, x3, x4 to a single numeric vector and create a factor vector to specify the group of the corresponding element of the numeric vector.
Use the command x <- c(x1,x2,x3,x4) to combine x1, x2, x3, x4 to a numeric vector x of length 40,000. For the factor variable, we create it using the gl() function mentioned in Week 8's notes:
x <- c(x1,x2,x3,x4)
gl()
group <- gl(4,1e4,labels=c("x1","x2","x3","x4"))
The first 10,000 elements of 'group' are level "x1"; the next 10,000 elements are level "x2"; the next 10,000 elements are level "x3"; and the last 10,000 elements are level "x4". These levels match precisely the groups in 'x'.
i. Perform an F test for x1, x2, x3 and x4. Enter the p-value to 3 significant figures. Enter 0 if the p-value is less than 10-10.
P-value of the F test =
j. Perform pairwise t-tests with Bonferroni correction to adjust the p-values. Which of the following pairs are significantly different? (Select all that apply) x1, x2 x1, x3 x1, x4 x2, x3 x2, x4 x3, x4
k. Perform a Kruskal-Wallis test for x1, x2, x3 and x4. Enter the p-value to 3 significant figures. Enter 0 if the p-value is less than 10-10.
P-value of the Kruskal-Wallis test =
l. Perform pairwise Wilcoxon tests with Bonferroni correction to adjust the p-values. Which of the following pairs are significantly different? (Select all that apply) x1, x2 x1, x3 x1, x4 x2, x3 x2, x4 x3, x4