What is the difference between these three function calls?
rbinom(20, 1, 0.25) rbinom(1, 20, 0.25) rbinom(20, 20, 0.25)
Answer: the three parameters to rbinom represent (1) the number of binomial experiments to simulate,
(2) the number of trials in one binomial simulation, and (3) the probability of success in one trial.
Here are the results:
# Simulate 20 experiments with one trial each:
rbinom(20, 1, 0.25)
[1] 0 0 0 1 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0
# Simulate one experiment with 20 trials:
# rbinom(1, 20, 0.25)
[1] 8
# Simulate 20 experiments with 20 trials each:
# rbinom(20, 20, 0.25)
[1] 2 8 2 7 9 2 3 6 5 5 4 5 4 6 3 4 5 5 5 4
The examTimes vector is defined by this R statement:
examTimes <- c(18, 160, 234, 149, 145, 107,
197, 75, 201, 225, 211, 119, 157, 145,
107, 244, 163, 114, 145, 68, 111, 185,
202, 146, 203, 224, 213, 104, 178, 166)
These are the times in minutes for students in a statistics class
to complete the class final exam. Use the R function t.test
to test the null hypotheses that the true average time for a typical student to
take the exam is 175 minutes. Perform the test at these significance levels:
0.05, 0.01, 0.10.
Note: R does not have a function that specifically performs z-tests. Use the
t.test function instead.
A z-test and a t-test use exactly the same test statistic:
t = z = (x - μ) / (sx/√n)
The advantage of the t-test is that it works for any sample size, including that
when n < 30. However, for smaller values of n, a wider confidence interval is
used, computed with the t-distribution instead of the normal distribution. We will discuss t-tests later today.
Answer:
> t.test(exam_scores, mu=175, conf.level=0.95)
One Sample t-test
data: exam_scores
t = -1.7956, df = 29, p-value = 0.08298
alternative hypothesis: true mean is not equal to 175
95 percent confidence interval:
136.9259 177.4741
sample estimates:
mean of x
157.2