Question

In R, Part 1. Learn to understand the significance level α in hypothesis testing. a) Generate a matrix “ss” with 1000 rows and 10 columns. The elements of “ss” are random samples from standard normal...

In R,

Part 1. Learn to understand the significance level α in hypothesis testing.

a) Generate a matrix “ss” with 1000 rows and 10 columns. The elements of “ss” are random samples from standard normal distribution.

b) Run the following lines:

mytest <- function(x) {

return(t.test(x,mu=0)$p.value)

}

mytest(rnorm(100))

Note that, when you input a vector in the function mytest, you will get the p-value for the one sample t-test H0 : µ = 0 vs Ha : µ =/= 0.

c) Conduct one sample t-test H0 : µ = 0 vs Ha : µ =/= 0 for each row of “ss”. (Hint: use either functions apply() or for() and a function mytest())

d) For the 1000 tests you conducted in c), what is the ratio of rejection if the significance level  α = 0.05? How about α = 0.1 or 0.01?

Part 2. Let’s start from R built-in dataset “sleep” (You may access it by running sleep in R or running data(sleep) in R).

a) Load dataset sleep and open the description file.  

b) Draw histogram for column “extra”. Comment on the shape of the histogram.

c) Define two vectors “x” and “y” as following:

x<-sleep$extra[1:10]

y<-sleep$extra[11:20]

d) Conduct two-sample t-test to check whether the means of x and y are significantly different. Make sure to state your hypothesis, test statistic, p-value, decision rule and conclusion for the test  -

e) Define a vector “z” as following:

z<-x-y

f) Conduct one-sample t-test to check whether the mean of z is significantly different from 0.   

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi There,

Please find the solution.

a)

ss <- matrix(c(10:100), nrow = 1000,ncol= 10, byrow = FALSE)
print(ss)
OUTPUT

[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 10 100 99 98 97 96 95 94 93 92 [2,] 11 10 100 99 98 97 96 95 94 93 [3,] 12 11 10 100 99 98 97 96 95 94 [4,] 13 12 11 10 100 99 98 97 96 95 [5,] 14 13 12 11 10 100 99 98 97 96 [6,] 15 14 13 12 11 10 100 99 98 97 [7,] 16 15 14 13 12 11 10 100 99 98 [8,] 17 16 15 14 13 12 11 10 100 99 [9,] 18 17 16 15 14 13 12 11 10 100 [10,] 19 18 17 16 15 14 13 12 11 10 [11,] 20 19 18 17 16 15 14 13 12 11 [12,] 21 20 19 18 17 16 15 14 13 12 [13,] 22 21 20 19 18 17 16 15 14 13 [14,] 23 22 21 20 19 18 17 16 15 14 [15,] 24 23 22 21 20 19 18 17 16 15 [16,] 25 24 23 22 21 20 19 18 17 16 [17,] 26 25 24 23 22 21 20 19 18 17....

b)

mytest <- function(x) {

return(t.test(x,mu=0)$p.value)

}

mytest(rnorm(100))

OUTPUT

[1] 0.4112541

c)

apply(ss,mytest)

OUTPUT

[1] 0.5635022

d)

rejection.level(0.02)

rejection.level(0.1)

OUTPUT

[1] 0.08967416

[1] 0.385624

PART2

a)

sleep<- read.csv("sleep.csv")

description(sleep)

b)

hist(sleep,ylab = "Extra",col = "yellow",border = "blue")

c)

x<-sleep$extra[1:10]

y<-sleep$extra[11:20]

e) z<-x-y

f) t.test(y~x)

Thanks

Feel free to write back in case of doubt.

Add a comment
Know the answer?
Add Answer to:
In R, Part 1. Learn to understand the significance level α in hypothesis testing. a) Generate a matrix “ss” with 1000 rows and 10 columns. The elements of “ss” are random samples from standard normal...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Code in R Part 1. a) Run the following lines: n<-30 x<-matrix(rnorm(n * 1000), 1000,n) xL,1:3]<-xl,1:3]*10...

    Code in R Part 1. a) Run the following lines: n<-30 x<-matrix(rnorm(n * 1000), 1000,n) xL,1:3]<-xl,1:3]*10 y<-1+matrix(rnorm (n * 1000), 1000, n) Note: the samples in "x" are contaminated. b) Conduct 1000 two-sample two-sided t-tests for the associated rows of "xand "". (e.g., for the first test, the two samples are "x[1," and "y[1,]", for the second test, the two samples are "x[2," and "y[2,1",etc.). Calculate the total number of rejections of the 1000 tests. (Use significant level a =...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT