0
votes

Produce 10 random observations from a normal distribution with mean 80 and typical deviation 30 Let's pretend that we do not know the mean μ of the distribution. Using the sample ,check(test) the 2 hypothesis

H0 : µ = 80 vs H1 : µ not equal 80.

Repeat the process for 100 times and record only the p-value each time. Using the 5% significance level to comment your results Show all the values of p-value.

Here is what i did

t<-c( rnorm(10, mean = 80, sd = 30))
t.test (y, mu = 80)
t.test(y, mu =80, alternative = ”greater”)$p.value
 t.test(y, mu = 80, alternative = ”less”)$p.value

notes:

Suppose that in a vector y is stored the data of a sample. This command

t.test(y, mu = 9)

make two-sided hypothesis check(testing), specifically it check whether the mean of the distribution from which the data comes from is equal to 9 ,in case of one-sided check the command is,

t.test(y, mu = 9, alternative = ”greater”) or t.test(y, mu = 9, alternative = ”less”)

accordingly. These commands give the results of the check(testing), including the confidence interval. If someone wants only the value of p-value ,must add $p.value in the end command . For example, the command

t.test (y, mu = 9) $p.value

only gives the p-value for the two -sided check(test) hypothesis

1
So what's the question?thelatemail
you could do this in one line replicate(100, t.test(rnorm(10, 80, 30), mu = 80)$p.value)rawr

1 Answers

1
votes

[EDIT: I'm assuming this is for a school assignment and that you are very new to R.]

Not entirely clear what your question is... However, your code seems to contain some errors..

You create 10 random observations with mean 80 and sd 30. You assign those observations to a vector, t. This is not a smart idea to begin with because t is the R command for transpose - it is not a good idea to use redefine reserved names like this.

You then perform the test using the t.test command. Note that in R, unlike in say Python, the "." does not refer to a method of an object. So when you call t.test(y ... ), you are performing a t-test on a vector of observations y, which you have not defined.

The notes you post assume that your vector of observations is, in fact, called y. If you run ?t.test in the R console, you will see that y is the default name of the parameter of the t.test function that corresponds to a vector of observations.

You probably want is this:

y<-c( rnorm(10, mean = 80, sd = 30))
t.test (y, mu = 80)
t.test(y, mu =80, alternative = "greater")$p.value
t.test(y, mu = 80, alternative = "less")$p.value

But note that you could have used any reasonable variable name for the vector of observations - you would just want to call t.test on the correct vector. For instance,

sample_observations <- c( rnorm(10, mean = 80, sd = 30))
t.test (sample_observations, mu = 80)

[EDIT: There appeared to be unicode in the pasted code snippets. That's fixed now]