Question

In: Statistics and Probability

Use R to generate two random numbers n11, n21 from the Binomial distribution: Bin(10, 0.4). Print...

Use R to generate two random numbers n11, n21 from the Binomial distribution: Bin(10, 0.4). Print your results.

Please don’t forget to use the command set.seed(101) before the commands gen- erating the random numbers.

(b) (2 points) Use the R command ntable < − array(data = c(n11, n21, n1plus-n11, n2plus-n21), dim = c(2,2)) to create a 2 × 2 table using the numbers generated in part (a) above. Print your table.

(c) (3 points) Perform the Fisher’s exact test on the 2 × 2 table you created in part (b) above. Print your output. What is the P-value? Do you reject the null hypothesis of independence of the row and column variables at the 5 percent level of significance? Give reasons to your answer.

(d) (4 points) Repeat the above steps 10000 times. You don’t have to print the 10000 tables. Print the first five p-values. How many times (out of all 10000 tests), do you reject the null hypothesis of independence of the row and column variables at the 5 percent level of significance? Comment on your results.

(e) (2 points) Repeat part (d) above, but this time with n11, n21 from the Binomial distribution: Bin(100, 0.4). How many times (out of all 10000 tests), do you reject the null hypothesis of independence of the row and column variables at the 5 percent level of significance? Comment on your results.

Please do part d and e.

Things that are given: n11=3, n21=1, n1plus=10, n2plus=10

Please do not copy and paste the solution for this question that was solved last time. The parameters are clearly defined.

Solutions

Expert Solution

d) The R code to run a simulation 10000 times is given below

N <- 10000
set.seed(199)
n <- 10
p <- 0.4
n_rej <- 0
n1plus <- n
n2plus <- n
for (i in 1:N)
{
n11 <- rbinom(1,n,p)
n21 <- rbinom(1,n,p)
ntable <− array(data = c(n11, n21, n1plus-n11, n2plus-n21), dim = c(2,2))
p <- fisher.test(ntable,alternative="two.sided")$p.value
if(i<= 5)
{
print (p)
}
if (p <0.05)
{
n_rej <- n_rej+1
}
}

n_rej

The first 5 P-values are printed below:

[1] 0.1408669
[1] 1
[1] 1
[1] 1
[1] 1
>
> n_rej
[1] 0

The null hypothesis of independence of the row and column variables at the 5 percent level of significance is rejected 0 times out of 10000.

e) Code modified for .

N <- 10000
set.seed(199)
n <- 100
p <- 0.4
n_rej <- 0
n1plus <- n
n2plus <- n
for (i in 1:N)
{
n11 <- rbinom(1,n,p)
n21 <- rbinom(1,n,p)
ntable <− array(data = c(n11, n21, n1plus-n11, n2plus-n21), dim = c(2,2))
p <- fisher.test(ntable,alternative="two.sided")$p.value
if(i<= 5)
{
print (p)
}
if (p <0.05)
{
n_rej <- n_rej+1
}
}

n_rej

The first 5 P-values are printed below:

[1] 0.3123252
[1] 0.5427761
[1] 0.6714837
[1] 1
[1] 1

The null hypothesis of independence of the row and column variables at the 5 percent level of significance is rejected  0 times out of 10000.

Check your definitions of n11=3, n21=1, n1plus=10, n2plus=10. This is not correct. Another student defined n1plus, n2plus in a different way. I am not responsible. I have given you the code.


Related Solutions

Use Excel to generate the probability distribution for a binomial random variable for which there are...
Use Excel to generate the probability distribution for a binomial random variable for which there are 20 trials (n = 20) and the probability of success is 0.5 (p = 0.5), and show the graph.
Generate 1000 random numbers from ??3? starting with standard normal random numbers in R.
Generate 1000 random numbers from ??3? starting with standard normal random numbers in R.
Write the R code to generate five independent uniform random numbers and use that to generate...
Write the R code to generate five independent uniform random numbers and use that to generate 5 independent Bernoulli random variables with probability of success p = 0.4. please use RStudio. please do not use lab nor rbern for calculations.
a) Using the programming tool of your choice generate 10 random numbers from a flat distribution...
a) Using the programming tool of your choice generate 10 random numbers from a flat distribution between -0.5 and 0.5, and find the mean of these 10 numbers. Consider this mean to be the ‘result’ of this procedure. b) Repeat this 10 times and calculate the mean and variance of your 10 results. Is the distance of the mean from 0 about what you would expect? Why? c) Now repeat it 100 times and calculate the mean and variance. Is...
Use R and perform following: Generate 1000 observations from an exponential distribution with mean 10. Generate...
Use R and perform following: Generate 1000 observations from an exponential distribution with mean 10. Generate 1000 observations from a central t-distribution with 8 degree of freedom. Make a qqplot of observations in problem 1 versus quantiles generated from a t-distribution with 8 degree of freedom. Can the t distribution be used to approximate data in part 1?Submit the plot. Repeat above part but submit a qqplot of the observations in 1 versus quantiles from an exponential with mean 1....
Generate 1000 random numbers from ??2, 5? starting with standard normal random numbers in R.
Generate 1000 random numbers from ??2, 5? starting with standard normal random numbers in R.
For the binomial distribution with n = 10 and p = 0.4, where p is probability...
For the binomial distribution with n = 10 and p = 0.4, where p is probability of success. Let X be the number of successes. (a) Find the probability of three or more successes. (b) Find the µ, E(X), and σ 2 , V ar(X)
A computer was used to generate ten random numbers from a normal distribution with a set...
A computer was used to generate ten random numbers from a normal distribution with a set of unknown mean and variance: −1.1623, 0.2210, 1.6518, −1.1312, −0.2879, −1.0458, 1.3706, −0.7492, −0.1355, −1.2686. Eight more random normal numbers with the same variance perhaps a different mean were then generated (the mean may or may not actually be different): 0.3472, 2.2437, 1.0712, 2.5906, 0.5163, −1.1743, 0.0473, −0.8338. (a) What do you think the means of the random normal number generators were? What do...
Describe the algorithm to generate random numbers from an arbitrary discrete distribution with finite number of...
Describe the algorithm to generate random numbers from an arbitrary discrete distribution with finite number of outcomes.
Use R to generate n = 400 samples (idependent identically distributed random numbers) of X ∼...
Use R to generate n = 400 samples (idependent identically distributed random numbers) of X ∼ N(0, 4). For each Xi , simulate Yi according to Yi = 3 + 2.5Xi + εi , where εi ∼ N(0, 16), i = 1, ..., n. Use R to solve the following questions. (a) Compute the least square estimators of βˆ 0 and βˆ 1. (b) Draw a regression line according to the numbers computed in (a). Plot Y and X with...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT