In: Statistics and Probability
Use R to load in the file “data.csv”. Assume that this is a random sample from some population with mean µ and variance σ 2 .
(a) Plot a histogram of the data.
(b) Compute a 95% confidence interval for the population mean µ using the formula
X ± (S/√ n)tn−1,.975.
(Hint: tn−1,.975 can be computed with qt(.975,df=n-1))
(c) Compute a p-value for the hypothesis H0 : µ = 5 versus HA : µ > 5, based on the test statistic T = X−5 S/√ n .
(Hint: The p-value can be computed using 1-pt(T,df=n-1))
(d) Based on the p-value, do we reject the null hypothesis at α = .01?
(e) What is the smallest significance level α for which we would reject the null?
Data set:
| x | |
| 1 | 4.698166 |
| 2 | 4.447565 |
| 3 | 6.841008 |
| 4 | 7.013583 |
| 5 | 3.129358 |
| 6 | 5.147627 |
| 7 | 2.549057 |
| 8 | 4.061032 |
| 9 | 2.482377 |
| 10 | 6.200452 |
| 11 | 3.017356 |
| 12 | 3.54399 |
| 13 | 5.02652 |
| 14 | 5.941181 |
| 15 | 7.012088 |
| 16 | 1.780168 |
| 17 | 4.338341 |
| 18 | 8.932189 |
| 19 | 8.437784 |
| 20 | 8.858227 |
| 21 | 4.750132 |
| 22 | 9.313738 |
| 23 | 4.09576 |
| 24 | 2.746881 |
| 25 | 3.80401 |
| 26 | 9.34906 |
| 27 | 5.87805 |
| 28 | 7.306379 |
| 29 | 7.147015 |
| 30 | 4.489627 |
| 31 | 5.048496 |
| 32 | 3.97515 |
| 33 | 5.325467 |
| 34 | 8.177696 |
| 35 | 6.422605 |
| 36 | 7.81162 |
| 37 | 9.849941 |
| 38 | 9.936086 |
| 39 | 8.045554 |
| 40 | 4.141212 |
| 41 | 5.19843 |
| 42 | 6.439768 |
| 43 | 5.067979 |
| 44 | 3.790223 |
| 45 | 8.642296 |
| 46 | 10.72038 |
| 47 | 5.450084 |
| 48 | 4.960262 |
| 49 | 3.355154 |
| 50 | 4.35933 |
Sol:

> library(readr)
> Data <- read_delim("C:/Users/M1045151/Downloads/Data.csv",
+ ";", escape_double = FALSE, trim_ws = TRUE)
After importing
T get histogram in R
hist(Data$x)

From histogram we observe that x follows normal distribution
SolutionB:
Rcode:
n <- 50
qt(.975,df=50-1)
mean(Data$x)
sd(Data$x)
tc=2.009575
xbar=sample mean=5.781129
sample sd=s=
95% confidence interval for mean
xbar-tc8s/sqrt(50),xbar+tc*s/sqrt(n)
5.781129-2.009575*2.246647/sqrt(50),5.781129+2.009575*2.246647/sqrt(50)
5.142639,6.419619
95% lower limit:5.142639
95% upper limit=6.419619
SIMPLE RCODE TO GET ABOVE ANSWER:
t.test(Data$x)
Output:
One Sample t-test
data: Data$x
t = 18.195, df = 49, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
5.142639 6.419619
sample estimates:
mean of x
5.781129
95 percent confidence interval:
5.142639 6.419619
Solutionc:
Rcode:
t.test(Data$x,mu=5,alternative = "greater")
output:
One Sample t-test
data: Data$x
t = 2.4585, df = 49, p-value = 0.008766
alternative hypothesis: true mean is greater than 5
98 percent confidence interval:
5.110772 Inf
sample estimates:
mean of x
5.781129
p=0.008766
(d) Based on the p-value, do we reject the null hypothesis at α = .01?
p=0.008766
alpha=0.01
p>0.01
Fail to reject Ho.
(e) What is the smallest significance level α for which we would reject the null?
smallest level of alpha=10%=0.10
because as p=0.008766
p<alpha
reject Ho.
ANSWER:
10%
RSCREENSHOT: